From 98c6b31384477c771ba47a5f34384d0b8c7dcfc4 Mon Sep 17 00:00:00 2001
From: The-going <48602507+The-going@users.noreply.github.com>
Date: Wed, 2 Feb 2022 21:42:37 +0300
Subject: sound:soc:sunxi:sun4i-codec adcis select capture source

---
 sound/soc/sunxi/sun4i-codec.c | 51 ++++++++++++++++++++++++++++++++---
 1 file changed, 47 insertions(+), 4 deletions(-)

diff --git a/sound/soc/sunxi/sun4i-codec.c b/sound/soc/sunxi/sun4i-codec.c
index 886b3fa537d2..5b67e2905a44 100644
--- a/sound/soc/sunxi/sun4i-codec.c
+++ b/sound/soc/sunxi/sun4i-codec.c
@@ -6,6 +6,7 @@
  * Copyright 2015 Adam Sampson <ats@offog.org>
  * Copyright 2016 Chen-Yu Tsai <wens@csie.org>
  * Copyright 2018 Mesih Kilinc <mesihkilinc@gmail.com>
+ * Copyright 2021 gryzun <gryzun_an@rambler.ru>
  *
  * Based on the Allwinner SDK driver, released under the GPL.
  */
@@ -743,6 +744,16 @@ static struct snd_soc_dai_driver sun4i_codec_dai = {
 };
 
 /*** sun4i Codec ***/
+
+static const char *adcis_text[] = {"Line In", "FM In", "Mic1 Mono", "Mic2 Mono",
+			"Mic1,Mic2", "Mic1+2 Mono", "MIX Out", "Line,Mic1"};
+
+static SOC_ENUM_SINGLE_DECL(adcis_mixer, SUN4I_CODEC_ADC_ACTL,
+					SUN4I_CODEC_ADC_ACTL_ADCIS, adcis_text);
+
+static const struct snd_kcontrol_new sun4i_codec_mux_controls =
+	SOC_DAPM_ENUM("Capture Source Capture Route", adcis_mixer);
+
 static const struct snd_kcontrol_new sun4i_codec_pa_mute =
 	SOC_DAPM_SINGLE("Switch", SUN4I_CODEC_DAC_ACTL,
 			SUN4I_CODEC_DAC_ACTL_PA_MUTE, 1, 0);
@@ -756,6 +767,8 @@ static DECLARE_TLV_DB_SCALE(sun4i_codec_fmin_loopback_gain_scale, -450, 150,
 			    0);
 static DECLARE_TLV_DB_SCALE(sun4i_codec_micin_loopback_gain_scale, -450, 150,
 			    0);
+static DECLARE_TLV_DB_SCALE(sun4i_codec_capture_gain_scale, -450, 150,
+			    0);
 static DECLARE_TLV_DB_RANGE(sun4i_codec_micin_preamp_gain_scale,
 			    0, 0, TLV_DB_SCALE_ITEM(0, 0, 0),
 			    1, 7, TLV_DB_SCALE_ITEM(3500, 300, 0));
