Skip to contentSkip to conversation

ASoC: rt712-sdca: Add FU05 playback switch control

PATCH In review [email protected] 2 participants 2 messages Feb 26, 2025

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

PATCH 1/1 ASoC: rt712-sdca: Add FU05 playback switch control

From: Shuming Fan <[email protected]>

Because there is no playback switch control for rt712-sdw headphone endpoint, it causes there is no way to control HP on and off in ALSA UCM config.

---
 sound/soc/codecs/rt712-sdca.c | 80 +++++++++++++++++++++++++++--------
 sound/soc/codecs/rt712-sdca.h |  3 ++
 2 files changed, 66 insertions(+), 17 deletions(-)
sound/soc/codecs/rt712-sdca.c +63 -17
index 78dbf9eed494..19d99b9d4ab2 100644
@@ -652,6 +652,61 @@ static int rt712_sdca_fu0f_capture_put(struct snd_kcontrol *kcontrol,
 	return 1;
 }
 
+static int rt712_sdca_set_fu05_playback_ctl(struct rt712_sdca_priv *rt712)
+{
+	int err;
+	unsigned int ch_01, ch_02;
+
+	ch_01 = (rt712->fu05_dapm_mute || rt712->fu05_mixer_l_mute) ? 0x01 : 0x00;
+	ch_02 = (rt712->fu05_dapm_mute || rt712->fu05_mixer_r_mute) ? 0x01 : 0x00;
+
+	err = regmap_write(rt712->regmap,
+			SDW_SDCA_CTL(FUNC_NUM_JACK_CODEC, RT712_SDCA_ENT_USER_FU05,
+			RT712_SDCA_CTL_FU_MUTE, CH_01), ch_01);
+	if (err < 0)
+		return err;
+
+	err = regmap_write(rt712->regmap,
+			SDW_SDCA_CTL(FUNC_NUM_JACK_CODEC, RT712_SDCA_ENT_USER_FU05,
+			RT712_SDCA_CTL_FU_MUTE, CH_02), ch_02);
+	if (err < 0)
+		return err;
+
+	return 0;
+}
+
+static int rt712_sdca_fu05_playback_get(struct snd_kcontrol *kcontrol,
+	struct snd_ctl_elem_value *ucontrol)
+{
+	struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
+	struct rt712_sdca_priv *rt712 = snd_soc_component_get_drvdata(component);
+
+	ucontrol->value.integer.value[0] = !rt712->fu05_mixer_l_mute;
+	ucontrol->value.integer.value[1] = !rt712->fu05_mixer_r_mute;
+	return 0;
+}
+
+static int rt712_sdca_fu05_playback_put(struct snd_kcontrol *kcontrol,
+	struct snd_ctl_elem_value *ucontrol)
+{
+	struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
+	struct rt712_sdca_priv *rt712 = snd_soc_component_get_drvdata(component);
+	int err;
+
+	if (rt712->fu05_mixer_l_mute == !ucontrol->value.integer.value[0] &&
+		rt712->fu05_mixer_r_mute == !ucontrol->value.integer.value[1])
+		return 0;
+
+	rt712->fu05_mixer_l_mute = !ucontrol->value.integer.value[0];
+	rt712->fu05_mixer_r_mute = !ucontrol->value.integer.value[1];
+
+	err = rt712_sdca_set_fu05_playback_ctl(rt712);
+	if (err < 0)
+		return err;
+
+	return 1;
+}
+
 static const DECLARE_TLV_DB_SCALE(out_vol_tlv, -6525, 75, 0);
 static const DECLARE_TLV_DB_SCALE(mic_vol_tlv, -1725, 75, 0);
 static const DECLARE_TLV_DB_SCALE(boost_vol_tlv, 0, 1000, 0);
@@ -674,6 +729,8 @@ static const struct snd_kcontrol_new rt712_sdca_controls[] = {
 		SDW_SDCA_CTL(FUNC_NUM_JACK_CODEC, RT712_SDCA_ENT_PLATFORM_FU44, RT712_SDCA_CTL_FU_CH_GAIN, CH_02),
 		8, 3, 0,
 		rt712_sdca_set_gain_get, rt712_sdca_set_gain_put, boost_vol_tlv),
