audio: add audio spdif format kcontrol [1/2]
authorZhe Wang <Zhe.Wang@amlogic.com>
Fri, 11 May 2018 06:53:30 +0000 (14:53 +0800)
committerZhe Wang <Zhe.Wang@amlogic.com>
Fri, 11 May 2018 06:56:00 +0000 (14:56 +0800)
PD#165552: add audio spdif format kcontrol

1) remove drc control for ground noise
2) fast attrack for volume
3) add spdif format kcontrol

Change-Id: I3b4574170d808dd7fe955d249e3414880285eb3e
Signed-off-by: Zhe Wang <Zhe.Wang@amlogic.com>
sound/soc/amlogic/meson/spdif_codec.c
sound/soc/amlogic/meson/tv.c

index a9b66cf..6dc6751 100644 (file)
@@ -28,6 +28,7 @@
 #ifdef CONFIG_AMLOGIC_HDMITX
 #include <linux/amlogic/media/vout/hdmi_tx/hdmi_tx_ext.h>
 #endif
+#include "spdif_dai.h"
 
 #define DRV_NAME "spdif-dit"
 
@@ -83,6 +84,7 @@ void aml_spdif_pinmux_init(struct device *dev)
                                "audio_spdif_out_mute");
                if (IS_ERR(v_spdif_codec.p_pinctrl_out_mute_state)) {
                        devm_pinctrl_put(v_spdif_codec.p_pinctrl_out_mute);
+                       v_spdif_codec.p_pinctrl_out_mute_state = NULL;
                        dev_err(dev, "audio_spdif_out_mute can't get pinctrl\n");
                }
        }
@@ -98,6 +100,7 @@ void aml_spdif_pinmux_init(struct device *dev)
                                "audio_spdif_out");
                if (IS_ERR(v_spdif_codec.p_pinctrl_out_state)) {
                        devm_pinctrl_put(v_spdif_codec.p_pinctrl_out);
+                       v_spdif_codec.p_pinctrl_out_state = NULL;
                        dev_err(dev, "audio_spdif_out can't get pinctrl\n");
                }
        }
@@ -161,6 +164,38 @@ static int aml_audio_get_spdif_mute(struct snd_kcontrol *kcontrol,
        return 0;
 }
 
+static const char *const spdif_format_texts[10] = {
+       "2 CH PCM", "DTS RAW Mode", "Dolby Digital", "DTS",
+       "DD+", "DTS-HD", "Multi-channel LPCM", "TrueHD", "DTS-HD MA",
+       "HIGH SR Stereo LPCM"
+};
+
+static const struct soc_enum spdif_format_enum =
+       SOC_ENUM_SINGLE(SND_SOC_NOPM, 0, ARRAY_SIZE(spdif_format_texts),
+                       spdif_format_texts);
+
+static int spdif_format_get_enum(
+       struct snd_kcontrol *kcontrol,
+       struct snd_ctl_elem_value *ucontrol)
+{
+       ucontrol->value.enumerated.item[0] = IEC958_mode_codec;
+       return 0;
+}
+
+static int spdif_format_set_enum(
+       struct snd_kcontrol *kcontrol,
+       struct snd_ctl_elem_value *ucontrol)
+{
+       int index = ucontrol->value.enumerated.item[0];
+
+       if (index >= 10) {
+               pr_err("bad parameter for spdif format set\n");
+               return -1;
+       }
+       IEC958_mode_codec = index;
+       return 0;
+}
+
 #ifdef CONFIG_AMLOGIC_HDMITX
 /* call HDMITX API to enable/disable internal audio out */
 static int aml_get_hdmi_out_audio(struct snd_kcontrol *kcontrol,
@@ -252,8 +287,12 @@ static int aml_set_hdmi_out_channel_mask(struct snd_kcontrol *kcontrol,
 
 static const struct snd_kcontrol_new spdif_controls[] = {
        SOC_SINGLE_BOOL_EXT("Audio spdif mute",
-                           0, aml_audio_get_spdif_mute,
-                           aml_audio_set_spdif_mute),
+                               0, aml_audio_get_spdif_mute,
+                               aml_audio_set_spdif_mute),
+       SOC_ENUM_EXT("Audio spdif format",
+                               spdif_format_enum,
+                               spdif_format_get_enum,
+                               spdif_format_set_enum),
 #ifdef CONFIG_AMLOGIC_HDMITX
        SOC_SINGLE_BOOL_EXT("Audio hdmi-out mute",
                                0, aml_get_hdmi_out_audio,
index 460d735..6d0b4ce 100644 (file)
@@ -114,18 +114,6 @@ static u32 aml_hw_resample_table[7][5] = {
        {0x00800000, 0x0, 0x0, 0x0, 0x0},
 };
 
-static int DRC0_enable(int enable)
-{
-       if (enable == 1) {
-               aml_eqdrc_write(AED_DRC_THD0, aml_drc_tko_table[2]);
-               aml_eqdrc_write(AED_DRC_K0, aml_drc_tko_table[4]);
-       } else {
-               aml_eqdrc_write(AED_DRC_THD0, 0xbf000000);
-               aml_eqdrc_write(AED_DRC_K0, 0x40000);
-       }
-       return 0;
-}
-
 static const char *const audio_in_source_texts[] = {
        "LINEIN", "ATV", "HDMI", "SPDIFIN" };
 
@@ -432,7 +420,8 @@ static int set_internal_EQ_volume(
                        | (channel_1_volume << 8) /* channel 1 volume: 0dB*/
                        | (channel_2_volume << 0) /* channel 2 volume: 0dB*/
                        );
-       aml_eqdrc_write(AED_EQ_VOLUME_SLEW_CNT, 0x40);
+       /*fast attrack*/
+       aml_eqdrc_write(AED_EQ_VOLUME_SLEW_CNT, 0x5);
        aml_eqdrc_write(AED_MUTE, 0);
        return 0;
 }
@@ -1806,13 +1795,9 @@ int gxtvbb_set_audin_source(int audin_src)
        if (audin_src == 0) {
                /* select external codec ADC as I2S source */
                aml_audin_update_bits(AUDIN_SOURCE_SEL, 3, 0);
-
-               External_Mute(0);
        } else if (audin_src == 1) {
                /* select ATV output as I2S source */
                aml_audin_update_bits(AUDIN_SOURCE_SEL, 3, 1);
-
-               External_Mute(0);
        } else if (audin_src == 2) {
                /* select HDMI-rx as Audio In source */
                /* [14:12]cntl_hdmirx_chsts_sel: */
@@ -1831,8 +1816,6 @@ int gxtvbb_set_audin_source(int audin_src)
                                                0);
        }  else if (audin_src == 3) {
                aml_audin_update_bits(AUDIN_SOURCE_SEL, 0x3 << 4, 0);
-
-               External_Mute(0);
        }
 
        return 0;
@@ -1843,15 +1826,9 @@ int txl_set_audin_source(int audin_src)
        if (audin_src == 0) {
                /* select internal codec ADC in TXL as I2S source */
                aml_audin_update_bits(AUDIN_SOURCE_SEL, 3, 3);
-
-               DRC0_enable(1);
-               External_Mute(0);
        } else if (audin_src == 1) {
                /* select ATV output as I2S source */
                aml_audin_update_bits(AUDIN_SOURCE_SEL, 3, 1);
-
-               DRC0_enable(1);
-               External_Mute(0);
        } else if (audin_src == 2) {
                /* select HDMI-rx as Audio In source */
                /* [14:12]cntl_hdmirx_chsts_sel: */
@@ -1868,11 +1845,8 @@ int txl_set_audin_source(int audin_src)
                                                0xf << 8);
                aml_audin_update_bits(AUDIN_SOURCE_SEL, 0x7 << 12,
                                                0);
-               DRC0_enable(0);
        }  else if (audin_src == 3) {
                aml_audin_update_bits(AUDIN_SOURCE_SEL, 0x3 << 4, 0);
-               DRC0_enable(0);
-               External_Mute(0);
        }
 
        return 0;