@@ -809,6 +822,9 @@ static const struct snd_kcontrol_new sun7i_codec_controls[] = {
 	SOC_SINGLE_TLV("Mic2 Boost Volume", SUN7I_CODEC_AC_MIC_PHONE_CAL,
 		       SUN7I_CODEC_AC_MIC_PHONE_CAL_PREG2, 7, 0,
 		       sun7i_codec_micin_preamp_gain_scale),
+	SOC_SINGLE_TLV("Capture Boost Capture Volume", SUN4I_CODEC_ADC_ACTL,
+		       SUN4I_CODEC_ADC_ACTL_VADCG, 7, 0,
+		       sun4i_codec_capture_gain_scale),
 };
 
 static const struct snd_kcontrol_new sun4i_codec_mixer_controls[] = {
@@ -887,6 +903,13 @@ static const struct snd_soc_dapm_widget sun4i_codec_codec_dapm_widgets[] = {
 	SND_SOC_DAPM_PGA("MIC2 Pre-Amplifier", SUN4I_CODEC_ADC_ACTL,
 			 SUN4I_CODEC_ADC_ACTL_PREG2EN, 0, NULL, 0),
 
+	/* ADC Mux */
+	SND_SOC_DAPM_MUX("Right Capture Source Capture Route", SND_SOC_NOPM, 0, 0,
+		&sun4i_codec_mux_controls),
+
+	SND_SOC_DAPM_MUX("Left Capture Source Capture Route", SND_SOC_NOPM, 0, 0,
+		&sun4i_codec_mux_controls),
+
 	/* Power Amplifier */
 	SND_SOC_DAPM_MIXER("Power Amplifier", SUN4I_CODEC_ADC_ACTL,
 			   SUN4I_CODEC_ADC_ACTL_PA_EN, 0,
@@ -915,6 +938,30 @@ static const struct snd_soc_dapm_route sun4i_codec_codec_dapm_routes[] = {
 	{ "Right ADC", NULL, "ADC" },
 	{ "Right DAC", NULL, "DAC" },
 
+	/* Left Mux Capture Routes */
+	{ "Left Capture Source Capture Route", "Mic1 Mono", "MIC1 Pre-Amplifier" },
+	{ "Left Capture Source Capture Route", "Mic2 Mono", "MIC2 Pre-Amplifier" },
+	{ "Left Capture Source Capture Route", "Line In", "Line Left" },
+	{ "Left Capture Source Capture Route", "FM In", "FM Left" },
+	{ "Left Capture Source Capture Route", "MIX Out", "Left Mixer" },
+	{ "Left Capture Source Capture Route", "Mic1,Mic2", "MIC1 Pre-Amplifier" },
+	{ "Left Capture Source Capture Route", "Mic1+2 Mono", "MIC1 Pre-Amplifier" },
+	{ "Left Capture Source Capture Route", "Mic1+2 Mono", "MIC2 Pre-Amplifier" },
+	{ "Left Capture Source Capture Route", "Line,Mic1", "Line Left" },
+	{ "Left ADC", NULL, "Left Capture Source Capture Route" },
+
+	/* Right Mux Capture Routes */
+	{ "Right Capture Source Capture Route", "Mic1 Mono", "MIC1 Pre-Amplifier" },
+	{ "Right Capture Source Capture Route", "Mic2 Mono", "MIC2 Pre-Amplifier" },
+	{ "Right Capture Source Capture Route", "Line In", "Line Right" },
+	{ "Right Capture Source Capture Route", "FM In", "FM Right" },
+	{ "Right Capture Source Capture Route", "MIX Out", "Right Mixer" },
+	{ "Right Capture Source Capture Route", "Mic1,Mic2", "MIC2 Pre-Amplifier" },
+	{ "Right Capture Source Capture Route", "Mic1+2 Mono", "MIC1 Pre-Amplifier" },
+	{ "Right Capture Source Capture Route", "Mic1+2 Mono", "MIC2 Pre-Amplifier" },
+	{ "Right Capture Source Capture Route", "Line,Mic1", "MIC1 Pre-Amplifier" },
+	{ "Right ADC", NULL, "Right Capture Source Capture Route" },
+
 	/* Right Mixer Routes */
 	{ "Right Mixer", NULL, "Mixer Enable" },
 	{ "Right Mixer", "Right Mixer Left DAC Playback Switch", "Left DAC" },
@@ -944,14 +991,10 @@ static const struct snd_soc_dapm_route sun4i_codec_codec_dapm_routes[] = {
 	{ "HP Left", NULL, "Power Amplifier Mute" },
 
 	/* Mic1 Routes */
-	{ "Left ADC", NULL, "MIC1 Pre-Amplifier" },
-	{ "Right ADC", NULL, "MIC1 Pre-Amplifier" },
 	{ "MIC1 Pre-Amplifier", NULL, "Mic1"},
 	{ "Mic1", NULL, "VMIC" },
 
 	/* Mic2 Routes */
-	{ "Left ADC", NULL, "MIC2 Pre-Amplifier" },
-	{ "Right ADC", NULL, "MIC2 Pre-Amplifier" },
 	{ "MIC2 Pre-Amplifier", NULL, "Mic2"},
 	{ "Mic2", NULL, "VMIC" },
 };
-- 
2.35.3

