Add slot width setting
[tas2770sw-android/tas2770sw-android.git] / tas2770-codec.c
index e47a024ef50660fad8b762f51813d625aaf6fcec..1dabd7b7b9d74796d7875abe7fa956c3f41b9090 100644 (file)
@@ -47,6 +47,8 @@
 
 #define TAS2770_MDELAY 0xFFFFFFFE
 
+static int tas2770_set_slot(struct snd_soc_codec *codec, int slot_width);
+
 static unsigned int tas2770_codec_read(struct snd_soc_codec *codec,
                unsigned int reg)
 {
@@ -106,9 +108,7 @@ static int tas2770_codec_suspend(struct snd_soc_codec *codec)
        mutex_lock(&pTAS2770->codec_lock);
 
        dev_dbg(pTAS2770->dev, "%s\n", __func__);
-       snd_soc_update_bits(codec, TAS2770_PowerControl,
-                       TAS2770_PowerControl_OperationalMode10_Mask,
-                       TAS2770_PowerControl_OperationalMode10_Shutdown);
+
        mutex_unlock(&pTAS2770->codec_lock);
        return ret;
 }
@@ -121,9 +121,6 @@ static int tas2770_codec_resume(struct snd_soc_codec *codec)
        mutex_lock(&pTAS2770->codec_lock);
 
        dev_dbg(pTAS2770->dev, "%s\n", __func__);
-       snd_soc_update_bits(codec, TAS2770_PowerControl,
-               TAS2770_PowerControl_OperationalMode10_Mask,
-               TAS2770_PowerControl_OperationalMode10_Active);
 
        mutex_unlock(&pTAS2770->codec_lock);
        return ret;
@@ -150,7 +147,7 @@ static int tas2770_dac_event(struct snd_soc_dapm_widget *w,
        case SND_SOC_DAPM_POST_PMU:
                snd_soc_update_bits(codec, TAS2770_PowerControl,
                        TAS2770_PowerControl_OperationalMode10_Mask,
-                       TAS2770_PowerControl_OperationalMode10_Active);
+                       TAS2770_PowerControl_OperationalMode10_Mute);
                break;
        case SND_SOC_DAPM_PRE_PMD:
                snd_soc_update_bits(codec, TAS2770_PowerControl,
@@ -222,6 +219,7 @@ 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 ret = 0;
+       int slot_width_tmp = 16;
 
        dev_dbg(pTAS2770->dev, "%s, format: %d\n", __func__,
                params_format(params));
@@ -230,45 +228,53 @@ static int tas2770_hw_params(struct snd_pcm_substream *substream,
        case SNDRV_PCM_FORMAT_S16_LE:
                snd_soc_update_bits(codec,
                        TAS2770_TDMConfigurationReg2,
-                       TAS2770_TDMConfigurationReg2_RXWLEN32_Mask |
-                       TAS2770_TDMConfigurationReg2_RXSLEN10_Mask,
-                       TAS2770_TDMConfigurationReg2_RXWLEN32_16Bits |
-                       TAS2770_TDMConfigurationReg2_RXSLEN10_16Bits);
-                       pTAS2770->ch_size = 16;
+                       TAS2770_TDMConfigurationReg2_RXWLEN32_Mask,
+                       TAS2770_TDMConfigurationReg2_RXWLEN32_16Bits);
+                       pTAS2770->mnCh_size = 16;
+                       if (pTAS2770->mnSlot_width == 0)
+                               slot_width_tmp = 16;
                break;
        case SNDRV_PCM_FORMAT_S24_LE:
                        snd_soc_update_bits(codec,
                        TAS2770_TDMConfigurationReg2,
-                       TAS2770_TDMConfigurationReg2_RXWLEN32_Mask |
-                       TAS2770_TDMConfigurationReg2_RXSLEN10_Mask,
-                       TAS2770_TDMConfigurationReg2_RXWLEN32_24Bits  |
-                       TAS2770_TDMConfigurationReg2_RXSLEN10_32Bits);
-                       pTAS2770->ch_size = 32;
+                       TAS2770_TDMConfigurationReg2_RXWLEN32_Mask,
+                       TAS2770_TDMConfigurationReg2_RXWLEN32_24Bits);
+                       pTAS2770->mnCh_size = 24;
+                       if (pTAS2770->mnSlot_width == 0)
+                               slot_width_tmp = 32;
                break;
        case SNDRV_PCM_FORMAT_S32_LE:
                        snd_soc_update_bits(codec,
                        TAS2770_TDMConfigurationReg2,
-                       TAS2770_TDMConfigurationReg2_RXWLEN32_Mask |
-                       TAS2770_TDMConfigurationReg2_RXSLEN10_Mask,
-                       TAS2770_TDMConfigurationReg2_RXWLEN32_32Bits |
-                       TAS2770_TDMConfigurationReg2_RXSLEN10_32Bits);
-                       pTAS2770->ch_size = 32;
+                       TAS2770_TDMConfigurationReg2_RXWLEN32_Mask,
+                       TAS2770_TDMConfigurationReg2_RXWLEN32_32Bits);
+                       pTAS2770->mnCh_size = 32;
+                       if (pTAS2770->mnSlot_width == 0)
+                               slot_width_tmp = 32;
                break;
 