@@ -1884,13 +1858,8 @@ int txlx_set_audin_source(int audin_src)
                /* select internal codec ADC in TXLX as HDMI-i2s*/
                aml_audin_update_bits(AUDIN_SOURCE_SEL, 3 << 16,
                                        3 << 16);
-
-               DRC0_enable(1);
-               External_Mute(0);
        } else if (audin_src == 1) {
                /* select ATV output as I2S source */
-               DRC0_enable(1);
-               External_Mute(0);
        } else if (audin_src == 2) {
                /* select HDMI-rx as Audio In source */
                /* [14:12]cntl_hdmirx_chsts_sel: */
@@ -1900,18 +1869,14 @@ int txlx_set_audin_source(int audin_src)
                /* 1=Select HDMIRX SPDIF output as AUDIN source */
                /* [1:0] i2sin_src_sel: */
                /* 2=Select HDMIRX I2S output as AUDIN source */
-               aml_audin_update_bits(AUDIN_SOURCE_SEL, 0x3, 2);
                aml_audin_update_bits(AUDIN_SOURCE_SEL, 0x3 << 4,
                                                1 << 4);
                aml_audin_update_bits(AUDIN_SOURCE_SEL, 0xf << 8,
                                                0xf << 8);
                aml_audin_update_bits(AUDIN_SOURCE_SEL, 0x7 << 12,
                                                0);
-               DRC0_enable(0);
        }  else if (audin_src == 3) {
                aml_audin_update_bits(AUDIN_SOURCE_SEL, 0x3 << 4, 0);
-               DRC0_enable(0);
-               External_Mute(0);
        }
 
        return 0;
@@ -1923,14 +1888,8 @@ int txhd_set_audin_source(int audin_src)
                /* select internal codec ADC in TXLX as HDMI-i2s*/
                aml_audin_update_bits(AUDIN_SOURCE_SEL, 3 << 16,
                                        3 << 16);
-
-               DRC0_enable(1);
-               External_Mute(0);
        } else if (audin_src == 1) {
                /* select ATV output as I2S source */
-
-               DRC0_enable(1);
-               External_Mute(0);
        } else if (audin_src == 2) {
                /* select HDMI-rx as Audio In source */
                /* [14:12]cntl_hdmirx_chsts_sel: */
@@ -1940,18 +1899,14 @@ int txhd_set_audin_source(int audin_src)
                /* 1=Select HDMIRX SPDIF output as AUDIN source */
                /* [1:0] i2sin_src_sel: */
                /* 2=Select HDMIRX I2S output as AUDIN source */
-
                aml_audin_update_bits(AUDIN_SOURCE_SEL, 0x3 << 4,
                                                1 << 4);
                aml_audin_update_bits(AUDIN_SOURCE_SEL, 0xf << 8,
                                                0xf << 8);
                aml_audin_update_bits(AUDIN_SOURCE_SEL, 0x7 << 12,
                                                0);
-               DRC0_enable(0);
        }  else if (audin_src == 3) {
                aml_audin_update_bits(AUDIN_SOURCE_SEL, 0x3 << 4, 0);
-               DRC0_enable(0);
-               External_Mute(0);
        }
 
        return 0;