diff mbox series

ASoC: rt1011: add i2s reference control for rt1011

Message ID 20210906101208.11585-1-jack.yu@realtek.com (mailing list archive)
State Accepted
Commit 87f40af26c26233b060767f3e7cff5e54647cf2b
Headers show
Series ASoC: rt1011: add i2s reference control for rt1011 | expand

Commit Message

Jack Yu Sept. 6, 2021, 10:12 a.m. UTC
Add i2s reference control for rt1011 amp.

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

Comments

Pierre-Louis Bossart Sept. 7, 2021, 2:53 p.m. UTC | #1
On 9/6/21 5:12 AM, Jack Yu wrote:
> Add i2s reference control for rt1011 amp.
> 
> Signed-off-by: Jack Yu <jack.yu@realtek.com>

> +static const char * const rt1011_i2s_ref[] = {
> +	"None", "Left Channel", "Right Channel"
> +};

> +enum {
> +	RT1011_I2S_REF_NONE,
> +	RT1011_I2S_REF_LEFT_CH,
> +	RT1011_I2S_REF_RIGHT_CH,
> +};

is it possible to get Left-Right-mix (mixed on rt1011) and Left-Right
(two channels, with the application selecting what they want)?
Jack Yu Sept. 8, 2021, 2:17 a.m. UTC | #2
> -----Original Message-----
> From: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
> Sent: Tuesday, September 7, 2021 10:54 PM
> To: Jack Yu <jack.yu@realtek.com>; broonie@kernel.org;
> lgirdwood@gmail.com
> Cc: Oder Chiou <oder_chiou@realtek.com>; alsa-devel@alsa-project.org;
> lars@metafoo.de; kent_chen@realtek.com [陳建宏]
> <kent_chen@realtek.com>; Derek [方德義] <derek.fang@realtek.com>;
> Shuming [范書銘] <shumingf@realtek.com>; Flove(HsinFu)
> <flove@realtek.com>
> Subject: Re: [PATCH] ASoC: rt1011: add i2s reference control for rt1011
> 
> On 9/6/21 5:12 AM, Jack Yu wrote:
> > Add i2s reference control for rt1011 amp.
> >
> > Signed-off-by: Jack Yu <jack.yu@realtek.com>
> 
> > +static const char * const rt1011_i2s_ref[] = {
> > +	"None", "Left Channel", "Right Channel"
> > +};
> 
> > +enum {
> > +	RT1011_I2S_REF_NONE,
> > +	RT1011_I2S_REF_LEFT_CH,
> > +	RT1011_I2S_REF_RIGHT_CH,
> > +};
> 
> is it possible to get Left-Right-mix (mixed on rt1011) and Left-Right (two
> channels, with the application selecting what they want)?

It's a mono amp, so there's no Left-Right-mix setting. 
And for the choice of Left-Right channel, it's already available with this patch.

> 
> ------Please consider the environment before printing this e-mail.
Pierre-Louis Bossart Sept. 8, 2021, 3:22 p.m. UTC | #3
On 9/7/21 9:17 PM, Jack Yu wrote:
> 
>> -----Original Message-----
>> From: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
>> Sent: Tuesday, September 7, 2021 10:54 PM
>> To: Jack Yu <jack.yu@realtek.com>; broonie@kernel.org;
>> lgirdwood@gmail.com
>> Cc: Oder Chiou <oder_chiou@realtek.com>; alsa-devel@alsa-project.org;
>> lars@metafoo.de; kent_chen@realtek.com [陳建宏]
>> <kent_chen@realtek.com>; Derek [方德義] <derek.fang@realtek.com>;
>> Shuming [范書銘] <shumingf@realtek.com>; Flove(HsinFu)
>> <flove@realtek.com>
>> Subject: Re: [PATCH] ASoC: rt1011: add i2s reference control for rt1011
>>
>> On 9/6/21 5:12 AM, Jack Yu wrote:
>>> Add i2s reference control for rt1011 amp.
>>>
>>> Signed-off-by: Jack Yu <jack.yu@realtek.com>
>>
>>> +static const char * const rt1011_i2s_ref[] = {
>>> +	"None", "Left Channel", "Right Channel"
>>> +};
>>
>>> +enum {
>>> +	RT1011_I2S_REF_NONE,
>>> +	RT1011_I2S_REF_LEFT_CH,
>>> +	RT1011_I2S_REF_RIGHT_CH,
>>> +};
>>
>> is it possible to get Left-Right-mix (mixed on rt1011) and Left-Right (two
>> channels, with the application selecting what they want)?
> 
> It's a mono amp, so there's no Left-Right-mix setting. 
> And for the choice of Left-Right channel, it's already available with this patch.

