alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ASoC: rt1011: revert 'I2S Reference' to SOC_ENUM_EXT
@ 2021-11-11  9:17 Jack Yu
  2021-11-12 21:27 ` Mark Brown
  2021-11-30 11:24 ` Péter Ujfalusi
  0 siblings, 2 replies; 6+ messages in thread
From: Jack Yu @ 2021-11-11  9:17 UTC (permalink / raw)
  To: broonie, lgirdwood
  Cc: oder_chiou, Jack Yu, alsa-devel, lars, kent_chen, derek.fang,
	shumingf, flove

Revert 'I2S Reference' to SOC_ENUM_EXT because the settings are specific
for some platforms, the default setting for 'I2S Reference' does nothing,
only some SoC platform need to configure it.
Previous 'I2S Reference' in SOC_ENUM format only toggles one bit of
RT1011_TDM1_SET_1 register, which isn't enough for specific platform.

Signed-off-by: Jack Yu <jack.yu@realtek.com>
---
 sound/soc/codecs/rt1011.c | 55 ++++++++++++++++++++++++++++++++++-----
 sound/soc/codecs/rt1011.h |  7 +++++
 2 files changed, 56 insertions(+), 6 deletions(-)

diff --git a/sound/soc/codecs/rt1011.c b/sound/soc/codecs/rt1011.c
index 297af7ff824c..b62301a6281f 100644
--- a/sound/soc/codecs/rt1011.c
+++ b/sound/soc/codecs/rt1011.c
@@ -1311,13 +1311,54 @@ static int rt1011_r0_load_info(struct snd_kcontrol *kcontrol,
 	.put = rt1011_r0_load_mode_put \
 }
 
