asoc: tegra: cs42l73: Support voice call
ScottPeterson [Fri, 28 Sep 2012 21:36:50 +0000 (14:36 -0700)]
Add support for voice calls on pluto platform.

Bug 1056501

Signed-off-by: ScottPeterson <speterson@nvidia.com>
Reviewed-on: http://git-master/r/139823
(cherry picked from commit 9a18bc54326a603b46bd15f500a08b6149f6b70c)

Change-Id: I100497338b9cdb7ec66627151e4c7e7840f059fa
Signed-off-by: Bharat Nihalani <bnihalani@nvidia.com>
Signed-off-by: Rahul Mittal <rmittal@nvidia.com>
Reviewed-on: http://git-master/r/146965
Reviewed-by: Simone Willett <swillett@nvidia.com>
Tested-by: Simone Willett <swillett@nvidia.com>

arch/arm/mach-tegra/board-pluto.c
sound/soc/tegra/tegra30_i2s.c
sound/soc/tegra/tegra_cs42l73.c

index 18baccb..b04a220 100644 (file)
@@ -146,6 +146,7 @@ static __initdata struct tegra_clk_init_table pluto_clk_init_table[] = {
        { "pwm",        "pll_p",        3187500,        false},
        { "blink",      "clk_32k",      32768,          true},
        { "i2s1",       "pll_a_out0",   0,              false},
+       { "i2s2",       "pll_a_out0",   0,              false},
        { "i2s3",       "pll_a_out0",   0,              false},
        { "i2s4",       "pll_a_out0",   0,              false},
        { "spdif_out",  "pll_a_out0",   0,              false},
@@ -154,7 +155,9 @@ static __initdata struct tegra_clk_init_table pluto_clk_init_table[] = {
        { "dam1",       "clk_m",        12000000,       false},
        { "dam2",       "clk_m",        12000000,       false},
        { "audio1",     "i2s1_sync",    0,              false},
+       { "audio2",     "i2s2_sync",    0,              false},
        { "audio3",     "i2s3_sync",    0,              false},
+       { "audio4",     "i2s4_sync",    0,              false},
        { "vi_sensor",  "pll_p",        150000000,      false},
        { "cilab",      "pll_p",        150000000,      false},
        { "cilcd",      "pll_p",        150000000,      false},
@@ -406,6 +409,22 @@ static struct tegra_asoc_platform_data pluto_audio_pdata = {
                .audio_port_id  = 1,
                .is_i2s_master  = 0,
                .i2s_mode       = TEGRA_DAIFMT_I2S,
+               .sample_size    = 16,
+               .channels       = 2,
+       },
+       .i2s_param[BASEBAND]    = {
+               .audio_port_id  = 2,
+               .is_i2s_master  = 1,
+               .i2s_mode       = TEGRA_DAIFMT_I2S,
+               .sample_size    = 16,
+               .rate           = 16000,
+               .channels       = 2,
+       },
+       .i2s_param[BT_SCO]      = {
+               .audio_port_id  = 3,
+               .is_i2s_master  = 1,
+               .i2s_mode       = TEGRA_DAIFMT_DSP_A,
+               .sample_size    = 16,
        },
 };
 
@@ -441,9 +460,15 @@ static struct platform_device *pluto_devices[] __initdata = {
        &tegra_dam_device0,
        &tegra_dam_device1,
        &tegra_dam_device2,
+       &tegra_i2s_device0,
        &tegra_i2s_device1,
+       &tegra_i2s_device2,
        &tegra_i2s_device3,
        &tegra_i2s_device4,
+       &tegra_spdif_device,
+       &spdif_dit_device,
+       &bluetooth_dit_device,
+       &baseband_dit_device,
        &pluto_audio_device,
        &tegra_hda_device,
 #if defined(CONFIG_CRYPTO_DEV_TEGRA_AES)
index 749e8de..e4defa2 100644 (file)
@@ -137,11 +137,11 @@ static const struct file_operations tegra30_i2s_debug_fops = {
        .release = single_release,
 };
 
-static void tegra30_i2s_debug_add(struct tegra30_i2s *i2s)
+static void tegra30_i2s_debug_add(struct tegra30_i2s *i2s, int id)
 {
        char name[] = DRV_NAME ".0";
 
-       snprintf(name, sizeof(name), DRV_NAME);
+       snprintf(name, sizeof(name), DRV_NAME".%1d", id);
        i2s->debug = debugfs_create_file(name, S_IRUGO, snd_soc_debugfs_root,
                                                i2s, &tegra30_i2s_debug_fops);
 }
@@ -152,7 +152,7 @@ static void tegra30_i2s_debug_remove(struct tegra30_i2s *i2s)
                debugfs_remove(i2s->debug);
 }
 #else
-static inline void tegra30_i2s_debug_add(struct tegra30_i2s *i2s)
+static inline void tegra30_i2s_debug_add(struct tegra30_i2s *i2s, int id)
 {
 }
 
@@ -1192,6 +1192,7 @@ int tegra30_make_voice_call_connections(struct codec_config *codec_info,
        codec_i2s->reg_ctrl |= TEGRA30_I2S_CTRL_XFER_EN_RX;
        tegra30_i2s_write(codec_i2s, TEGRA30_I2S_CTRL,
                codec_i2s->reg_ctrl);
+
        bb_i2s->reg_ctrl |= TEGRA30_I2S_CTRL_XFER_EN_TX;
        bb_i2s->reg_ctrl |= TEGRA30_I2S_CTRL_XFER_EN_RX;
        tegra30_i2s_write(bb_i2s, TEGRA30_I2S_CTRL,
@@ -1364,7 +1365,7 @@ static __devinit int tegra30_i2s_platform_probe(struct platform_device *pdev)
                goto err_unmap;
        }
 
-       tegra30_i2s_debug_add(i2s);
+       tegra30_i2s_debug_add(i2s, pdev->id);
 
        return 0;
 
index 83153ff..17442a8 100644 (file)
 
 #include "tegra_pcm.h"
 #include "tegra_asoc_utils.h"
-
+#ifndef CONFIG_ARCH_TEGRA_2x_SOC
+#include "tegra30_ahub.h"
+#include "tegra30_i2s.h"
+#include "tegra30_dam.h"
+#endif
 #define DRV_NAME "tegra-snd-cs42l73"
 
 #define GPIO_SPKR_EN    BIT(0)
 #define GPIO_EXT_MIC_EN BIT(3)
 #define GPIO_HP_DET     BIT(4)
 
+#define DAI_LINK_HIFI          0
+#define DAI_LINK_SPDIF         1
+#define DAI_LINK_BTSCO         2
+#define DAI_LINK_VOICE_CALL    3
+#define DAI_LINK_BT_VOICE_CALL 4
+#define NUM_DAI_LINKS  5
+
+const char *tegra_cs42l73_i2s_dai_name[TEGRA30_NR_I2S_IFC] = {
+       "tegra30-i2s.0",
+       "tegra30-i2s.1",
+       "tegra30-i2s.2",
+       "tegra30-i2s.3",
+       "tegra30-i2s.4",
+};
+
+extern int g_is_call_mode;
+
+
 struct tegra_cs42l73 {
        struct tegra_asoc_utils_data util_data;
        struct tegra_asoc_platform_data *pdata;
@@ -63,16 +85,122 @@ struct tegra_cs42l73 {
        bool init_done;
        int is_call_mode;
        int is_device_bt;
+#ifndef CONFIG_ARCH_TEGRA_2x_SOC
+       struct codec_config codec_info[NUM_I2S_DEVICES];
+#endif
        struct regulator *dmic_reg;
        struct regulator *dmic_1v8_reg;
+       struct regulator *hmic_reg;
        enum snd_soc_bias_level bias_level;
        struct snd_soc_card *pcard;
 #ifdef CONFIG_SWITCH
        int jack_status;
 #endif
-       int clock_enabled;
+       volatile int clock_enabled;
+};
+
+static int tegra_call_mode_info(struct snd_kcontrol *kcontrol,
+                       struct snd_ctl_elem_info *uinfo)
+{
+       uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
+       uinfo->count = 1;
+       uinfo->value.integer.min = 0;
+       uinfo->value.integer.max = 1;
+       return 0;
+}
+
+static int tegra_call_mode_get(struct snd_kcontrol *kcontrol,
+               struct snd_ctl_elem_value *ucontrol)
+{
+       struct tegra_cs42l73 *machine = snd_kcontrol_chip(kcontrol);
+
+       ucontrol->value.integer.value[0] = machine->is_call_mode;
+
+       return 0;
+}
+
+static int tegra_call_mode_put(struct snd_kcontrol *kcontrol,
+               struct snd_ctl_elem_value *ucontrol)
+{
+       struct tegra_cs42l73 *machine = snd_kcontrol_chip(kcontrol);
+       int is_call_mode_new = ucontrol->value.integer.value[0];
+       int codec_index;
+       unsigned int i;
+
+       if (machine->is_call_mode == is_call_mode_new)
+               return 0;
+
+       if (machine->is_device_bt)
+               codec_index = BT_SCO;
+       else
+               codec_index = HIFI_CODEC;
+
+       if (is_call_mode_new) {
+               if (machine->codec_info[codec_index].rate == 0 ||
+                       machine->codec_info[codec_index].channels == 0)
+                               return -EINVAL;
+
+               for (i = 0; i < machine->pcard->num_links; i++)
+                       machine->pcard->dai_link[i].ignore_suspend = 1;
+
+               tegra30_make_voice_call_connections(
+                       &machine->codec_info[codec_index],
+                       &machine->codec_info[BASEBAND]);
+       } else {
+               tegra30_break_voice_call_connections(
+                       &machine->codec_info[codec_index],
+                       &machine->codec_info[BASEBAND]);
+
+               for (i = 0; i < machine->pcard->num_links; i++)
+                       machine->pcard->dai_link[i].ignore_suspend = 0;
+       }
+
+       machine->is_call_mode = is_call_mode_new;
+       g_is_call_mode = machine->is_call_mode;
+
+       return 1;
+}
+
+struct snd_kcontrol_new tegra_call_mode_control = {
+       .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
+       .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+       .name = "Call Mode Switch",
+       .private_value = 0xffff,
+       .info = tegra_call_mode_info,
+       .get = tegra_call_mode_get,
+       .put = tegra_call_mode_put
 };
 
+#ifndef CONFIG_ARCH_TEGRA_2x_SOC
+static int tegra_cs42l73_set_dam_cif(int dam_ifc, int srate,
+                       int channels, int bit_size, int src_on, int src_srate,
+                       int src_channels, int src_bit_size)
+{
+       tegra30_dam_set_gain(dam_ifc, TEGRA30_DAM_CHIN1, 0x1000);
+       tegra30_dam_set_samplerate(dam_ifc, TEGRA30_DAM_CHOUT,
+                               srate);
+       tegra30_dam_set_samplerate(dam_ifc, TEGRA30_DAM_CHIN1,
+                               srate);
+       tegra30_dam_set_acif(dam_ifc, TEGRA30_DAM_CHIN1,
+               channels, bit_size, channels,
+                               bit_size);
+       tegra30_dam_set_acif(dam_ifc, TEGRA30_DAM_CHOUT,
+               channels, bit_size, channels,
+                               bit_size);
+
+       tegra30_dam_set_gain(dam_ifc, TEGRA30_DAM_CHIN0_SRC, 0x1000);
+       if (src_on) {
+               tegra30_dam_set_samplerate(dam_ifc, TEGRA30_DAM_CHIN0_SRC,
+                       src_srate);
+               tegra30_dam_set_acif(dam_ifc, TEGRA30_DAM_CHIN0_SRC,
+                       src_channels, src_bit_size, 1, 32);
+       }
+
+       return 0;
+}
+#endif
+
+
 static int tegra_cs42l73_hw_params(struct snd_pcm_substream *substream,
                                        struct snd_pcm_hw_params *params)
 {
@@ -83,9 +211,22 @@ static int tegra_cs42l73_hw_params(struct snd_pcm_substream *substream,
        struct snd_soc_card *card = codec->card;
        struct tegra_cs42l73 *machine = snd_soc_card_get_drvdata(card);
        struct tegra_asoc_platform_data *pdata = machine->pdata;
-       int srate, mclk, i2s_daifmt;
-       int err, rate;
+#ifndef CONFIG_ARCH_TEGRA_2x_SOC
+       struct tegra30_i2s *i2s = snd_soc_dai_get_drvdata(cpu_dai);
+#endif
+       int srate, mclk, sample_size, i2s_daifmt, i2s_master;
+       int err;
+       int rate;
 
+       i2s_master = pdata->i2s_param[HIFI_CODEC].is_i2s_master;
+
+       switch (params_format(params)) {
+       case SNDRV_PCM_FORMAT_S16_LE:
+               sample_size = 16;
+               break;
+       default:
+               return -EINVAL;
+       }
        srate = params_rate(params);
 
        switch (srate) {
@@ -105,8 +246,8 @@ static int tegra_cs42l73_hw_params(struct snd_pcm_substream *substream,
        }
 
        i2s_daifmt = SND_SOC_DAIFMT_NB_NF;
-       i2s_daifmt |= pdata->i2s_param[HIFI_CODEC].is_i2s_master ?
-                       SND_SOC_DAIFMT_CBS_CFS : SND_SOC_DAIFMT_CBM_CFM;
+       i2s_daifmt |= i2s_master ? SND_SOC_DAIFMT_CBS_CFS :
+                               SND_SOC_DAIFMT_CBM_CFM;
 
        switch (pdata->i2s_param[HIFI_CODEC].i2s_mode) {
        case TEGRA_DAIFMT_I2S:
@@ -165,6 +306,153 @@ static int tegra_cs42l73_hw_params(struct snd_pcm_substream *substream,
                return err;
        }
 
+#ifndef CONFIG_ARCH_TEGRA_2x_SOC
+       if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
+               tegra_cs42l73_set_dam_cif(i2s->dam_ifc, srate,
+                       params_channels(params), sample_size, 0, 0, 0, 0);
+#endif
+
+       return 0;
+}
+
+#if 1
+static int tegra_spdif_hw_params(struct snd_pcm_substream *substream,
+                                       struct snd_pcm_hw_params *params)
+{
+       struct snd_soc_pcm_runtime *rtd = substream->private_data;
+       struct snd_soc_card *card = rtd->card;
+       struct tegra_cs42l73 *machine = snd_soc_card_get_drvdata(card);
+       int srate, mclk, min_mclk;
+       int err;
+
+       srate = params_rate(params);
+       switch (srate) {
+       case 11025:
+       case 22050:
+       case 44100:
+       case 88200:
+               mclk = 11289600;
+               break;
+       case 8000:
+       case 16000:
+       case 32000:
+       case 48000:
+       case 64000:
+       case 96000:
+               mclk = 12288000;
+               break;
+       default:
+               return -EINVAL;
+       }
+       min_mclk = 128 * srate;
+
+       err = tegra_asoc_utils_set_rate(&machine->util_data, srate, mclk);
+       if (err < 0) {
+               if (!(machine->util_data.set_mclk % min_mclk))
+                       mclk = machine->util_data.set_mclk;
+               else {
+                       dev_err(card->dev, "Can't configure clocks\n");
+                       return err;
+               }
+       }
+
+       tegra_asoc_utils_lock_clk_rate(&machine->util_data, 1);
+
+       return 0;
+}
+#endif
+
+static int tegra_bt_hw_params(struct snd_pcm_substream *substream,
+               struct snd_pcm_hw_params *params)
+{
+       struct snd_soc_pcm_runtime *rtd = substream->private_data;
+#ifndef CONFIG_ARCH_TEGRA_2x_SOC
+       struct tegra30_i2s *i2s = snd_soc_dai_get_drvdata(rtd->cpu_dai);
+#endif
+       struct snd_soc_card *card = rtd->card;
+       struct tegra_cs42l73 *machine = snd_soc_card_get_drvdata(card);
+       struct tegra_asoc_platform_data *pdata = machine->pdata;
+       int err, srate, mclk, min_mclk, sample_size;
+       int i2s_daifmt;
+
+       switch (params_format(params)) {
+       case SNDRV_PCM_FORMAT_S16_LE:
+               sample_size = 16;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       srate = params_rate(params);
+       switch (srate) {
+       case 11025:
+       case 22050:
+       case 44100:
+       case 88200:
+               mclk = 11289600;
+               break;
+       case 8000:
+       case 16000:
+       case 32000:
+       case 48000:
+       case 64000:
+       case 96000:
+               mclk = 12288000;
+               break;
+       default:
+               return -EINVAL;
+       }
+       min_mclk = 64 * srate;
+
+       err = tegra_asoc_utils_set_rate(&machine->util_data, srate, mclk);
+       if (err < 0) {
+               if (!(machine->util_data.set_mclk % min_mclk))
+                       mclk = machine->util_data.set_mclk;
+               else {
+                       dev_err(card->dev, "Can't configure clocks\n");
+                       return err;
+               }
+       }
+
+       tegra_asoc_utils_lock_clk_rate(&machine->util_data, 1);
+
+       i2s_daifmt = SND_SOC_DAIFMT_NB_NF;
+       i2s_daifmt |= pdata->i2s_param[BT_SCO].is_i2s_master ?
+                       SND_SOC_DAIFMT_CBS_CFS : SND_SOC_DAIFMT_CBM_CFM;
+
+       switch (pdata->i2s_param[BT_SCO].i2s_mode) {
+       case TEGRA_DAIFMT_I2S:
+               i2s_daifmt |= SND_SOC_DAIFMT_I2S;
+               break;
+       case TEGRA_DAIFMT_DSP_A:
+               i2s_daifmt |= SND_SOC_DAIFMT_DSP_A;
+               break;
+       case TEGRA_DAIFMT_DSP_B:
+               i2s_daifmt |= SND_SOC_DAIFMT_DSP_B;
+               break;
+       case TEGRA_DAIFMT_LEFT_J:
+               i2s_daifmt |= SND_SOC_DAIFMT_LEFT_J;
+               break;
+       case TEGRA_DAIFMT_RIGHT_J:
+               i2s_daifmt |= SND_SOC_DAIFMT_RIGHT_J;
+               break;
+       default:
+               dev_err(card->dev, "Can't configure i2s format\n");
+               return -EINVAL;
+       }
+
+       err = snd_soc_dai_set_fmt(rtd->cpu_dai, i2s_daifmt);
+       if (err < 0) {
+               dev_err(rtd->codec->card->dev, "cpu_dai fmt not set\n");
+               return err;
+       }
+
+#ifndef CONFIG_ARCH_TEGRA_2x_SOC
+       if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
+               tegra_cs42l73_set_dam_cif(i2s->dam_ifc, params_rate(params),
+                       params_channels(params), sample_size, 0, 0, 0, 0);
+#endif
+
        return 0;
 }
 
@@ -178,9 +466,363 @@ static int tegra_hw_free(struct snd_pcm_substream *substream)
        return 0;
 }
 
+#ifndef CONFIG_ARCH_TEGRA_2x_SOC
+static int tegra_cs42l73_startup(struct snd_pcm_substream *substream)
+{
+       struct snd_soc_pcm_runtime *rtd = substream->private_data;
+       struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
+       struct tegra30_i2s *i2s = snd_soc_dai_get_drvdata(cpu_dai);
+       struct tegra_cs42l73 *machine = snd_soc_card_get_drvdata(rtd->card);
+       struct codec_config *codec_info;
+       struct codec_config *bb_info;
+       int codec_index;
+
+       if (!i2s->is_dam_used)
+               return 0;
+
+       if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
+               /*dam configuration*/
+               if (!i2s->dam_ch_refcount)
+                       i2s->dam_ifc = tegra30_dam_allocate_controller();
+
+               tegra30_dam_allocate_channel(i2s->dam_ifc, TEGRA30_DAM_CHIN1);
+               i2s->dam_ch_refcount++;
+               tegra30_dam_enable_clock(i2s->dam_ifc);
+
+               tegra30_ahub_set_rx_cif_source(TEGRA30_AHUB_RXCIF_DAM0_RX1 +
+                               (i2s->dam_ifc*2), i2s->txcif);
+
+               /*
+               *make the dam tx to i2s rx connection if this is the only client
+               *using i2s for playback
+               */
+               if (i2s->playback_ref_count == 1)
+                       tegra30_ahub_set_rx_cif_source(
+                               TEGRA30_AHUB_RXCIF_I2S0_RX0 + i2s->id,
+                               TEGRA30_AHUB_TXCIF_DAM0_TX0 + i2s->dam_ifc);
+
+               /* enable the dam*/
+               tegra30_dam_enable(i2s->dam_ifc, TEGRA30_DAM_ENABLE,
+                               TEGRA30_DAM_CHIN1);
+       } else {
+
+               i2s->is_call_mode_rec = machine->is_call_mode;
+
+               if (!i2s->is_call_mode_rec)
+                       return 0;
+
+               if (machine->is_device_bt)
+                       codec_index = BT_SCO;
+               else
+                       codec_index = HIFI_CODEC;
+
+               codec_info = &machine->codec_info[codec_index];
+               bb_info = &machine->codec_info[BASEBAND];
+
+               /* allocate a dam for voice call recording */
+
+               i2s->call_record_dam_ifc = tegra30_dam_allocate_controller();
+               tegra30_dam_allocate_channel(i2s->call_record_dam_ifc,
+                       TEGRA30_DAM_CHIN0_SRC);
+               tegra30_dam_allocate_channel(i2s->call_record_dam_ifc,
+                       TEGRA30_DAM_CHIN1);
+               tegra30_dam_enable_clock(i2s->call_record_dam_ifc);
+
+               /* configure the dam */
+               tegra_cs42l73_set_dam_cif(i2s->call_record_dam_ifc,
+                       codec_info->rate, codec_info->channels,
+                       codec_info->bitsize, 1, bb_info->rate,
+                       bb_info->channels, bb_info->bitsize);
+
+               /* setup the connections for voice call record */
+
+               tegra30_ahub_unset_rx_cif_source(i2s->rxcif);
+               tegra30_ahub_set_rx_cif_source(TEGRA30_AHUB_RXCIF_DAM0_RX0 +
+                       (i2s->call_record_dam_ifc*2),
+                       TEGRA30_AHUB_TXCIF_I2S0_TX0 + bb_info->i2s_id);
+               tegra30_ahub_set_rx_cif_source(TEGRA30_AHUB_RXCIF_DAM0_RX1 +
+                       (i2s->call_record_dam_ifc*2),
+                       TEGRA30_AHUB_TXCIF_I2S0_TX0 + codec_info->i2s_id);
+               tegra30_ahub_set_rx_cif_source(i2s->rxcif,
+                       TEGRA30_AHUB_TXCIF_DAM0_TX0 + i2s->call_record_dam_ifc);
+
+               /* enable the dam*/
+
+               tegra30_dam_enable(i2s->call_record_dam_ifc, TEGRA30_DAM_ENABLE,
+                               TEGRA30_DAM_CHIN1);
+               tegra30_dam_enable(i2s->call_record_dam_ifc, TEGRA30_DAM_ENABLE,
+                               TEGRA30_DAM_CHIN0_SRC);
+       }
+
+       return 0;
+}
+
+static void tegra_cs42l73_shutdown(struct snd_pcm_substream *substream)
+{
+       struct snd_soc_pcm_runtime *rtd = substream->private_data;
+       struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
+       struct tegra30_i2s *i2s = snd_soc_dai_get_drvdata(cpu_dai);
+
+       if (!i2s->is_dam_used)
+               return;
+
+       if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
+               /* disable the dam*/
+               tegra30_dam_enable(i2s->dam_ifc, TEGRA30_DAM_DISABLE,
+                               TEGRA30_DAM_CHIN1);
+
+               /* disconnect the ahub connections*/
+               tegra30_ahub_unset_rx_cif_source(TEGRA30_AHUB_RXCIF_DAM0_RX1 +
+                                       (i2s->dam_ifc*2));
+
+               /* disable the dam and free the controller */
+               tegra30_dam_disable_clock(i2s->dam_ifc);
+               tegra30_dam_free_channel(i2s->dam_ifc, TEGRA30_DAM_CHIN1);
+               i2s->dam_ch_refcount--;
+               if (!i2s->dam_ch_refcount)
+                       tegra30_dam_free_controller(i2s->dam_ifc);
+        } else {
+
+               if (!i2s->is_call_mode_rec)
+                       return;
+
+               i2s->is_call_mode_rec = 0;
+
+               /* disable the dam*/
+               tegra30_dam_enable(i2s->call_record_dam_ifc,
+                       TEGRA30_DAM_DISABLE, TEGRA30_DAM_CHIN1);
+               tegra30_dam_enable(i2s->call_record_dam_ifc,
+                       TEGRA30_DAM_DISABLE, TEGRA30_DAM_CHIN0_SRC);
+
+               /* disconnect the ahub connections*/
+               tegra30_ahub_unset_rx_cif_source(i2s->rxcif);
+               tegra30_ahub_unset_rx_cif_source(TEGRA30_AHUB_RXCIF_DAM0_RX0 +
+                       (i2s->call_record_dam_ifc*2));
+               tegra30_ahub_unset_rx_cif_source(TEGRA30_AHUB_RXCIF_DAM0_RX1 +
+                       (i2s->call_record_dam_ifc*2));
+
+               /* free the dam channels and dam controller */
+               tegra30_dam_disable_clock(i2s->call_record_dam_ifc);
+               tegra30_dam_free_channel(i2s->call_record_dam_ifc,
+                       TEGRA30_DAM_CHIN1);
+               tegra30_dam_free_channel(i2s->call_record_dam_ifc,
+                       TEGRA30_DAM_CHIN0_SRC);
+               tegra30_dam_free_controller(i2s->call_record_dam_ifc);
+        }
+
+       return;
+}
+#endif
+
+static int tegra_voice_call_hw_params(struct snd_pcm_substream *substream,
+                       struct snd_pcm_hw_params *params)
+{
+       struct snd_soc_pcm_runtime *rtd = substream->private_data;
+       struct snd_soc_dai *codec_dai = rtd->codec_dai;
+       struct snd_soc_codec *codec = rtd->codec;
+       struct snd_soc_card *card = codec->card;
+       struct tegra_cs42l73 *machine = snd_soc_card_get_drvdata(card);
+       struct tegra_asoc_platform_data *pdata = machine->pdata;
+       int srate, mclk, i2s_daifmt;
+       int err, rate;
+
+       srate = params_rate(params);
+       switch (srate) {
+       case 8000:
+       case 16000:
+       case 24000:
+       case 32000:
+       case 48000:
+       case 64000:
+       case 96000:
+               mclk = 12288000;
+               break;
+       case 11025:
+       case 22050:
+       case 44100:
+       case 88200:
+               mclk = 11289600;
+               break;
+       default:
+               return -EINVAL;
+               break;
+       }
+
+       i2s_daifmt = SND_SOC_DAIFMT_NB_NF;
+       i2s_daifmt |= pdata->i2s_param[HIFI_CODEC].is_i2s_master ?
+                       SND_SOC_DAIFMT_CBS_CFS : SND_SOC_DAIFMT_CBM_CFM;
+
+       switch (pdata->i2s_param[HIFI_CODEC].i2s_mode) {
+       case TEGRA_DAIFMT_I2S:
+               i2s_daifmt |= SND_SOC_DAIFMT_I2S;
+               break;
+       case TEGRA_DAIFMT_DSP_A:
+               i2s_daifmt |= SND_SOC_DAIFMT_DSP_A;
+               break;
+       case TEGRA_DAIFMT_DSP_B:
+               i2s_daifmt |= SND_SOC_DAIFMT_DSP_B;
+               break;
+       case TEGRA_DAIFMT_LEFT_J:
+               i2s_daifmt |= SND_SOC_DAIFMT_LEFT_J;
+               break;
+       case TEGRA_DAIFMT_RIGHT_J:
+               i2s_daifmt |= SND_SOC_DAIFMT_RIGHT_J;
+               break;
+       default:
+               dev_err(card->dev, "Can't configure i2s format\n");
+               return -EINVAL;
+       }
+
+       err = tegra_asoc_utils_set_rate(&machine->util_data, srate, mclk);
+       if (err < 0) {
+               if (!(machine->util_data.set_mclk % mclk))
+                       mclk = machine->util_data.set_mclk;
+               else {
+                       dev_err(card->dev, "Can't configure clocks\n");
+                       return err;
+               }
+       }
+
+       tegra_asoc_utils_lock_clk_rate(&machine->util_data, 1);
+
+       rate = clk_get_rate(machine->util_data.clk_cdev1);
+
+       err = snd_soc_dai_set_fmt(codec_dai, i2s_daifmt);
+       if (err < 0) {
+               dev_err(card->dev, "codec_dai fmt not set\n");
+               return err;
+       }
+
+       err = snd_soc_dai_set_sysclk(codec_dai, 0, rate, SND_SOC_CLOCK_IN);
+       if (err < 0) {
+               dev_err(card->dev, "codec_dai clock not set\n");
+               return err;
+       }
+
+#ifndef CONFIG_ARCH_TEGRA_2x_SOC
+       /* codec configuration */
+       machine->codec_info[HIFI_CODEC].rate = params_rate(params);
+       machine->codec_info[HIFI_CODEC].channels = params_channels(params);
+#endif
+
+       machine->is_device_bt = 0;
+
+       return 0;
+}
+
+static void tegra_voice_call_shutdown(struct snd_pcm_substream *substream)
+{
+       struct snd_soc_pcm_runtime *rtd = substream->private_data;
+       struct tegra_cs42l73 *machine  =
+                       snd_soc_card_get_drvdata(rtd->codec->card);
+
+#ifndef CONFIG_ARCH_TEGRA_2x_SOC
+       machine->codec_info[HIFI_CODEC].rate = 0;
+       machine->codec_info[HIFI_CODEC].channels = 0;
+#endif
+
+       return;
+}
+
+static int tegra_bt_voice_call_hw_params(struct snd_pcm_substream *substream,
+                       struct snd_pcm_hw_params *params)
+{
+       struct snd_soc_pcm_runtime *rtd = substream->private_data;
+       struct snd_soc_card *card = rtd->card;
+       struct tegra_cs42l73 *machine = snd_soc_card_get_drvdata(card);
+       int err, srate, mclk, min_mclk;
+
+       srate = params_rate(params);
+       switch (srate) {
+       case 11025:
+       case 22050:
+       case 44100:
+       case 88200:
+               mclk = 11289600;
+               break;
+       case 8000:
+       case 16000:
+       case 32000:
+       case 48000:
+       case 64000:
+       case 96000:
+               mclk = 12288000;
+               break;
+       default:
+               return -EINVAL;
+       }
+       min_mclk = 64 * srate;
+
+       err = tegra_asoc_utils_set_rate(&machine->util_data, srate, mclk);
+       if (err < 0) {
+               if (!(machine->util_data.set_mclk % min_mclk))
+                       mclk = machine->util_data.set_mclk;
+               else {
+                       dev_err(card->dev, "Can't configure clocks\n");
+                       return err;
+               }
+       }
+
+       tegra_asoc_utils_lock_clk_rate(&machine->util_data, 1);
+
+#ifndef CONFIG_ARCH_TEGRA_2x_SOC
+       /* codec configuration */
+       machine->codec_info[BT_SCO].rate = params_rate(params);
+       machine->codec_info[BT_SCO].channels = params_channels(params);
+#endif
+
+       machine->is_device_bt = 1;
+
+       return 0;
+}
+
+static void tegra_bt_voice_call_shutdown(struct snd_pcm_substream *substream)
+{
+       struct snd_soc_pcm_runtime *rtd = substream->private_data;
+       struct tegra_cs42l73 *machine  =
+                       snd_soc_card_get_drvdata(rtd->codec->card);
+
+#ifndef CONFIG_ARCH_TEGRA_2x_SOC
+       machine->codec_info[BT_SCO].rate = 0;
+       machine->codec_info[BT_SCO].channels = 0;
+#endif
+
+       return;
+}
+
 static struct snd_soc_ops tegra_cs42l73_ops = {
        .hw_params = tegra_cs42l73_hw_params,
        .hw_free = tegra_hw_free,
+#ifndef CONFIG_ARCH_TEGRA_2x_SOC
+       .startup = tegra_cs42l73_startup,
+       .shutdown = tegra_cs42l73_shutdown,
+#endif
+};
+
+static struct snd_soc_ops tegra_spdif_ops = {
+       .hw_params = tegra_spdif_hw_params,
+       .hw_free = tegra_hw_free,
+};
+
+static struct snd_soc_ops tegra_voice_call_ops = {
+       .hw_params = tegra_voice_call_hw_params,
+       .shutdown = tegra_voice_call_shutdown,
+       .hw_free = tegra_hw_free,
+};
+
+static struct snd_soc_ops tegra_bt_voice_call_ops = {
+       .hw_params = tegra_bt_voice_call_hw_params,
+       .shutdown = tegra_bt_voice_call_shutdown,
+       .hw_free = tegra_hw_free,
+};
+
+static struct snd_soc_ops tegra_bt_ops = {
+       .hw_params = tegra_bt_hw_params,
+       .hw_free = tegra_hw_free,
+#ifndef CONFIG_ARCH_TEGRA_2x_SOC
+       .startup = tegra_cs42l73_startup,
+       .shutdown = tegra_cs42l73_shutdown,
+#endif
 };
 
 
@@ -227,7 +869,9 @@ static int tegra_cs42l73_jack_notifier(struct notifier_block *self,
 
        switch (machine->jack_status) {
        case SND_JACK_HEADPHONE:
-               state = BIT_HEADSET_NO_MIC;
+               /*For now force headset mic mode*/
+               /*state = BIT_HEADSET_NO_MIC; */
+               state = BIT_HEADSET;
                break;
        case SND_JACK_HEADSET:
                state = BIT_HEADSET;
@@ -300,6 +944,31 @@ static int tegra_cs42l73_event_int_spk(struct snd_soc_dapm_widget *w,
 
        gpio_set_value_cansleep(pdata->gpio_spkr_en,
                                SND_SOC_DAPM_EVENT_ON(event));
+
+       return 0;
+}
+
+static int tegra_cs42l73_event_ext_mic(struct snd_soc_dapm_widget *w,
+                                       struct snd_kcontrol *k, int event)
+{
+       struct snd_soc_dapm_context *dapm = w->dapm;
+       struct snd_soc_card *card = dapm->card;
+       struct tegra_cs42l73 *machine = snd_soc_card_get_drvdata(card);
+       struct tegra_asoc_platform_data *pdata = machine->pdata;
+
+       if (machine->hmic_reg) {
+               if (SND_SOC_DAPM_EVENT_ON(event))
+                       regulator_enable(machine->hmic_reg);
+               else
+                       regulator_disable(machine->hmic_reg);
+       }
+
+       if (!(machine->gpio_requested & GPIO_EXT_MIC_EN))
+               return 0;
+
+       gpio_set_value_cansleep(pdata->gpio_ext_mic_en,
+                               SND_SOC_DAPM_EVENT_ON(event));
+
        return 0;
 }
 
@@ -307,14 +976,14 @@ static int tegra_cs42l73_event_int_spk(struct snd_soc_dapm_widget *w,
 static const struct snd_soc_dapm_widget tegra_cs42l73_dapm_widgets[] = {
        SND_SOC_DAPM_SPK("Int Spk", tegra_cs42l73_event_int_spk),
        SND_SOC_DAPM_HP("Headphone", NULL),
-       SND_SOC_DAPM_MIC("Headset Mic", NULL),
+       SND_SOC_DAPM_MIC("Headset Mic", tegra_cs42l73_event_ext_mic),
        SND_SOC_DAPM_MIC("Int D-Mic", tegra_cs42l73_event_int_mic),
 };
 
 /* cs42l73 Audio Map */
 static const struct snd_soc_dapm_route tegra_cs42l73_audio_map[] = {
        {"Int Spk", NULL, "SPKOUT"},
-       {"MIC2", NULL, "Headset Mic"},
+       {"MIC1", NULL, "Headset Mic"},
        /* Headphone (L+R)->  HPOUTA, HPOUTB */
        {"Headphone", NULL, "HPOUTA"},
        {"Headphone", NULL, "HPOUTB"},
@@ -327,6 +996,7 @@ static const struct snd_soc_dapm_route tegra_cs42l73_audio_map[] = {
 static const struct snd_kcontrol_new tegra_cs42l73_controls[] = {
        SOC_DAPM_PIN_SWITCH("Int Spk"),
        SOC_DAPM_PIN_SWITCH("Int D-Mic"),
+       SOC_DAPM_PIN_SWITCH("Headset Mic"),
 };
 
 static int tegra_cs42l73_init(struct snd_soc_pcm_runtime *rtd)
@@ -336,22 +1006,24 @@ static int tegra_cs42l73_init(struct snd_soc_pcm_runtime *rtd)
        struct snd_soc_card *card = codec->card;
        struct tegra_cs42l73 *machine = snd_soc_card_get_drvdata(card);
        struct tegra_asoc_platform_data *pdata = machine->pdata;
+#ifndef CONFIG_ARCH_TEGRA_2x_SOC
+       struct tegra30_i2s *i2s = snd_soc_dai_get_drvdata(rtd->cpu_dai);
+#endif
        int ret;
 
+#ifndef CONFIG_ARCH_TEGRA_2x_SOC
+       if (machine->codec_info[BASEBAND].i2s_id != -1)
+               i2s->is_dam_used = true;
+#endif
 
        if (machine->init_done)
                return 0;
 
        machine->init_done = true;
 
-/*
        machine->pcard = card;
        machine->bias_level = SND_SOC_BIAS_STANDBY;
        machine->clock_enabled = 1;
-*/
-
-       machine->bias_level = SND_SOC_BIAS_STANDBY;
-       machine->clock_enabled = 1;
 
        ret = snd_soc_add_card_controls(card, tegra_cs42l73_controls,
                        ARRAY_SIZE(tegra_cs42l73_controls));
@@ -393,6 +1065,22 @@ static int tegra_cs42l73_init(struct snd_soc_pcm_runtime *rtd)
                machine->gpio_requested |= GPIO_HP_DET;
        }
 
+       if (gpio_is_valid(pdata->gpio_spkr_en)) {
+               ret = gpio_request(pdata->gpio_spkr_en, "spkr_en");
+               if (ret) {
+                       dev_err(card->dev, "cannot get spkr_en gpio\n");
+                       return ret;
+               }
+               machine->gpio_requested |= GPIO_SPKR_EN;
+
+               gpio_direction_output(pdata->gpio_spkr_en, 0);
+       }
+
+
+       /* Add call mode switch control */
+       ret = snd_ctl_add(codec->card->snd_card,
+               snd_ctl_new1(&tegra_call_mode_control, machine));
+
        ret = tegra_asoc_utils_register_ctls(&machine->util_data);
        if (ret < 0)
                return ret;
@@ -400,17 +1088,53 @@ static int tegra_cs42l73_init(struct snd_soc_pcm_runtime *rtd)
        return 0;
 }
 
-static struct snd_soc_dai_link tegra_cs42l73_dai[] = {
-       {
-               .name = "CS42L73",
-               .stream_name = "VSP Playback Record",
-               .codec_name = "cs42l73.0-004a",
-               .platform_name = "tegra-pcm-audio",
-               .cpu_dai_name = "tegra30-i2s.1",
-               .codec_dai_name = "cs42l73-vsp",
-               .init = tegra_cs42l73_init,
-               .ops = &tegra_cs42l73_ops,
-       },
+static struct snd_soc_dai_link tegra_cs42l73_dai[NUM_DAI_LINKS] = {
+       [DAI_LINK_HIFI] = {
+                       .name = "CS42L73",
+                       .stream_name = "VSP Playback Record",
+                       .codec_name = "cs42l73.0-004a",
+                       .platform_name = "tegra-pcm-audio",
+                   .cpu_dai_name = "tegra30-i2s.1",
+                       .codec_dai_name = "cs42l73-vsp",
+                       .init = tegra_cs42l73_init,
+                       .ops = &tegra_cs42l73_ops,
+               },
+       [DAI_LINK_SPDIF] = {
+                       .name = "SPDIF",
+                       .stream_name = "SPDIF PCM",
+                       .codec_name = "spdif-dit.0",
+                       .platform_name = "tegra-pcm-audio",
+                       .cpu_dai_name = "tegra30-spdif",
+                       .codec_dai_name = "dit-hifi",
+                       .ops = &tegra_spdif_ops,
+               },
+       [DAI_LINK_BTSCO] = {
+                       .name = "BT SCO",
+                       .stream_name = "BT SCO PCM",
+                       .codec_name = "spdif-dit.1",
+                       .platform_name = "tegra-pcm-audio",
+                       .codec_dai_name = "dit-hifi",
+                       .init = tegra_cs42l73_init,
+                       .ops = &tegra_bt_ops,
+               },
+       [DAI_LINK_VOICE_CALL] = {
+                       .name = "VOICE CALL",
+                       .stream_name = "VOICE CALL PCM",
+                       .codec_name = "cs42l73.0-004a",
+                       .platform_name = "tegra-pcm-audio",
+                       .cpu_dai_name = "dit-hifi",
+                       .codec_dai_name = "cs42l73-vsp",
+                       .ops = &tegra_voice_call_ops,
+               },
+       [DAI_LINK_BT_VOICE_CALL] = {
+                       .name = "BT VOICE CALL",
+                       .stream_name = "BT VOICE CALL PCM",
+                       .codec_name = "spdif-dit.2",
+                       .platform_name = "tegra-pcm-audio",
+                       .cpu_dai_name = "dit-hifi",
+                       .codec_dai_name = "dit-hifi",
+                       .ops = &tegra_bt_voice_call_ops,
+               },
 };
 
 static int tegra_cs42l73_suspend_post(struct snd_soc_card *card)
@@ -486,6 +1210,7 @@ static __devinit int tegra_cs42l73_driver_probe(struct platform_device *pdev)
        struct tegra_cs42l73 *machine;
        struct tegra_asoc_platform_data *pdata;
        int ret;
+       int i;
        pdata = pdev->dev.platform_data;
        if (!pdata) {
                dev_err(&pdev->dev, "No platform data supplied\n");
@@ -534,6 +1259,12 @@ static __devinit int tegra_cs42l73_driver_probe(struct platform_device *pdev)
                machine->dmic_1v8_reg = 0;
        }
 
+       machine->hmic_reg = regulator_get(&pdev->dev, "mic_ventral");
+       if (IS_ERR(machine->hmic_reg)) {
+               dev_info(&pdev->dev, "No headset mic regulator found\n");
+               machine->hmic_reg = 0;
+       }
+
 #ifdef CONFIG_SWITCH
        /* Addd h2w swith class support */
        ret = switch_dev_register(&tegra_cs42l73_headset_switch);
@@ -544,6 +1275,34 @@ static __devinit int tegra_cs42l73_driver_probe(struct platform_device *pdev)
        card->dev = &pdev->dev;
        platform_set_drvdata(pdev, card);
        snd_soc_card_set_drvdata(card, machine);
+
+
+
+#ifndef CONFIG_ARCH_TEGRA_2x_SOC
+       for (i = 0; i < NUM_I2S_DEVICES ; i++) {
+               machine->codec_info[i].i2s_id =
+                       pdata->i2s_param[i].audio_port_id;
+               machine->codec_info[i].bitsize =
+                       pdata->i2s_param[i].sample_size;
+               machine->codec_info[i].is_i2smaster =
+                       pdata->i2s_param[i].is_i2s_master;
+               machine->codec_info[i].rate =
+                       pdata->i2s_param[i].rate;
+               machine->codec_info[i].channels =
+                       pdata->i2s_param[i].channels;
+               if ((pdata->i2s_param[i].i2s_mode == TEGRA_DAIFMT_DSP_A) ||
+                       (pdata->i2s_param[i].i2s_mode == TEGRA_DAIFMT_DSP_B))
+                       machine->codec_info[i].is_format_dsp = 1;
+               else
+                       machine->codec_info[i].is_format_dsp = 0;
+       }
+
+       tegra_cs42l73_dai[DAI_LINK_HIFI].cpu_dai_name =
+       tegra_cs42l73_i2s_dai_name[machine->codec_info[HIFI_CODEC].i2s_id];
+
+       tegra_cs42l73_dai[DAI_LINK_BTSCO].cpu_dai_name =
+       tegra_cs42l73_i2s_dai_name[machine->codec_info[BT_SCO].i2s_id];
+#endif
        card->dapm.idle_bias_off = 1;
        ret = snd_soc_register_card(card);
        if (ret) {
@@ -600,6 +1359,8 @@ static int __devexit tegra_cs42l73_driver_remove(struct platform_device *pdev)
                regulator_put(machine->dmic_reg);
        if (machine->dmic_1v8_reg)
                regulator_put(machine->dmic_1v8_reg);
+       if (machine->hmic_reg)
+               regulator_put(machine->hmic_reg);
 
        if (gpio_is_valid(pdata->gpio_ldo1_en)) {
                gpio_set_value(pdata->gpio_ldo1_en, 0);