So it's just to place a mono reference in either left or right channel
of the I2S link? Why not dual-mono as well then?
Jack Yu Sept. 9, 2021, 2:40 a.m. UTC | #4
> -----Original Message-----
> From: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
> Sent: Wednesday, September 8, 2021 11:23 PM
> To: Jack Yu <jack.yu@realtek.com>; broonie@kernel.org;
> lgirdwood@gmail.com
> Cc: Oder Chiou <oder_chiou@realtek.com>; alsa-devel@alsa-project.org;
> lars@metafoo.de; kent_chen@realtek.com [陳建宏]
> <kent_chen@realtek.com>; Derek [方德義] <derek.fang@realtek.com>;
> Shuming [范書銘] <shumingf@realtek.com>; Flove(HsinFu)
> <flove@realtek.com>
> Subject: Re: [PATCH] ASoC: rt1011: add i2s reference control for rt1011
> 
> On 9/7/21 9:17 PM, Jack Yu wrote:
> >
> >> -----Original Message-----
> >> From: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
> >> Sent: Tuesday, September 7, 2021 10:54 PM
> >> To: Jack Yu <jack.yu@realtek.com>; broonie@kernel.org;
> >> lgirdwood@gmail.com
> >> Cc: Oder Chiou <oder_chiou@realtek.com>; alsa-devel@alsa-project.org;
> >> lars@metafoo.de; kent_chen@realtek.com [陳建宏]
> >> <kent_chen@realtek.com>; Derek [方德義] <derek.fang@realtek.com>;
> >> Shuming [范書銘] <shumingf@realtek.com>; Flove(HsinFu)
> >> <flove@realtek.com>
> >> Subject: Re: [PATCH] ASoC: rt1011: add i2s reference control for
> >> rt1011
> >>
> >> On 9/6/21 5:12 AM, Jack Yu wrote:
> >>> Add i2s reference control for rt1011 amp.
> >>>
> >>> Signed-off-by: Jack Yu <jack.yu@realtek.com>
> >>
> >>> +static const char * const rt1011_i2s_ref[] = {
> >>> +	"None", "Left Channel", "Right Channel"
> >>> +};
> >>
> >>> +enum {
> >>> +	RT1011_I2S_REF_NONE,
> >>> +	RT1011_I2S_REF_LEFT_CH,
> >>> +	RT1011_I2S_REF_RIGHT_CH,
> >>> +};
> >>
> >> is it possible to get Left-Right-mix (mixed on rt1011) and Left-Right
> >> (two channels, with the application selecting what they want)?
> >
> > It's a mono amp, so there's no Left-Right-mix setting.
> > And for the choice of Left-Right channel, it's already available with this
> patch.
> 
> So it's just to place a mono reference in either left or right channel of the I2S
> link? Why not dual-mono as well then?

The patch is a specific control for two amps to send AEC data on single I2S data input pin by standard I2S protocol. 
If there are two I2S input from SoC, we can add dual-mono mode for it, but so far there is no requirement regarding to this mode.

> ------Please consider the environment before printing this e-mail.
Pierre-Louis Bossart Sept. 9, 2021, 3:25 a.m. UTC | #5
>>>>> +static const char * const rt1011_i2s_ref[] = {
>>>>> +	"None", "Left Channel", "Right Channel"
>>>>> +};
>>>>
>>>>> +enum {
>>>>> +	RT1011_I2S_REF_NONE,
>>>>> +	RT1011_I2S_REF_LEFT_CH,
>>>>> +	RT1011_I2S_REF_RIGHT_CH,
>>>>> +};
>>>>
>>>> is it possible to get Left-Right-mix (mixed on rt1011) and Left-Right
>>>> (two channels, with the application selecting what they want)?
>>>
>>> It's a mono amp, so there's no Left-Right-mix setting.
>>> And for the choice of Left-Right channel, it's already available with this
>> patch.
>>
>> So it's just to place a mono reference in either left or right channel of the I2S
>> link? Why not dual-mono as well then?
> 
> The patch is a specific control for two amps to send AEC data on single I2S data input pin by standard I2S protocol. 

That's really useful information and worthy of a comment.

What you are doing here is similar to selecting the slot for each amp
with set_tdm_slot(), but leaving the choice to userspace, isn't it?

