Skip to contentSkip to conversation

ASoC: rt712-sdca: Add RT712 SDCA driver for Jack and Amp topology

PATCH In review [email protected] 2 participants 6 messages Feb 7, 2023 – Feb 10, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ASoC: rt712-sdca: Add RT712 SDCA driver for Jack and Amp topology

From: Shuming Fan <[email protected]>

This is the initial codec driver for rt712 SDCA (Jack+Amp topology). The host should connect with rt712 SdW1 interface.

---
 sound/soc/codecs/Kconfig          |    7 +
 sound/soc/codecs/Makefile         |    2 +
 sound/soc/codecs/rt712-sdca-sdw.c |  485 +++++++++++
 sound/soc/codecs/rt712-sdca-sdw.h |  108 +++
 sound/soc/codecs/rt712-sdca.c     | 1328 +++++++++++++++++++++++++++++
 sound/soc/codecs/rt712-sdca.h     |  220 +++++
 6 files changed, 2150 insertions(+)
 create mode 100644 sound/soc/codecs/rt712-sdca-sdw.c
 create mode 100644 sound/soc/codecs/rt712-sdca-sdw.h
 create mode 100644 sound/soc/codecs/rt712-sdca.c
 create mode 100644 sound/soc/codecs/rt712-sdca.h
sound/soc/codecs/Kconfig +7 -0
index 5028d67cfd8e..02141788ad9d 100644
@@ -198,6 +198,7 @@ config SND_SOC_ALL_CODECS
 	imply SND_SOC_RT700_SDW
 	imply SND_SOC_RT711_SDW
 	imply SND_SOC_RT711_SDCA_SDW
+	imply SND_SOC_RT712_SDCA_SDW
 	imply SND_SOC_RT715_SDW
 	imply SND_SOC_RT715_SDCA_SDW
 	imply SND_SOC_RT1308_SDW
@@ -1462,6 +1463,12 @@ config SND_SOC_RT711_SDCA_SDW
 	select REGMAP_SOUNDWIRE
 	select REGMAP_SOUNDWIRE_MBQ
 
+config SND_SOC_RT712_SDCA_SDW
+	tristate "Realtek RT712 SDCA Codec - SDW"
+	depends on SOUNDWIRE
+	select REGMAP_SOUNDWIRE
+	select REGMAP_SOUNDWIRE_MBQ
+
 config SND_SOC_RT715
 	tristate
 
sound/soc/codecs/Makefile +2 -0
index e88cb8b5baec..72faf83138eb 100644
@@ -227,6 +227,7 @@ snd-soc-rt5682s-objs := rt5682s.o
 snd-soc-rt700-objs := rt700.o rt700-sdw.o
 snd-soc-rt711-objs := rt711.o rt711-sdw.o
 snd-soc-rt711-sdca-objs := rt711-sdca.o rt711-sdca-sdw.o
+snd-soc-rt712-sdca-objs := rt712-sdca.o rt712-sdca-sdw.o
 snd-soc-rt715-objs := rt715.o rt715-sdw.o
 snd-soc-rt715-sdca-objs := rt715-sdca.o rt715-sdca-sdw.o
 snd-soc-rt9120-objs := rt9120.o
@@ -589,6 +590,7 @@ obj-$(CONFIG_SND_SOC_RT5682S)	+= snd-soc-rt5682s.o
 obj-$(CONFIG_SND_SOC_RT700)     += snd-soc-rt700.o
 obj-$(CONFIG_SND_SOC_RT711)     += snd-soc-rt711.o
 obj-$(CONFIG_SND_SOC_RT711_SDCA_SDW)     += snd-soc-rt711-sdca.o
+obj-$(CONFIG_SND_SOC_RT712_SDCA_SDW)     += snd-soc-rt712-sdca.o
 obj-$(CONFIG_SND_SOC_RT715)     += snd-soc-rt715.o
 obj-$(CONFIG_SND_SOC_RT715_SDCA_SDW)     += snd-soc-rt715-sdca.o
 obj-$(CONFIG_SND_SOC_RT9120)	+= snd-soc-rt9120.o