-static const char * const rt1011_i2s_ref_texts[] = {
-	"Left Channel", "Right Channel"
+static const char * const rt1011_i2s_ref[] = {
+	"None", "Left Channel", "Right Channel"
 };
 
-static SOC_ENUM_SINGLE_DECL(rt1011_i2s_ref_enum,
-			    RT1011_TDM1_SET_1, 7,
-			    rt1011_i2s_ref_texts);
+static SOC_ENUM_SINGLE_DECL(rt1011_i2s_ref_enum, 0, 0,
+	rt1011_i2s_ref);
+
+static int rt1011_i2s_ref_put(struct snd_kcontrol *kcontrol,
+		struct snd_ctl_elem_value *ucontrol)
+{
+	struct snd_soc_component *component =
+		snd_soc_kcontrol_component(kcontrol);
+	struct rt1011_priv *rt1011 =
+		snd_soc_component_get_drvdata(component);
+
+	rt1011->i2s_ref = ucontrol->value.enumerated.item[0];
+	switch (rt1011->i2s_ref) {
+	case RT1011_I2S_REF_LEFT_CH:
+		regmap_write(rt1011->regmap, RT1011_TDM_TOTAL_SET, 0x0240);
+		regmap_write(rt1011->regmap, RT1011_TDM1_SET_2, 0x8);
+		regmap_write(rt1011->regmap, RT1011_TDM1_SET_1, 0x1022);
+		regmap_write(rt1011->regmap, RT1011_ADCDAT_OUT_SOURCE, 0x4);
+		break;
+	case RT1011_I2S_REF_RIGHT_CH:
+		regmap_write(rt1011->regmap, RT1011_TDM_TOTAL_SET, 0x0240);
+		regmap_write(rt1011->regmap, RT1011_TDM1_SET_2, 0x8);
+		regmap_write(rt1011->regmap, RT1011_TDM1_SET_1, 0x10a2);
+		regmap_write(rt1011->regmap, RT1011_ADCDAT_OUT_SOURCE, 0x4);
+		break;
+	default:
+		dev_info(component->dev, "I2S Reference: Do nothing\n");
+	}
+
+	return 0;
+}
+
+static int rt1011_i2s_ref_get(struct snd_kcontrol *kcontrol,
+		struct snd_ctl_elem_value *ucontrol)
+{
+	struct snd_soc_component *component =
+		snd_soc_kcontrol_component(kcontrol);
+	struct rt1011_priv *rt1011 =
+		snd_soc_component_get_drvdata(component);
+
+	ucontrol->value.enumerated.item[0] = rt1011->i2s_ref;
+
+	return 0;
+}
 
 static const struct snd_kcontrol_new rt1011_snd_controls[] = {
 	/* I2S Data In Selection */
@@ -1358,7 +1399,8 @@ static const struct snd_kcontrol_new rt1011_snd_controls[] = {
 	SOC_SINGLE("R0 Temperature", RT1011_STP_INITIAL_RESISTANCE_TEMP,
 		2, 255, 0),
 	/* I2S Reference */
-	SOC_ENUM("I2S Reference", rt1011_i2s_ref_enum),
+	SOC_ENUM_EXT("I2S Reference", rt1011_i2s_ref_enum,
+		rt1011_i2s_ref_get, rt1011_i2s_ref_put),
 };
 
 static int rt1011_is_sys_clk_from_pll(struct snd_soc_dapm_widget *source,
@@ -2017,6 +2059,7 @@ static int rt1011_probe(struct snd_soc_component *component)
 
 	schedule_work(&rt1011->cali_work);
 
+	rt1011->i2s_ref = 0;
 	rt1011->bq_drc_params = devm_kcalloc(component->dev,
 		RT1011_ADVMODE_NUM, sizeof(struct rt1011_bq_drc_params *),
 		GFP_KERNEL);
diff --git a/sound/soc/codecs/rt1011.h b/sound/soc/codecs/rt1011.h
index 68fadc15fa8c..4d6e7492d99c 100644
--- a/sound/soc/codecs/rt1011.h
+++ b/sound/soc/codecs/rt1011.h
@@ -654,6 +654,12 @@ enum {
 	RT1011_AIFS
 };
 
+enum {
+	RT1011_I2S_REF_NONE,
+	RT1011_I2S_REF_LEFT_CH,
+	RT1011_I2S_REF_RIGHT_CH,
+};
+
 /* BiQual & DRC related settings */
 #define RT1011_BQ_DRC_NUM 128
 struct rt1011_bq_drc_params {
@@ -692,6 +698,7 @@ struct rt1011_priv {
 	unsigned int r0_reg, cali_done;
 	unsigned int r0_calib, temperature_calib;
 	int recv_spk_mode;
+	int i2s_ref;
 };
 
 #endif		/* end of _RT1011_H_ */
-- 
2.33.0


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

* Re: [PATCH] ASoC: rt1011: revert 'I2S Reference' to SOC_ENUM_EXT
  2021-11-11  9:17 [PATCH] ASoC: rt1011: revert 'I2S Reference' to SOC_ENUM_EXT Jack Yu
@ 2021-11-12 21:27 ` Mark Brown
  2021-11-30 11:24 ` Péter Ujfalusi
  1 sibling, 0 replies; 6+ messages in thread
From: Mark Brown @ 2021-11-12 21:27 UTC (permalink / raw)
  To: Jack Yu, lgirdwood
  Cc: oder_chiou, alsa-devel, lars, kent_chen, derek.fang, shumingf, flove

On Thu, 11 Nov 2021 17:17:05 +0800, Jack Yu wrote:
> Revert 'I2S Reference' to SOC_ENUM_EXT because the settings are specific
> for some platforms, the default setting for 'I2S Reference' does nothing,
> only some SoC platform need to configure it.
> Previous 'I2S Reference' in SOC_ENUM format only toggles one bit of
> RT1011_TDM1_SET_1 register, which isn't enough for specific platform.
> 
> 
> [...]

Applied to

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

Thanks!

[1/1] ASoC: rt1011: revert 'I2S Reference' to SOC_ENUM_EXT
      commit: a382285b6feda8db56955e5897453405c198048d

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] 6+ messages in thread

* Re: [PATCH] ASoC: rt1011: revert 'I2S Reference' to SOC_ENUM_EXT
  2021-11-11  9:17 [PATCH] ASoC: rt1011: revert 'I2S Reference' to SOC_ENUM_EXT Jack Yu
  2021-11-12 21:27 ` Mark Brown
@ 2021-11-30 11:24 ` Péter Ujfalusi
  2021-12-01  2:36   ` Jack Yu
  1 sibling, 1 reply; 6+ messages in thread
From: Péter Ujfalusi @ 2021-11-30 11:24 UTC (permalink / raw)
  To: Jack Yu, broonie, lgirdwood
  Cc: oder_chiou, alsa-devel, lars, kent_chen, derek.fang, shumingf, flove

Hi Jack,

On 11/11/2021 11:17, Jack Yu wrote:
> Revert 'I2S Reference' to SOC_ENUM_EXT because the settings are specific
> for some platforms, the default setting for 'I2S Reference' does nothing,
> only some SoC platform need to configure it.
> Previous 'I2S Reference' in SOC_ENUM format only toggles one bit of
> RT1011_TDM1_SET_1 register, which isn't enough for specific platform.

This patch again breaks audio but in a less obvious way.
If a user _ever_ touches the "I2S Reference" then audio playback will
never going to work again as instead of changing the i2s reference the
code clears all settings done by set_tdm_slot, dai_fmt to something
which is some product specific setting.
One would think that a reboot helps, but on boot we tend to restore the
saved amixer settings -> audio playback is broken.
So, before reboot one has to set the reference to None and reboot and
hope that on boot the NOP (None) is going to be set which means that the
custom enum code would not overwrite the configuration of the codec.

There is a single bit in RT1011_TDM1_SET_1 (bit 7) which selects the I2S
reference and the reset value is Left (0).

With this custom enum put code you effectively reconfigure the code to
be unusable on most likely in all systems except the one which needs
these settings...

> 
> Signed-off-by: Jack Yu <jack.yu@realtek.com>
> ---
>  sound/soc/codecs/rt1011.c | 55 ++++++++++++++++++++++++++++++++++-----
>  sound/soc/codecs/rt1011.h |  7 +++++
>  2 files changed, 56 insertions(+), 6 deletions(-)
> 
> diff --git a/sound/soc/codecs/rt1011.c b/sound/soc/codecs/rt1011.c
> index 297af7ff824c..b62301a6281f 100644
> --- a/sound/soc/codecs/rt1011.c
> +++ b/sound/soc/codecs/rt1011.c
> @@ -1311,13 +1311,54 @@ static int rt1011_r0_load_info(struct snd_kcontrol *kcontrol,
>  	.put = rt1011_r0_load_mode_put \
>  }
>  
> -static const char * const rt1011_i2s_ref_texts[] = {
> -	"Left Channel", "Right Channel"
> +static const char * const rt1011_i2s_ref[] = {
> +	"None", "Left Channel", "Right Channel"
>  };
>  
> -static SOC_ENUM_SINGLE_DECL(rt1011_i2s_ref_enum,
> -			    RT1011_TDM1_SET_1, 7,
> -			    rt1011_i2s_ref_texts);
> +static SOC_ENUM_SINGLE_DECL(rt1011_i2s_ref_enum, 0, 0,
> +	rt1011_i2s_ref);
> +
> +static int rt1011_i2s_ref_put(struct snd_kcontrol *kcontrol,
> +		struct snd_ctl_elem_value *ucontrol)
> +{
> +	struct snd_soc_component *component =
> +		snd_soc_kcontrol_component(kcontrol);
> +	struct rt1011_priv *rt1011 =
> +		snd_soc_component_get_drvdata(component);
> +
> +	rt1011->i2s_ref = ucontrol->value.enumerated.item[0];
> +	switch (rt1011->i2s_ref) {
> +	case RT1011_I2S_REF_LEFT_CH:
> +		regmap_write(rt1011->regmap, RT1011_TDM_TOTAL_SET, 0x0240);
> +		regmap_write(rt1011->regmap, RT1011_TDM1_SET_2, 0x8);
> +		regmap_write(rt1011->regmap, RT1011_TDM1_SET_1, 0x1022);
> +		regmap_write(rt1011->regmap, RT1011_ADCDAT_OUT_SOURCE, 0x4);
> +		break;
> +	case RT1011_I2S_REF_RIGHT_CH:
> +		regmap_write(rt1011->regmap, RT1011_TDM_TOTAL_SET, 0x0240);
> +		regmap_write(rt1011->regmap, RT1011_TDM1_SET_2, 0x8);
> +		regmap_write(rt1011->regmap, RT1011_TDM1_SET_1, 0x10a2);
> +		regmap_write(rt1011->regmap, RT1011_ADCDAT_OUT_SOURCE, 0x4);
> +		break;
> +	default:
> +		dev_info(component->dev, "I2S Reference: Do nothing\n");
> +	}
> +
> +	return 0;
> +}
> +
> +static int rt1011_i2s_ref_get(struct snd_kcontrol *kcontrol,
> +		struct snd_ctl_elem_value *ucontrol)
> +{
> +	struct snd_soc_component *component =
> +		snd_soc_kcontrol_component(kcontrol);
> +	struct rt1011_priv *rt1011 =
> +		snd_soc_component_get_drvdata(component);
> +
> +	ucontrol->value.enumerated.item[0] = rt1011->i2s_ref;
> +
> +	return 0;
> +}
>  
>  static const struct snd_kcontrol_new rt1011_snd_controls[] = {
>  	/* I2S Data In Selection */
> @@ -1358,7 +1399,8 @@ static const struct snd_kcontrol_new rt1011_snd_controls[] = {
>  	SOC_SINGLE("R0 Temperature", RT1011_STP_INITIAL_RESISTANCE_TEMP,
>  		2, 255, 0),
>  	/* I2S Reference */
> -	SOC_ENUM("I2S Reference", rt1011_i2s_ref_enum),
> +	SOC_ENUM_EXT("I2S Reference", rt1011_i2s_ref_enum,
> +		rt1011_i2s_ref_get, rt1011_i2s_ref_put),
>  };
>  
>  static int rt1011_is_sys_clk_from_pll(struct snd_soc_dapm_widget *source,
> @@ -2017,6 +2059,7 @@ static int rt1011_probe(struct snd_soc_component *component)
>  
>  	schedule_work(&rt1011->cali_work);
>  
> +	rt1011->i2s_ref = 0;
>  	rt1011->bq_drc_params = devm_kcalloc(component->dev,
>  		RT1011_ADVMODE_NUM, sizeof(struct rt1011_bq_drc_params *),
>  		GFP_KERNEL);
> diff --git a/sound/soc/codecs/rt1011.h b/sound/soc/codecs/rt1011.h
> index 68fadc15fa8c..4d6e7492d99c 100644
> --- a/sound/soc/codecs/rt1011.h
> +++ b/sound/soc/codecs/rt1011.h
> @@ -654,6 +654,12 @@ enum {
>  	RT1011_AIFS
>  };
>  
> +enum {
> +	RT1011_I2S_REF_NONE,
> +	RT1011_I2S_REF_LEFT_CH,
> +	RT1011_I2S_REF_RIGHT_CH,
> +};
> +
>  /* BiQual & DRC related settings */
>  #define RT1011_BQ_DRC_NUM 128
>  struct rt1011_bq_drc_params {
> @@ -692,6 +698,7 @@ struct rt1011_priv {
>  	unsigned int r0_reg, cali_done;
>  	unsigned int r0_calib, temperature_calib;
>  	int recv_spk_mode;
> +	int i2s_ref;
>  };
>  
>  #endif		/* end of _RT1011_H_ */
> 

-- 
Péter

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

* RE: [PATCH] ASoC: rt1011: revert 'I2S Reference' to SOC_ENUM_EXT
  2021-11-30 11:24 ` Péter Ujfalusi
@ 2021-12-01  2:36   ` Jack Yu
  2021-12-01  7:00     ` Péter Ujfalusi
  0 siblings, 1 reply; 6+ messages in thread
From: Jack Yu @ 2021-12-01  2:36 UTC (permalink / raw)
  To: Péter Ujfalusi, broonie, lgirdwood
  Cc: Oder Chiou, alsa-devel, lars,
	kent_chen@realtek.com [陳建宏],
	Derek [方德義],
	Shuming [范書銘], Flove(HsinFu)

Hi Peter,

> On 11/11/2021 11:17, Jack Yu wrote:
> > Revert 'I2S Reference' to SOC_ENUM_EXT because the settings are
> > specific for some platforms, the default setting for 'I2S Reference'
> > does nothing, only some SoC platform need to configure it.
> > Previous 'I2S Reference' in SOC_ENUM format only toggles one bit of
> > RT1011_TDM1_SET_1 register, which isn't enough for specific platform.
> 
> This patch again breaks audio but in a less obvious way.
> If a user _ever_ touches the "I2S Reference" then audio playback will never
> going to work again as instead of changing the i2s reference the code clears all
> settings done by set_tdm_slot, dai_fmt to something which is some product
> specific setting.
> One would think that a reboot helps, but on boot we tend to restore the saved
> amixer settings -> audio playback is broken.
> So, before reboot one has to set the reference to None and reboot and hope
> that on boot the NOP (None) is going to be set which means that the custom
> enum code would not overwrite the configuration of the codec.
> 
> There is a single bit in RT1011_TDM1_SET_1 (bit 7) which selects the I2S
> reference and the reset value is Left (0).
> 
> With this custom enum put code you effectively reconfigure the code to be
> unusable on most likely in all systems except the one which needs these
> settings...
> 
This patch is specific for device which uses I2S format and need the reference data, 
if the device uses TDM format, it doesn't need to call "I2S Reference ".

If device runs TDM mode, machine driver sets TDM slot and DAI format, but no need to call " I2S reference ".
If device runs I2S mode, machine driver sets I2S DAI format, and ucm sets "I2S reference" (it's optional, only if device needs reference signal )

> >
> > Signed-off-by: Jack Yu <jack.yu@realtek.com>
> > ---
> >  sound/soc/codecs/rt1011.c | 55
> > ++++++++++++++++++++++++++++++++++-----
> >  sound/soc/codecs/rt1011.h |  7 +++++
> >  2 files changed, 56 insertions(+), 6 deletions(-)
> >
> > diff --git a/sound/soc/codecs/rt1011.c b/sound/soc/codecs/rt1011.c
> > index 297af7ff824c..b62301a6281f 100644
> > --- a/sound/soc/codecs/rt1011.c
> > +++ b/sound/soc/codecs/rt1011.c
> > @@ -1311,13 +1311,54 @@ static int rt1011_r0_load_info(struct
> snd_kcontrol *kcontrol,
> >  	.put = rt1011_r0_load_mode_put \
> >  }
> >
> > -static const char * const rt1011_i2s_ref_texts[] = {
> > -	"Left Channel", "Right Channel"
> > +static const char * const rt1011_i2s_ref[] = {
> > +	"None", "Left Channel", "Right Channel"
> >  };
> >
> > -static SOC_ENUM_SINGLE_DECL(rt1011_i2s_ref_enum,
> > -			    RT1011_TDM1_SET_1, 7,
> > -			    rt1011_i2s_ref_texts);
> > +static SOC_ENUM_SINGLE_DECL(rt1011_i2s_ref_enum, 0, 0,
> > +	rt1011_i2s_ref);
> > +
> > +static int rt1011_i2s_ref_put(struct snd_kcontrol *kcontrol,
> > +		struct snd_ctl_elem_value *ucontrol) {
> > +	struct snd_soc_component *component =
> > +		snd_soc_kcontrol_component(kcontrol);
> > +	struct rt1011_priv *rt1011 =
> > +		snd_soc_component_get_drvdata(component);
> > +
> > +	rt1011->i2s_ref = ucontrol->value.enumerated.item[0];
> > +	switch (rt1011->i2s_ref) {
> > +	case RT1011_I2S_REF_LEFT_CH:
> > +		regmap_write(rt1011->regmap, RT1011_TDM_TOTAL_SET, 0x0240);
> > +		regmap_write(rt1011->regmap, RT1011_TDM1_SET_2, 0x8);
> > +		regmap_write(rt1011->regmap, RT1011_TDM1_SET_1, 0x1022);
> > +		regmap_write(rt1011->regmap, RT1011_ADCDAT_OUT_SOURCE,
> 0x4);
> > +		break;
> > +	case RT1011_I2S_REF_RIGHT_CH:
> > +		regmap_write(rt1011->regmap, RT1011_TDM_TOTAL_SET, 0x0240);
> > +		regmap_write(rt1011->regmap, RT1011_TDM1_SET_2, 0x8);
> > +		regmap_write(rt1011->regmap, RT1011_TDM1_SET_1, 0x10a2);
> > +		regmap_write(rt1011->regmap, RT1011_ADCDAT_OUT_SOURCE,
> 0x4);
> > +		break;
> > +	default:
> > +		dev_info(component->dev, "I2S Reference: Do nothing\n");
> > +	}
> > +
> > +	return 0;
> > +}
> > +
> > +static int rt1011_i2s_ref_get(struct snd_kcontrol *kcontrol,
> > +		struct snd_ctl_elem_value *ucontrol) {
> > +	struct snd_soc_component *component =
> > +		snd_soc_kcontrol_component(kcontrol);
> > +	struct rt1011_priv *rt1011 =
> > +		snd_soc_component_get_drvdata(component);
> > +
> > +	ucontrol->value.enumerated.item[0] = rt1011->i2s_ref;
> > +
> > +	return 0;
> > +}
> >
> >  static const struct snd_kcontrol_new rt1011_snd_controls[] = {
> >  	/* I2S Data In Selection */
> > @@ -1358,7 +1399,8 @@ static const struct snd_kcontrol_new
> rt1011_snd_controls[] = {
> >  	SOC_SINGLE("R0 Temperature", RT1011_STP_INITIAL_RESISTANCE_TEMP,
> >  		2, 255, 0),
> >  	/* I2S Reference */
> > -	SOC_ENUM("I2S Reference", rt1011_i2s_ref_enum),
> > +	SOC_ENUM_EXT("I2S Reference", rt1011_i2s_ref_enum,
> > +		rt1011_i2s_ref_get, rt1011_i2s_ref_put),
> >  };
> >
> >  static int rt1011_is_sys_clk_from_pll(struct snd_soc_dapm_widget
> > *source, @@ -2017,6 +2059,7 @@ static int rt1011_probe(struct
> > snd_soc_component *component)
> >
> >  	schedule_work(&rt1011->cali_work);
> >
> > +	rt1011->i2s_ref = 0;
> >  	rt1011->bq_drc_params = devm_kcalloc(component->dev,
> >  		RT1011_ADVMODE_NUM, sizeof(struct rt1011_bq_drc_params *),
> >  		GFP_KERNEL);
> > diff --git a/sound/soc/codecs/rt1011.h b/sound/soc/codecs/rt1011.h
> > index 68fadc15fa8c..4d6e7492d99c 100644
> > --- a/sound/soc/codecs/rt1011.h
> > +++ b/sound/soc/codecs/rt1011.h
> > @@ -654,6 +654,12 @@ enum {
> >  	RT1011_AIFS
> >  };
> >
> > +enum {
> > +	RT1011_I2S_REF_NONE,
> > +	RT1011_I2S_REF_LEFT_CH,
> > +	RT1011_I2S_REF_RIGHT_CH,
> > +};
> > +
> >  /* BiQual & DRC related settings */
> >  #define RT1011_BQ_DRC_NUM 128
> >  struct rt1011_bq_drc_params {
> > @@ -692,6 +698,7 @@ struct rt1011_priv {
> >  	unsigned int r0_reg, cali_done;
> >  	unsigned int r0_calib, temperature_calib;
> >  	int recv_spk_mode;
> > +	int i2s_ref;
> >  };
> >
> >  #endif		/* end of _RT1011_H_ */
> >
> 
> --
> Péter
> ------Please consider the environment before printing this e-mail.

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

* Re: [PATCH] ASoC: rt1011: revert 'I2S Reference' to SOC_ENUM_EXT
  2021-12-01  2:36   ` Jack Yu
@ 2021-12-01  7:00     ` Péter Ujfalusi
  2021-12-01 12:30       ` Mark Brown
  0 siblings, 1 reply; 6+ messages in thread
From: Péter Ujfalusi @ 2021-12-01  7:00 UTC (permalink / raw)
  To: Jack Yu, broonie, lgirdwood
  Cc: Oder Chiou, alsa-devel, lars,
	kent_chen@realtek.com [陳建宏],
	Derek [方德義],
	Shuming [范書銘], Flove(HsinFu)

Hi jack,

On 01/12/2021 04:36, Jack Yu wrote:
> Hi Peter,
> 
>> On 11/11/2021 11:17, Jack Yu wrote:
>>> Revert 'I2S Reference' to SOC_ENUM_EXT because the settings are
>>> specific for some platforms, the default setting for 'I2S Reference'
>>> does nothing, only some SoC platform need to configure it.
>>> Previous 'I2S Reference' in SOC_ENUM format only toggles one bit of
>>> RT1011_TDM1_SET_1 register, which isn't enough for specific platform.
>>
>> This patch again breaks audio but in a less obvious way.
>> If a user _ever_ touches the "I2S Reference" then audio playback will never
>> going to work again as instead of changing the i2s reference the code clears all
>> settings done by set_tdm_slot, dai_fmt to something which is some product
>> specific setting.
>> One would think that a reboot helps, but on boot we tend to restore the saved
>> amixer settings -> audio playback is broken.
>> So, before reboot one has to set the reference to None and reboot and hope
>> that on boot the NOP (None) is going to be set which means that the custom
>> enum code would not overwrite the configuration of the codec.
>>
>> There is a single bit in RT1011_TDM1_SET_1 (bit 7) which selects the I2S
>> reference and the reset value is Left (0).
>>
>> With this custom enum put code you effectively reconfigure the code to be
>> unusable on most likely in all systems except the one which needs these
>> settings...
>>
> This patch is specific for device which uses I2S format and need the reference data, 
> if the device uses TDM format, it doesn't need to call "I2S Reference ".
> 
> If device runs TDM mode, machine driver sets TDM slot and DAI format, but no need to call " I2S reference ".
> If device runs I2S mode, machine driver sets I2S DAI format, and ucm sets "I2S reference" (it's optional, only if device needs reference signal )

But then this should not be called as 'I2S Reference'
'I2S Reference' is _one_ bit.
This is something like drop dai_fmt and all configuration and
set ADCDAT1/2 pin to output
set I2S, 24 bit for rx/tx
set undocumented BIT12 in RT1011_TDM1_SET_1
set 'TDM1 DOUT Source' to ALC

What happens if one starts 16bit audio playback after triggering this
macro? It is going to change some of the settings and things might brake
here and there?

What I'm saying is that the implementation is misleading and it is
covertly reconfigures the codec to some static config

> 
>>>
>>> Signed-off-by: Jack Yu <jack.yu@realtek.com>
>>> ---
>>>  sound/soc/codecs/rt1011.c | 55
>>> ++++++++++++++++++++++++++++++++++-----
>>>  sound/soc/codecs/rt1011.h |  7 +++++
>>>  2 files changed, 56 insertions(+), 6 deletions(-)
>>>
>>> diff --git a/sound/soc/codecs/rt1011.c b/sound/soc/codecs/rt1011.c
>>> index 297af7ff824c..b62301a6281f 100644
>>> --- a/sound/soc/codecs/rt1011.c
>>> +++ b/sound/soc/codecs/rt1011.c
>>> @@ -1311,13 +1311,54 @@ static int rt1011_r0_load_info(struct
>> snd_kcontrol *kcontrol,
>>>  	.put = rt1011_r0_load_mode_put \
>>>  }
>>>
>>> -static const char * const rt1011_i2s_ref_texts[] = {
>>> -	"Left Channel", "Right Channel"
>>> +static const char * const rt1011_i2s_ref[] = {
>>> +	"None", "Left Channel", "Right Channel"
>>>  };
>>>
>>> -static SOC_ENUM_SINGLE_DECL(rt1011_i2s_ref_enum,
>>> -			    RT1011_TDM1_SET_1, 7,
>>> -			    rt1011_i2s_ref_texts);
>>> +static SOC_ENUM_SINGLE_DECL(rt1011_i2s_ref_enum, 0, 0,
>>> +	rt1011_i2s_ref);
>>> +
>>> +static int rt1011_i2s_ref_put(struct snd_kcontrol *kcontrol,
>>> +		struct snd_ctl_elem_value *ucontrol) {
>>> +	struct snd_soc_component *component =
>>> +		snd_soc_kcontrol_component(kcontrol);
>>> +	struct rt1011_priv *rt1011 =
>>> +		snd_soc_component_get_drvdata(component);
>>> +
>>> +	rt1011->i2s_ref = ucontrol->value.enumerated.item[0];
>>> +	switch (rt1011->i2s_ref) {
>>> +	case RT1011_I2S_REF_LEFT_CH:
>>> +		regmap_write(rt1011->regmap, RT1011_TDM_TOTAL_SET, 0x0240);
>>> +		regmap_write(rt1011->regmap, RT1011_TDM1_SET_2, 0x8);
>>> +		regmap_write(rt1011->regmap, RT1011_TDM1_SET_1, 0x1022);
>>> +		regmap_write(rt1011->regmap, RT1011_ADCDAT_OUT_SOURCE,
>> 0x4);
>>> +		break;
>>> +	case RT1011_I2S_REF_RIGHT_CH:
>>> +		regmap_write(rt1011->regmap, RT1011_TDM_TOTAL_SET, 0x0240);
>>> +		regmap_write(rt1011->regmap, RT1011_TDM1_SET_2, 0x8);
>>> +		regmap_write(rt1011->regmap, RT1011_TDM1_SET_1, 0x10a2);
>>> +		regmap_write(rt1011->regmap, RT1011_ADCDAT_OUT_SOURCE,
>> 0x4);
>>> +		break;
>>> +	default:
>>> +		dev_info(component->dev, "I2S Reference: Do nothing\n");
>>> +	}
>>> +
>>> +	return 0;
>>> +}
>>> +
>>> +static int rt1011_i2s_ref_get(struct snd_kcontrol *kcontrol,
>>> +		struct snd_ctl_elem_value *ucontrol) {
>>> +	struct snd_soc_component *component =
>>> +		snd_soc_kcontrol_component(kcontrol);
>>> +	struct rt1011_priv *rt1011 =
>>> +		snd_soc_component_get_drvdata(component);
>>> +
>>> +	ucontrol->value.enumerated.item[0] = rt1011->i2s_ref;
>>> +
>>> +	return 0;
>>> +}
>>>
>>>  static const struct snd_kcontrol_new rt1011_snd_controls[] = {
>>>  	/* I2S Data In Selection */
>>> @@ -1358,7 +1399,8 @@ static const struct snd_kcontrol_new
>> rt1011_snd_controls[] = {
>>>  	SOC_SINGLE("R0 Temperature", RT1011_STP_INITIAL_RESISTANCE_TEMP,
>>>  		2, 255, 0),
>>>  	/* I2S Reference */
>>> -	SOC_ENUM("I2S Reference", rt1011_i2s_ref_enum),
>>> +	SOC_ENUM_EXT("I2S Reference", rt1011_i2s_ref_enum,
>>> +		rt1011_i2s_ref_get, rt1011_i2s_ref_put),
>>>  };
>>>
>>>  static int rt1011_is_sys_clk_from_pll(struct snd_soc_dapm_widget
>>> *source, @@ -2017,6 +2059,7 @@ static int rt1011_probe(struct
>>> snd_soc_component *component)
>>>
>>>  	schedule_work(&rt1011->cali_work);
>>>
>>> +	rt1011->i2s_ref = 0;
>>>  	rt1011->bq_drc_params = devm_kcalloc(component->dev,
>>>  		RT1011_ADVMODE_NUM, sizeof(struct rt1011_bq_drc_params *),
>>>  		GFP_KERNEL);
>>> diff --git a/sound/soc/codecs/rt1011.h b/sound/soc/codecs/rt1011.h
>>> index 68fadc15fa8c..4d6e7492d99c 100644
>>> --- a/sound/soc/codecs/rt1011.h
>>> +++ b/sound/soc/codecs/rt1011.h
>>> @@ -654,6 +654,12 @@ enum {
>>>  	RT1011_AIFS
>>>  };
>>>
>>> +enum {
>>> +	RT1011_I2S_REF_NONE,
>>> +	RT1011_I2S_REF_LEFT_CH,
>>> +	RT1011_I2S_REF_RIGHT_CH,
>>> +};
>>> +
>>>  /* BiQual & DRC related settings */
>>>  #define RT1011_BQ_DRC_NUM 128
>>>  struct rt1011_bq_drc_params {
>>> @@ -692,6 +698,7 @@ struct rt1011_priv {
>>>  	unsigned int r0_reg, cali_done;
>>>  	unsigned int r0_calib, temperature_calib;
>>>  	int recv_spk_mode;
>>> +	int i2s_ref;
>>>  };
>>>
>>>  #endif		/* end of _RT1011_H_ */
>>>
>>
>> --
>> Péter
>> ------Please consider the environment before printing this e-mail.

-- 
Péter

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

* Re: [PATCH] ASoC: rt1011: revert 'I2S Reference' to SOC_ENUM_EXT
  2021-12-01  7:00     ` Péter Ujfalusi
@ 2021-12-01 12:30       ` Mark Brown
  0 siblings, 0 replies; 6+ messages in thread
From: Mark Brown @ 2021-12-01 12:30 UTC (permalink / raw)
  To: Péter Ujfalusi
  Cc: Oder Chiou, Jack Yu, alsa-devel, lars,
	kent_chen@realtek.com [陳建宏],
	lgirdwood, Derek [方德義],
	Shuming [范書銘], Flove(HsinFu)

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

On Wed, Dec 01, 2021 at 09:00:02AM +0200, Péter Ujfalusi wrote:

> This is something like drop dai_fmt and all configuration and
> set ADCDAT1/2 pin to output
> set I2S, 24 bit for rx/tx
> set undocumented BIT12 in RT1011_TDM1_SET_1
> set 'TDM1 DOUT Source' to ALC

I'd expect that last one in particular to be a DAPM route.

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

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

end of thread, other threads:[~2021-12-01 12:31 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-11  9:17 [PATCH] ASoC: rt1011: revert 'I2S Reference' to SOC_ENUM_EXT Jack Yu
2021-11-12 21:27 ` Mark Brown
2021-11-30 11:24 ` Péter Ujfalusi
2021-12-01  2:36   ` Jack Yu
2021-12-01  7:00     ` Péter Ujfalusi
2021-12-01 12:30       ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).