Add support for multi format
authorTracy Yi <tracy-yi@ti.com>
Sat, 27 Jan 2018 15:27:02 +0000 (23:27 +0800)
committerTracy Yi <tracy-yi@ti.com>
Sun, 28 Jan 2018 00:04:18 +0000 (08:04 +0800)
Signed-off-by: Tracy Yi <tracy-yi@ti.com>
tas2770-codec.c
tas2770-regmap.c

index 9d75894a67f915645170ed87ef17b6edd6050c0f..5ba3efe1e58909a7e4642593a530c3724d29a49b 100644 (file)
@@ -48,6 +48,7 @@
 #define TAS2770_MDELAY 0xFFFFFFFE
 //#define KCONTROL_CODEC
 
+#define DAPM_TO_CODEC
 static unsigned int tas2770_codec_read(struct snd_soc_codec *codec,  unsigned int reg)
 {
        struct tas2770_priv *pTAS2770 = snd_soc_codec_get_drvdata(codec);
@@ -65,7 +66,6 @@ static unsigned int tas2770_codec_read(struct snd_soc_codec *codec,  unsigned in
                dev_dbg(pTAS2770->dev, "%s, reg: 0x%x, value: 0x%x\n", __func__, reg, value);
 
        mutex_unlock(&pTAS2770->dev_lock);
-
        if(nResult >= 0)
                return value;
        else
@@ -137,10 +137,13 @@ static const struct snd_kcontrol_new tas2770_asi_controls[] = {
 static int tas2770_dac_event(struct snd_soc_dapm_widget *w,
                        struct snd_kcontrol *kcontrol, int event) 
 {
-#if 1
+#ifdef DAPM_TO_CODEC
+       struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
+#else
        struct snd_soc_codec *codec = w->codec;
+#endif
 //     struct tas2770_priv *pTAS2770 = snd_soc_codec_get_drvdata(codec);
-
+       pr_err("%s",__func__);
        switch (event) {
        case SND_SOC_DAPM_POST_PMU:
                snd_soc_update_bits(codec, TAS2770_PowerControl,
@@ -154,7 +157,6 @@ static int tas2770_dac_event(struct snd_soc_dapm_widget *w,
                break;
        
        }
-#endif
        return 0;
 
 }
@@ -182,10 +184,11 @@ static const struct snd_soc_dapm_route tas2770_audio_map[] = {
 
 static int tas2770_mute(struct snd_soc_dai *dai, int mute)
 {
-#if 1
        struct snd_soc_codec *codec = dai->codec;
        struct tas2770_priv *pTAS2770 = snd_soc_codec_get_drvdata(codec);
 
+       dev_err(pTAS2770->dev, "%s mute %d",__func__, mute); 
+
        mutex_lock(&pTAS2770->codec_lock);
        if(mute) {
                snd_soc_update_bits(codec, TAS2770_PowerControl,
@@ -197,7 +200,6 @@ static int tas2770_mute(struct snd_soc_dai *dai, int mute)
                        TAS2770_PowerControl_OperationalMode10_Active); 
        }
        mutex_unlock(&pTAS2770->codec_lock);
-#endif
        return 0;
 }
 
@@ -209,9 +211,8 @@ static int tas2770_hw_params(struct snd_pcm_substream *substream,
 {
        struct snd_soc_codec *codec = dai->codec;
        struct tas2770_priv *pTAS2770 = snd_soc_codec_get_drvdata(codec);
-       int blr_clk_ratio;
        int ret = 0;
-
+       dev_err(pTAS2770->dev, "%s",__func__);
        dev_dbg(pTAS2770->dev, "%s, format: %d\n", __func__, params_format(params));
 
        switch(params_format(params)) {
@@ -224,7 +225,7 @@ static int tas2770_hw_params(struct snd_pcm_substream *substream,
                        TAS2770_TDMConfigurationReg2_RXWLEN32_16Bits );
                        pTAS2770->ch_size = 16;
                break;
-       case SNDRV_PCM_FMTBIT_S24_LE:
+       case SNDRV_PCM_FORMAT_S24_LE:
                        snd_soc_update_bits(codec,
                        TAS2770_TDMConfigurationReg2,
                        TAS2770_TDMConfigurationReg2_RXWLEN32_Mask |
@@ -233,7 +234,7 @@ static int tas2770_hw_params(struct snd_pcm_substream *substream,
                        TAS2770_TDMConfigurationReg2_RXWLEN32_24Bits );
                        pTAS2770->ch_size = 24;
                break;
-       case SNDRV_PCM_FMTBIT_S32_LE:
+       case SNDRV_PCM_FORMAT_S32_LE:
                        snd_soc_update_bits(codec,
                        TAS2770_TDMConfigurationReg2,
                        TAS2770_TDMConfigurationReg2_RXWLEN32_Mask |
@@ -245,81 +246,6 @@ static int tas2770_hw_params(struct snd_pcm_substream *substream,
 
        }
 
-       blr_clk_ratio = params_channels(params) * pTAS2770->ch_size;
-       dev_dbg(pTAS2770->dev, "blr_clk_ratio: %d\n", blr_clk_ratio);
-
-       switch(blr_clk_ratio) {
-       case 16: 
-                       snd_soc_update_bits(codec,
-                               TAS2770_ClockConfiguration,
-                               TAS2770_ClockConfiguration_SBCLKtoFS52_Mask,
-                               TAS2770_ClockConfiguration_SBCLKtoFS52_16);
-                       break;
-       case 24:
-                       snd_soc_update_bits(codec,
-                               TAS2770_ClockConfiguration,
-                               TAS2770_ClockConfiguration_SBCLKtoFS52_Mask,
-                               TAS2770_ClockConfiguration_SBCLKtoFS52_24);
-                       break;
-       case 32:
-                       snd_soc_update_bits(codec,
-                               TAS2770_ClockConfiguration,
-                               TAS2770_ClockConfiguration_SBCLKtoFS52_Mask,
-                               TAS2770_ClockConfiguration_SBCLKtoFS52_32);
-                       break;
-       case 48: 
-                       snd_soc_update_bits(codec,
-                               TAS2770_ClockConfiguration,
-                               TAS2770_ClockConfiguration_SBCLKtoFS52_Mask,
-                               TAS2770_ClockConfiguration_SBCLKtoFS52_48);
-                       break;                  
-       case 64:                        
-                       snd_soc_update_bits(codec,
-                               TAS2770_ClockConfiguration,
-                               TAS2770_ClockConfiguration_SBCLKtoFS52_Mask,
-                               TAS2770_ClockConfiguration_SBCLKtoFS52_64);
-                       break;
-       case 96:                        
-                       snd_soc_update_bits(codec,
-                               TAS2770_ClockConfiguration,
-                               TAS2770_ClockConfiguration_SBCLKtoFS52_Mask,
-                               TAS2770_ClockConfiguration_SBCLKtoFS52_96);
-                       break;
-       case 128:                       
-                       snd_soc_update_bits(codec,
-                               TAS2770_ClockConfiguration,
-                               TAS2770_ClockConfiguration_SBCLKtoFS52_Mask,
-                               TAS2770_ClockConfiguration_SBCLKtoFS52_128);
-                       break;                  
-       case 192:                       
-                       snd_soc_update_bits(codec,
-                               TAS2770_ClockConfiguration,
-                               TAS2770_ClockConfiguration_SBCLKtoFS52_Mask,
-                               TAS2770_ClockConfiguration_SBCLKtoFS52_192);
-                       break;
-       case 256:                       
-                       snd_soc_update_bits(codec,
-                               TAS2770_ClockConfiguration,
-                               TAS2770_ClockConfiguration_SBCLKtoFS52_Mask,
-                               TAS2770_ClockConfiguration_SBCLKtoFS52_256);
-                       break;
-       case 384:                       
-                       snd_soc_update_bits(codec,
-                               TAS2770_ClockConfiguration,
-                               TAS2770_ClockConfiguration_SBCLKtoFS52_Mask,
-                               TAS2770_ClockConfiguration_SBCLKtoFS52_384);
-                       break;                  
-       case 512:                       
-                       snd_soc_update_bits(codec,
-                               TAS2770_ClockConfiguration,
-                               TAS2770_ClockConfiguration_SBCLKtoFS52_Mask,
-                               TAS2770_ClockConfiguration_SBCLKtoFS52_512);
-                       break;
-       default:
-               dev_err(pTAS2770->dev, "Invalid BCLK to FSYNC ratio\n");
-               ret = -EINVAL;
-       }
-
        dev_dbg(pTAS2770->dev, "%s, sample rate: %d\n", __func__, params_rate(params));
        switch(params_rate(params))
        {
@@ -544,7 +470,7 @@ int tas2770_register_codec(struct tas2770_priv *pTAS2770)
        nResult = snd_soc_register_codec(pTAS2770->dev,
                &soc_codec_driver_tas2770,
                tas2770_dai_driver, ARRAY_SIZE(tas2770_dai_driver));
-
+        dev_info(pTAS2770->dev, "%s, enter result %d\n", __func__,nResult);
        return nResult;
 }
 
index bb4c5f33511f4929dbf8925f406e6397c9d74ae7..f25d7122e2e8128c1cd427672cd0a431251f9238 100644 (file)
@@ -51,7 +51,7 @@ static const struct reg_default tas2770_reg_defaults[] = {
        { TAS2770_InterruptMaskReg1, 0xb1 },
        { TAS2770_InterruptConfiguration, 0x05 },
        { TAS2770_MiscIRQ, 0x81 },
-       { TAS2770_ClockConfiguration, 0x0d },
+       { TAS2770_ClockConfiguration, 0x0c },
 
 };