sound/soc/codecs/rt712-sdca-sdw.c new file +485 -0

485 lines not on this page · raw message

sound/soc/codecs/rt712-sdca-sdw.h new file +108 -0

108 lines not on this page · raw message

sound/soc/codecs/rt712-sdca.c new file +1328 -0

1,328 lines not on this page · raw message

sound/soc/codecs/rt712-sdca.h new file +220 -0

220 lines not on this page · raw message

Signature · 1 line
2.38.1
maintainer
#1 lore raw

sound/soc/codecs/rt712-sdca.c line 370

Quoted 9 lines · On Tue, Feb 07, 2023 at 05:09:46PM +0800, [email protected] wrote:
sound/soc/codecs/rt712-sdca.c new file +8 -0
+	/* pin attached */
+	if (det_mode) {
+		/* read UMP message offset */
+		ret = regmap_read(rt712->regmap,
 
+			}
+		}
+	} else
+		rt712->jack_type = 0;

If one side of an if has { } the other side should too for clarity.

#2 lore raw
Quoted 11 lines

sound/soc/codecs/rt712-sdca.c line 370

Quoted 9 lines
sound/soc/codecs/rt712-sdca.c new file +8 -0
+	/* pin attached */
+	if (det_mode) {
+		/* read UMP message offset */
+		ret = regmap_read(rt712->regmap,
 
+			}
+		}
+	} else
+		rt712->jack_type = 0;

If one side of an if has { } the other side should too for clarity.

Sure, will send patch to fix.

Quoted 1 line

------Please consider the environment before printing this e-mail.

maintainer
#3 lore raw
In reply to [email protected]
Quoted 8 lines · On Tue, Feb 07, 2023 at 05:09:46PM +0800, [email protected] wrote:
sound/soc/codecs/rt712-sdca.c new file +8 -0
+static int rt712_sdca_mux_put(struct snd_kcontrol *kcontrol,
+			struct snd_ctl_elem_value *ucontrol)
+{
+	struct snd_soc_component *component =
+		snd_soc_dapm_kcontrol_component(kcontrol);
+	struct snd_soc_dapm_context *dapm =
+		snd_soc_dapm_kcontrol_dapm(kcontrol);
+	struct rt712_sdca_priv *rt712 = snd_soc_component_get_drvdata(component);

sound/soc/codecs/rt712-sdca.c line 730

Quoted 10 lines
sound/soc/codecs/rt712-sdca.c new file +9 -0
+	struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
+	unsigned int *item = ucontrol->value.enumerated.item;
+	unsigned int mask_sft;
 
+
+	snd_soc_dapm_mux_update_power(dapm, kcontrol,
+		item[0], e, NULL);
+
+	return 1;
+}

This unconditionally returns 1 if the value written is in bounds which means that an event will always be signalled. Please use mixer-test to check for this and other issues.

Quoted 4 lines
sound/soc/codecs/rt712-sdca.c new file +4 -0
+	/* set sampling frequency */
+	if (dai->id == RT712_AIF1) {
+		regmap_write(rt712->regmap,
+			SDW_SDCA_CTL(FUNC_NUM_JACK_CODEC, RT712_SDCA_ENT_CS01, RT712_SDCA_CTL_SAMPLE_FREQ_INDEX, 0),

sound/soc/codecs/rt712-sdca.c line 1109

Quoted 10 lines
sound/soc/codecs/rt712-sdca.c new file +10 -0
+			sampling_rate);
+		regmap_write(rt712->regmap,
+			SDW_SDCA_CTL(FUNC_NUM_JACK_CODEC, RT712_SDCA_ENT_CS11, RT712_SDCA_CTL_SAMPLE_FREQ_INDEX, 0),
+			sampling_rate);
+	}
+
+	if (dai->id == RT712_AIF2)
+		regmap_write(rt712->regmap,
+			SDW_SDCA_CTL(FUNC_NUM_AMP, RT712_SDCA_ENT_CS31, RT712_SDCA_CTL_SAMPLE_FREQ_INDEX, 0),
+			sampling_rate);