+       default:
+               dev_dbg(pTAS2770->dev, "Not supported params format\n");
+               return -EINVAL;
        }
 
-       dev_dbg(pTAS2770->dev, "ch_size: %d\n", pTAS2770->ch_size);
+       /* If machine driver did not call set slot width */
+       if (pTAS2770->mnSlot_width == 0)
+               tas2770_set_slot(codec, slot_width_tmp);
+
+       dev_dbg(pTAS2770->dev, "mnCh_size: %d\n", pTAS2770->mnCh_size);
        snd_soc_update_bits(codec,
                TAS2770_TDMConfigurationReg5,
                TAS2770_TDMConfigurationReg5_VSNSTX_Mask |
                TAS2770_TDMConfigurationReg5_VSNSSLOT50_Mask,
                TAS2770_TDMConfigurationReg5_VSNSTX_Enable |
-               (pTAS2770->ch_size >> 3));
+               pTAS2770->mnVmon_slot_no);
        snd_soc_update_bits(codec,
                TAS2770_TDMConfigurationReg6,
                TAS2770_TDMConfigurationReg6_ISNSTX_Mask |
                TAS2770_TDMConfigurationReg6_ISNSSLOT50_Mask,
-               TAS2770_TDMConfigurationReg6_ISNSTX_Enable);
+               TAS2770_TDMConfigurationReg6_ISNSTX_Enable |
+               pTAS2770->mnImon_slot_no);
 
        dev_dbg(pTAS2770->dev, "%s, sample rate: %d\n", __func__,
                params_rate(params));
@@ -391,10 +397,69 @@ static int tas2770_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
        return ret;
 }
 
+static int tas2770_set_slot(struct snd_soc_codec *codec, int slot_width)
+{
+       int ret = 0;
+       struct tas2770_priv *pTAS2770 = snd_soc_codec_get_drvdata(codec);
+
+       switch (slot_width) {
+       case 16:
+       ret = snd_soc_update_bits(codec,
+               TAS2770_TDMConfigurationReg2,
+               TAS2770_TDMConfigurationReg2_RXSLEN10_Mask,
+               TAS2770_TDMConfigurationReg2_RXSLEN10_16Bits);
+       break;
+
+       case 24:
+       ret = snd_soc_update_bits(codec,
+               TAS2770_TDMConfigurationReg2,
+               TAS2770_TDMConfigurationReg2_RXSLEN10_Mask,
+               TAS2770_TDMConfigurationReg2_RXSLEN10_24Bits);
+       break;
+
+       case 32:
+       ret = snd_soc_update_bits(codec,
+               TAS2770_TDMConfigurationReg2,
+               TAS2770_TDMConfigurationReg2_RXSLEN10_Mask,
+               TAS2770_TDMConfigurationReg2_RXSLEN10_32Bits);
+       break;
+
+       case 0:
+       /* Do not change slot width */
+       break;
+
+       default:
+               dev_dbg(pTAS2770->dev, "slot width not supported");
+               ret = -EINVAL;
+       }
+
+       if (ret >= 0)
+               pTAS2770->mnSlot_width = slot_width;
+
+       return ret;
+}
+
+static int tas2770_set_dai_tdm_slot(struct snd_soc_dai *dai,
+               unsigned int tx_mask, unsigned int rx_mask,
+               int slots, int slot_width)
+{
+       int ret = 0;
+       struct snd_soc_codec *codec = dai->codec;
+       struct tas2770_priv *pTAS2770 = snd_soc_codec_get_drvdata(codec);
+
+       dev_dbg(pTAS2770->dev, "%s, tx_mask:%d, rx_mask:%d, slots:%d, slot_width:%d",
+                       __func__, tx_mask, rx_mask, slots, slot_width);
+
+       ret = tas2770_set_slot(codec, slot_width);
+
+       return ret;
+}
+
 static struct snd_soc_dai_ops tas2770_dai_ops = {
        .digital_mute = tas2770_mute,
        .hw_params  = tas2770_hw_params,
        .set_fmt    = tas2770_set_dai_fmt,
+       .set_tdm_slot = tas2770_set_dai_tdm_slot,
 };
 
 #define TAS2770_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\