> If there are two I2S input from SoC, we can add dual-mono mode for it, but so far there is no requirement regarding to this mode.

ok.
Jack Yu Sept. 9, 2021, 5:17 a.m. UTC | #6
> -----Original Message-----
> From: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
> Sent: Thursday, September 9, 2021 11:26 AM
> To: Jack Yu <jack.yu@realtek.com>; broonie@kernel.org;
> lgirdwood@gmail.com
> Cc: Oder Chiou <oder_chiou@realtek.com>; alsa-devel@alsa-project.org;
> lars@metafoo.de; kent_chen@realtek.com [陳建宏]
> <kent_chen@realtek.com>; Derek [方德義] <derek.fang@realtek.com>;
> Shuming [范書銘] <shumingf@realtek.com>; Flove(HsinFu)
> <flove@realtek.com>
> Subject: Re: [PATCH] ASoC: rt1011: add i2s reference control for rt1011
> 
> >>>>> +static const char * const rt1011_i2s_ref[] = {
> >>>>> +	"None", "Left Channel", "Right Channel"
> >>>>> +};
> >>>>
> >>>>> +enum {
> >>>>> +	RT1011_I2S_REF_NONE,
> >>>>> +	RT1011_I2S_REF_LEFT_CH,
> >>>>> +	RT1011_I2S_REF_RIGHT_CH,
> >>>>> +};
> >>>>
> >>>> is it possible to get Left-Right-mix (mixed on rt1011) and
> >>>> Left-Right (two channels, with the application selecting what they want)?
> >>>
> >>> It's a mono amp, so there's no Left-Right-mix setting.
> >>> And for the choice of Left-Right channel, it's already available
> >>> with this
> >> patch.
> >>
> >> So it's just to place a mono reference in either left or right
> >> channel of the I2S link? Why not dual-mono as well then?
> >
> > The patch is a specific control for two amps to send AEC data on single I2S
> data input pin by standard I2S protocol.
> 
> That's really useful information and worthy of a comment.
> 
> What you are doing here is similar to selecting the slot for each amp with
> set_tdm_slot(), but leaving the choice to userspace, isn't it?
> 
Yes.

> > If there are two I2S input from SoC, we can add dual-mono mode for it, but
> so far there is no requirement regarding to this mode.
> 
> ok.
> 
> ------Please consider the environment before printing this e-mail.
Mark Brown Sept. 13, 2021, 10:53 a.m. UTC | #7
On Mon, 6 Sep 2021 18:12:08 +0800, Jack Yu wrote:
> Add i2s reference control for rt1011 amp.
> 
> 

Applied to

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

Thanks!

[1/1] ASoC: rt1011: add i2s reference control for rt1011
      commit: 87f40af26c26233b060767f3e7cff5e54647cf2b

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
diff mbox series

Patch

diff --git a/sound/soc/codecs/rt1011.c b/sound/soc/codecs/rt1011.c
index faff2b558687..508597866dff 100644
--- a/sound/soc/codecs/rt1011.c
+++ b/sound/soc/codecs/rt1011.c
@@ -1311,6 +1311,57 @@  static int rt1011_r0_load_info(struct snd_kcontrol *kcontrol,
 	.put = rt1011_r0_load_mode_put \
 }
 
+static const char * const rt1011_i2s_ref[] = {
+	"None", "Left Channel", "Right Channel"
+};
+
+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);
+	int i2s_ref_ch = ucontrol->value.integer.value[0];
+
+	switch (i2s_ref_ch) {
+	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");
+	}
+
+	rt1011->i2s_ref = ucontrol->value.integer.value[0];
+
+	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.integer.value[0] = rt1011->i2s_ref;
+
+	return 0;
+}
+
 static const struct snd_kcontrol_new rt1011_snd_controls[] = {
 	/* I2S Data In Selection */
 	SOC_ENUM("DIN Source", rt1011_din_source_enum),
@@ -1349,6 +1400,9 @@  static const struct snd_kcontrol_new rt1011_snd_controls[] = {
 	/* R0 temperature */
 	SOC_SINGLE("R0 Temperature", RT1011_STP_INITIAL_RESISTANCE_TEMP,
 		2, 255, 0),
+	/* I2S Reference */
+	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,
diff --git a/sound/soc/codecs/rt1011.h b/sound/soc/codecs/rt1011.h
index 68fadc15fa8c..afb2fad94216 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;
+	unsigned int i2s_ref;
 };
 
 #endif		/* end of _RT1011_H_ */