This would be better written as a switch statement, there were some other checks for variants that looked to have similar issues. It makes it clearer that only one option can be selected and allows you to have a default check that makes sure that any new variant with another AIF gets handled.

#4 lore raw
Quoted 14 lines · On Tue, Feb 07, 2023 at 05:09:46PM +0800, [email protected] wrote:

sound/soc/codecs/rt712-sdca.c

Quoted 8 lines
sound/soc/codecs/rt712-sdca.c new file +7 -0
+static int rt712_sdca_mux_put(struct snd_kcontrol *kcontrol,
+			struct snd_ctl_elem_value *ucontrol) {
+	struct snd_soc_component *component =
+		snd_soc_dapm_kcontrol_component(kcontrol);
+	struct snd_soc_dapm_context *dapm =
+		snd_soc_dapm_kcontrol_dapm(kcontrol);
+	struct rt712_sdca_priv *rt712 =

snd_soc_component_get_drvdata(component);

Quoted 3 lines
sound/soc/codecs/rt712-sdca.c new file +3 -0
+	struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
+	unsigned int *item = ucontrol->value.enumerated.item;
+	unsigned int mask_sft;
Quoted 10 lines

sound/soc/codecs/rt712-sdca.c line 730

Quoted 6 lines
sound/soc/codecs/rt712-sdca.c new file +6 -0
+
+	snd_soc_dapm_mux_update_power(dapm, kcontrol,
+		item[0], e, NULL);
+
+	return 1;
+}

This unconditionally returns 1 if the value written is in bounds which means that an event will always be signalled. Please use mixer-test to check for this and other issues.

I will add the code to check.
return 0 if no need to be changed
return 1 if needs to be changed
Thanks.

Quoted 16 lines

sound/soc/codecs/rt712-sdca.c

Quoted 4 lines
sound/soc/codecs/rt712-sdca.c new file +4 -0
+	/* set sampling frequency */
+	if (dai->id == RT712_AIF1) {
+		regmap_write(rt712->regmap,
+			SDW_SDCA_CTL(FUNC_NUM_JACK_CODEC,

RT712_SDCA_ENT_CS01, RT712_SDCA_CTL_SAMPLE_FREQ_INDEX, 0),

sound/soc/codecs/rt712-sdca.c

Quoted 3 lines
sound/soc/codecs/rt712-sdca.c new file +3 -0
+			sampling_rate);
+		regmap_write(rt712->regmap,
+			SDW_SDCA_CTL(FUNC_NUM_JACK_CODEC,

RT712_SDCA_ENT_CS11, RT712_SDCA_CTL_SAMPLE_FREQ_INDEX, 0),

sound/soc/codecs/rt712-sdca.c

Quoted 6 lines
sound/soc/codecs/rt712-sdca.c new file +6 -0
+			sampling_rate);
+	}
+
+	if (dai->id == RT712_AIF2)
+		regmap_write(rt712->regmap,
+			SDW_SDCA_CTL(FUNC_NUM_AMP, RT712_SDCA_ENT_CS31,

RT712_SDCA_CTL_SAMPLE_FREQ_INDEX, 0),

Quoted 6 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+			sampling_rate);

This would be better written as a switch statement, there were some other checks for variants that looked to have similar issues. It makes it clearer that only one option can be selected and allows you to have a default check that makes sure that any new variant with another AIF gets handled.

OK, will send the patch to fix.

Quoted 1 line

------Please consider the environment before printing this e-mail.

maintainer
#5 lore raw
In reply to [email protected]
Quoted 4 lines · On Tue, 07 Feb 2023 17:09:46 +0800, [email protected] wrote:

This is the initial codec driver for rt712 SDCA (Jack+Amp topology). The host should connect with rt712 SdW1 interface.

Applied to

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

Thanks!

[1/1] ASoC: rt712-sdca: Add RT712 SDCA driver for Jack and Amp topology

      commit: 6c39710da75caabc5f459a3f73fbb7435b4000aa

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