+	SOC_DOUBLE_EXT("FU05 Playback Switch", SND_SOC_NOPM, 0, 1, 1, 0,
+		rt712_sdca_fu05_playback_get, rt712_sdca_fu05_playback_put),
 };
 
 static const struct snd_kcontrol_new rt712_sdca_spk_controls[] = {
@@ -766,28 +823,15 @@ static int rt712_sdca_fu05_event(struct snd_soc_dapm_widget *w,
 	struct snd_soc_component *component =
 		snd_soc_dapm_to_component(w->dapm);
 	struct rt712_sdca_priv *rt712 = snd_soc_component_get_drvdata(component);
-	unsigned char unmute = 0x0, mute = 0x1;
 
 	switch (event) {
 	case SND_SOC_DAPM_POST_PMU:
-		regmap_write(rt712->regmap,
-			SDW_SDCA_CTL(FUNC_NUM_JACK_CODEC, RT712_SDCA_ENT_USER_FU05,
-				RT712_SDCA_CTL_FU_MUTE, CH_01),
-				unmute);
-		regmap_write(rt712->regmap,
-			SDW_SDCA_CTL(FUNC_NUM_JACK_CODEC, RT712_SDCA_ENT_USER_FU05,
-				RT712_SDCA_CTL_FU_MUTE, CH_02),
-				unmute);
+		rt712->fu05_dapm_mute = false;
+		rt712_sdca_set_fu05_playback_ctl(rt712);
 		break;
 	case SND_SOC_DAPM_PRE_PMD:
-		regmap_write(rt712->regmap,
-			SDW_SDCA_CTL(FUNC_NUM_JACK_CODEC, RT712_SDCA_ENT_USER_FU05,
-				RT712_SDCA_CTL_FU_MUTE, CH_01),
-				mute);
-		regmap_write(rt712->regmap,
-			SDW_SDCA_CTL(FUNC_NUM_JACK_CODEC, RT712_SDCA_ENT_USER_FU05,
-				RT712_SDCA_CTL_FU_MUTE, CH_02),
-				mute);
+		rt712->fu05_dapm_mute = true;
+		rt712_sdca_set_fu05_playback_ctl(rt712);
 		break;
 	}
 	return 0;
@@ -1640,6 +1684,8 @@ int rt712_sdca_init(struct device *dev, struct regmap *regmap,
 	rt712->fu1e_dapm_mute = true;
 	rt712->fu1e_mixer_mute[0] = rt712->fu1e_mixer_mute[1] =
 		rt712->fu1e_mixer_mute[2] = rt712->fu1e_mixer_mute[3] = true;
+	rt712->fu05_dapm_mute = true;
+	rt712->fu05_mixer_l_mute = rt712->fu05_mixer_r_mute = false;
 
 	/* JD source uses JD1 in default */
 	rt712->jd_src = RT712_JD1;
sound/soc/codecs/rt712-sdca.h +3 -0
index a08491496d90..7ab7d5feb50a 100644
@@ -42,6 +42,9 @@ struct  rt712_sdca_priv {
 	bool fu0f_mixer_r_mute;
 	bool fu1e_dapm_mute;
 	bool fu1e_mixer_mute[4];
+	bool fu05_dapm_mute;
+	bool fu05_mixer_l_mute;
+	bool fu05_mixer_r_mute;
 };
 
 struct rt712_dmic_kctrl_priv {
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 4 lines · On Wed, 26 Feb 2025 16:47:28 +0800, [email protected] wrote:

Because there is no playback switch control for rt712-sdw headphone endpoint, it causes there is no way to control HP on and off in ALSA UCM config.

Applied to

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

Thanks!

[1/1] ASoC: rt712-sdca: Add FU05 playback switch control

      commit: 62142da241a08006f89b0620f7291e3a08c0a094

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