asoc: tegra: aic326x machine: add voice call functionalities for ap30
[linux-2.6.git] / sound / soc / tegra / tegra_aic326x.c
1 /*
2  * tegra_aic326x.c - Tegra machine ASoC driver for boards using TI 3262 codec.
3  *
4  * Author: Vinod G. <vinodg@nvidia.com>
5  * Copyright (C) 2011 - NVIDIA, Inc.
6  *
7  * Based on code copyright/by:
8  *
9  * (c) 2010, 2011 Nvidia Graphics Pvt. Ltd.
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * version 2 as published by the Free Software Foundation.
14  *
15  * This program is distributed in the hope that it will be useful, but
16  * WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
23  * 02110-1301 USA
24  *
25  */
26
27 #include <asm/mach-types.h>
28
29 #include <linux/module.h>
30 #include <linux/platform_device.h>
31 #include <linux/slab.h>
32 #include <linux/gpio.h>
33 #include <linux/regulator/consumer.h>
34 #ifdef CONFIG_SWITCH
35 #include <linux/switch.h>
36 #endif
37
38 #include <mach/tegra_aic326x_pdata.h>
39
40 #include <sound/core.h>
41 #include <sound/jack.h>
42 #include <sound/pcm.h>
43 #include <sound/pcm_params.h>
44 #include <sound/soc.h>
45
46 #include "../codecs/tlv320aic326x.h"
47
48 #include "tegra_pcm.h"
49 #include "tegra_asoc_utils.h"
50
51 #ifdef CONFIG_ARCH_TEGRA_2x_SOC
52 #include "tegra20_das.h"
53 #else
54 #include "tegra30_ahub.h"
55 #include "tegra30_i2s.h"
56 #include "tegra30_dam.h"
57 #endif
58
59
60 #define DRV_NAME "tegra-snd-aic326x"
61
62 #define GPIO_SPKR_EN    BIT(0)
63 #define GPIO_HP_MUTE    BIT(1)
64 #define GPIO_INT_MIC_EN BIT(2)
65 #define GPIO_EXT_MIC_EN BIT(3)
66
67 #define DAI_LINK_HIFI           0
68 #define DAI_LINK_SPDIF          1
69 #define DAI_LINK_BTSCO          2
70 #define DAI_LINK_VOICE_CALL     3
71 #define DAI_LINK_BT_VOICE_CALL  4
72 #define NUM_DAI_LINKS   5
73
74 extern int g_is_call_mode;
75
76 #ifndef CONFIG_ARCH_TEGRA_2x_SOC
77 const char *tegra_i2s_dai_name[TEGRA30_NR_I2S_IFC] = {
78         "tegra30-i2s.0",
79         "tegra30-i2s.1",
80         "tegra30-i2s.2",
81         "tegra30-i2s.3",
82         "tegra30-i2s.4",
83 };
84 #endif
85
86 struct tegra_aic326x {
87         struct tegra_asoc_utils_data util_data;
88         struct tegra_aic326x_platform_data *pdata;
89         struct regulator *audio_reg;
90         int gpio_requested;
91         bool init_done;
92         int is_call_mode;
93         int is_device_bt;
94 #ifndef CONFIG_ARCH_TEGRA_2x_SOC
95         struct codec_config codec_info[NUM_I2S_DEVICES];
96         struct snd_soc_card *pcard;
97 #endif
98 };
99
100 static int tegra_aic326x_call_mode_info(struct snd_kcontrol *kcontrol,
101                         struct snd_ctl_elem_info *uinfo)
102 {
103         uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
104         uinfo->count = 1;
105         uinfo->value.integer.min = 0;
106         uinfo->value.integer.max = 1;
107         return 0;
108 }
109
110 static int tegra_aic326x_call_mode_get(struct snd_kcontrol *kcontrol,
111                 struct snd_ctl_elem_value *ucontrol)
112 {
113         struct tegra_aic326x *machine = snd_kcontrol_chip(kcontrol);
114
115         ucontrol->value.integer.value[0] = machine->is_call_mode;
116
117         return 0;
118 }
119
120 static int tegra_aic326x_call_mode_put(struct snd_kcontrol *kcontrol,
121                 struct snd_ctl_elem_value *ucontrol)
122 {
123         struct tegra_aic326x *machine = snd_kcontrol_chip(kcontrol);
124         int is_call_mode_new = ucontrol->value.integer.value[0];
125 #ifdef CONFIG_ARCH_TEGRA_2x_SOC
126         int codec_dap_id, codec_dap_sel, bb_dap_id, bb_dap_sel;
127 #else /*assumes tegra3*/
128         int codec_index;
129         unsigned int i;
130 #endif
131
132         if (machine->is_call_mode == is_call_mode_new)
133                 return 0;
134
135 #ifdef CONFIG_ARCH_TEGRA_2x_SOC
136         bb_dap_id = TEGRA20_DAS_DAP_ID_3;
137         bb_dap_sel = TEGRA20_DAS_DAP_SEL_DAP3;
138
139         if (machine->is_device_bt) {
140                 codec_dap_id = TEGRA20_DAS_DAP_ID_4;
141                 codec_dap_sel = TEGRA20_DAS_DAP_SEL_DAP4;
142         }
143         else {
144                 codec_dap_id = TEGRA20_DAS_DAP_ID_2;
145                 codec_dap_sel = TEGRA20_DAS_DAP_SEL_DAP2;
146         }
147 #else /*assumes tegra3*/
148         if (machine->is_device_bt)
149                 codec_index = BT_SCO;
150         else
151                 codec_index = HIFI_CODEC;
152 #endif
153
154         if (is_call_mode_new) {
155 #ifdef CONFIG_ARCH_TEGRA_2x_SOC
156                 tegra20_das_set_tristate(codec_dap_id, 1);
157                 tegra20_das_set_tristate(bb_dap_id, 1);
158                 tegra20_das_connect_dap_to_dap(codec_dap_id,
159                         bb_dap_sel, 0, 0, 0);
160                 tegra20_das_connect_dap_to_dap(bb_dap_id,
161                         codec_dap_sel, 1, 0, 0);
162                 tegra20_das_set_tristate(codec_dap_id, 0);
163                 tegra20_das_set_tristate(bb_dap_id, 0);
164 #else /*assumes tegra3*/
165                 if (machine->codec_info[codec_index].rate == 0 ||
166                         machine->codec_info[codec_index].channels == 0)
167                                 return -EINVAL;
168
169                 for (i = 0; i < machine->pcard->num_links; i++)
170                         machine->pcard->dai_link[i].ignore_suspend = 1;
171
172                 tegra30_make_voice_call_connections(
173                         &machine->codec_info[codec_index],
174                         &machine->codec_info[BASEBAND]);
175 #endif
176         } else {
177 #ifdef CONFIG_ARCH_TEGRA_2x_SOC
178                 tegra20_das_set_tristate(codec_dap_id, 1);
179                 tegra20_das_set_tristate(bb_dap_id, 1);
180                 tegra20_das_connect_dap_to_dap(bb_dap_id,
181                         bb_dap_sel, 0, 0, 0);
182                 tegra20_das_connect_dap_to_dap(codec_dap_id,
183                         codec_dap_sel, 0, 0, 0);
184                 tegra20_das_set_tristate(codec_dap_id, 0);
185                 tegra20_das_set_tristate(bb_dap_id, 0);
186 #else /*assumes tegra3*/
187                 tegra30_break_voice_call_connections(
188                         &machine->codec_info[codec_index],
189                         &machine->codec_info[BASEBAND]);
190
191                 for (i = 0; i < machine->pcard->num_links; i++)
192                         machine->pcard->dai_link[i].ignore_suspend = 0;
193 #endif
194         }
195
196         machine->is_call_mode = is_call_mode_new;
197         g_is_call_mode = machine->is_call_mode;
198
199         return 1;
200 }
201
202 struct snd_kcontrol_new tegra_aic326x_call_mode_control = {
203         .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
204         .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
205         .name = "Call Mode Switch",
206         .private_value = 0xffff,
207         .info = tegra_aic326x_call_mode_info,
208         .get = tegra_aic326x_call_mode_get,
209         .put = tegra_aic326x_call_mode_put
210 };
211
212 static int tegra_aic326x_get_mclk(int srate)
213 {
214         int mclk = 0;
215         switch (srate) {
216         case 8000:
217         case 16000:
218         case 24000:
219         case 32000:
220         case 48000:
221         case 64000:
222         case 96000:
223                 mclk = 12288000;
224                 break;
225         case 11025:
226         case 22050:
227         case 44100:
228         case 88200:
229                 mclk = 11289600;
230                 break;
231         default:
232                 mclk = -EINVAL;
233                 break;
234         }
235
236         return mclk;
237 }
238
239 #ifndef CONFIG_ARCH_TEGRA_2x_SOC
240 static int tegra_aic326x_set_dam_cif(int dam_ifc, int srate,
241                         int channels, int bit_size, int src_on, int src_srate,
242                         int src_channels, int src_bit_size)
243 {
244         tegra30_dam_set_gain(dam_ifc, TEGRA30_DAM_CHIN1, 0x1000);
245         tegra30_dam_set_samplerate(dam_ifc, TEGRA30_DAM_CHOUT,
246                                 srate);
247         tegra30_dam_set_samplerate(dam_ifc, TEGRA30_DAM_CHIN1,
248                                 srate);
249         tegra30_dam_set_acif(dam_ifc, TEGRA30_DAM_CHIN1,
250                 channels, bit_size, channels,
251                                 bit_size);
252         tegra30_dam_set_acif(dam_ifc, TEGRA30_DAM_CHOUT,
253                 channels, bit_size, channels,
254                                 bit_size);
255
256         if (src_on) {
257                 tegra30_dam_set_gain(dam_ifc, TEGRA30_DAM_CHIN0_SRC, 0x1000);
258                 tegra30_dam_set_samplerate(dam_ifc, TEGRA30_DAM_CHIN0_SRC,
259                         src_srate);
260                 tegra30_dam_set_acif(dam_ifc, TEGRA30_DAM_CHIN0_SRC,
261                         src_channels, src_bit_size, 1, 16);
262         }
263
264         return 0;
265 }
266 #endif
267
268 static int tegra_aic326x_hw_params(struct snd_pcm_substream *substream,
269                                         struct snd_pcm_hw_params *params)
270 {
271         struct snd_soc_pcm_runtime *rtd = substream->private_data;
272         struct snd_soc_dai *codec_dai = rtd->codec_dai;
273         struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
274         struct snd_soc_codec *codec = rtd->codec;
275         struct snd_soc_card *card = codec->card;
276         struct tegra_aic326x *machine = snd_soc_card_get_drvdata(card);
277         int srate, mclk, sample_size, daifmt;
278         int err;
279 #ifndef CONFIG_ARCH_TEGRA_2x_SOC
280         struct tegra30_i2s *i2s = snd_soc_dai_get_drvdata(cpu_dai);
281 #endif
282
283         switch (params_format(params)) {
284         case SNDRV_PCM_FORMAT_S16_LE:
285                 sample_size = 16;
286                 break;
287         default:
288                 return -EINVAL;
289         }
290
291         srate = params_rate(params);
292
293         mclk = tegra_aic326x_get_mclk(srate);
294         if (mclk < 0)
295                 return mclk;
296
297         daifmt = SND_SOC_DAIFMT_I2S |
298                         SND_SOC_DAIFMT_NB_NF |
299                         SND_SOC_DAIFMT_CBS_CFS;
300
301         err = tegra_asoc_utils_set_rate(&machine->util_data, srate, mclk);
302         if (err < 0) {
303                 if (!(machine->util_data.set_mclk % mclk))
304                         mclk = machine->util_data.set_mclk;
305                 else {
306                         dev_err(card->dev, "Can't configure clocks\n");
307                         return err;
308                 }
309         }
310
311         tegra_asoc_utils_lock_clk_rate(&machine->util_data, 1);
312
313         err = snd_soc_dai_set_fmt(codec_dai, daifmt);
314         if (err < 0) {
315                 dev_err(card->dev, "codec_dai fmt not set\n");
316                 return err;
317         }
318
319         err = snd_soc_dai_set_fmt(cpu_dai, daifmt);
320         if (err < 0) {
321                 dev_err(card->dev, "cpu_dai fmt not set\n");
322                 return err;
323         }
324
325         err = snd_soc_dai_set_sysclk(codec_dai, 0, mclk,
326                                         SND_SOC_CLOCK_IN);
327         if (err < 0) {
328                 dev_err(card->dev, "codec_dai clock not set\n");
329                 return err;
330         }
331
332 #ifdef CONFIG_ARCH_TEGRA_2x_SOC
333         err = tegra20_das_connect_dac_to_dap(TEGRA20_DAS_DAP_SEL_DAC1,
334                                         TEGRA20_DAS_DAP_ID_1);
335         if (err < 0) {
336                 dev_err(card->dev, "failed to set dap-dac path\n");
337                 return err;
338         }
339
340         err = tegra20_das_connect_dap_to_dac(TEGRA20_DAS_DAP_ID_1,
341                                         TEGRA20_DAS_DAP_SEL_DAC1);
342         if (err < 0) {
343                 dev_err(card->dev, "failed to set dac-dap path\n");
344                 return err;
345         }
346 #else /*assumes tegra3*/
347         if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK  && i2s->is_dam_used)
348                 tegra_aic326x_set_dam_cif(i2s->dam_ifc, srate,
349                         params_channels(params), sample_size, 0, 0, 0, 0);
350 #endif
351
352         return 0;
353 }
354
355 static int tegra_aic326x_spdif_hw_params(struct snd_pcm_substream *substream,
356                                         struct snd_pcm_hw_params *params)
357 {
358         struct snd_soc_pcm_runtime *rtd = substream->private_data;
359         struct snd_soc_card *card = rtd->card;
360         struct tegra_aic326x *machine = snd_soc_card_get_drvdata(card);
361         int srate, mclk, min_mclk;
362         int err;
363
364         srate = params_rate(params);
365
366         mclk = tegra_aic326x_get_mclk(srate);
367         if (mclk < 0)
368                 return mclk;
369
370         min_mclk = 128 * srate;
371
372         err = tegra_asoc_utils_set_rate(&machine->util_data, srate, mclk);
373         if (err < 0) {
374                 if (!(machine->util_data.set_mclk % min_mclk))
375                         mclk = machine->util_data.set_mclk;
376                 else {
377                         dev_err(card->dev, "Can't configure clocks\n");
378                         return err;
379                 }
380         }
381
382         tegra_asoc_utils_lock_clk_rate(&machine->util_data, 1);
383
384         return 0;
385 }
386
387 static int tegra_aic326x_bt_hw_params(struct snd_pcm_substream *substream,
388                 struct snd_pcm_hw_params *params)
389 {
390         struct snd_soc_pcm_runtime *rtd = substream->private_data;
391         struct snd_soc_card *card = rtd->card;
392         struct tegra_aic326x *machine = snd_soc_card_get_drvdata(card);
393         int err, srate, mclk, min_mclk, sample_size;
394 #ifndef CONFIG_ARCH_TEGRA_2x_SOC
395         struct tegra30_i2s *i2s = snd_soc_dai_get_drvdata(rtd->cpu_dai);
396 #endif
397
398         switch (params_format(params)) {
399         case SNDRV_PCM_FORMAT_S16_LE:
400                 sample_size = 16;
401                 break;
402         default:
403                 return -EINVAL;
404         }
405
406         srate = params_rate(params);
407
408         mclk = tegra_aic326x_get_mclk(srate);
409         if (mclk < 0)
410                 return mclk;
411
412         min_mclk = 64 * srate;
413
414         err = tegra_asoc_utils_set_rate(&machine->util_data, srate, mclk);
415         if (err < 0) {
416                 if (!(machine->util_data.set_mclk % min_mclk))
417                         mclk = machine->util_data.set_mclk;
418                 else {
419                         dev_err(card->dev, "Can't configure clocks\n");
420                         return err;
421                 }
422         }
423
424         tegra_asoc_utils_lock_clk_rate(&machine->util_data, 1);
425
426         err = snd_soc_dai_set_fmt(rtd->cpu_dai,
427                         SND_SOC_DAIFMT_DSP_A |
428                         SND_SOC_DAIFMT_NB_NF |
429                         SND_SOC_DAIFMT_CBS_CFS);
430
431         if (err < 0) {
432                 dev_err(rtd->codec->card->dev, "cpu_dai fmt not set\n");
433                 return err;
434         }
435
436 #ifdef CONFIG_ARCH_TEGRA_2x_SOC
437         err = tegra20_das_connect_dac_to_dap(TEGRA20_DAS_DAP_SEL_DAC2,
438                                         TEGRA20_DAS_DAP_ID_4);
439         if (err < 0) {
440                 dev_err(card->dev, "failed to set dac-dap path\n");
441                 return err;
442         }
443
444         err = tegra20_das_connect_dap_to_dac(TEGRA20_DAS_DAP_ID_4,
445                                         TEGRA20_DAS_DAP_SEL_DAC2);
446         if (err < 0) {
447                 dev_err(card->dev, "failed to set dac-dap path\n");
448                 return err;
449         }
450 #else
451         if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK && i2s->is_dam_used)
452                 tegra_aic326x_set_dam_cif(i2s->dam_ifc, params_rate(params),
453                         params_channels(params), sample_size, 0, 0, 0, 0);
454 #endif
455
456         return 0;
457 }
458
459 #ifndef CONFIG_ARCH_TEGRA_2x_SOC
460 static int tegra_aic326x_startup(struct snd_pcm_substream *substream)
461 {
462         struct snd_soc_pcm_runtime *rtd = substream->private_data;
463         struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
464         struct tegra30_i2s *i2s = snd_soc_dai_get_drvdata(cpu_dai);
465         struct tegra_aic326x *machine = snd_soc_card_get_drvdata(rtd->card);
466         struct codec_config *codec_info;
467         struct codec_config *bb_info;
468         int codec_index;
469
470         if (!i2s->is_dam_used)
471                 return 0;
472
473         if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
474                 /*dam configuration*/
475                 if (!i2s->dam_ch_refcount)
476                         i2s->dam_ifc = tegra30_dam_allocate_controller();
477
478                 tegra30_dam_allocate_channel(i2s->dam_ifc, TEGRA30_DAM_CHIN1);
479                 i2s->dam_ch_refcount++;
480                 tegra30_dam_enable_clock(i2s->dam_ifc);
481
482                 tegra30_ahub_set_rx_cif_source(TEGRA30_AHUB_RXCIF_DAM0_RX1 +
483                                 (i2s->dam_ifc*2), i2s->txcif);
484
485                 /*
486                 *make the dam tx to i2s rx connection if this is the only client
487                 *using i2s for playback
488                 */
489                 if (i2s->playback_ref_count == 1)
490                         tegra30_ahub_set_rx_cif_source(
491                                 TEGRA30_AHUB_RXCIF_I2S0_RX0 + i2s->id,
492                                 TEGRA30_AHUB_TXCIF_DAM0_TX0 + i2s->dam_ifc);
493
494                 /* enable the dam*/
495                 tegra30_dam_enable(i2s->dam_ifc, TEGRA30_DAM_ENABLE,
496                                 TEGRA30_DAM_CHIN1);
497         } else {
498
499                 i2s->is_call_mode_rec = machine->is_call_mode;
500
501                 if (!i2s->is_call_mode_rec)
502                         return 0;
503
504                 if (machine->is_device_bt)
505                         codec_index = BT_SCO;
506                 else
507                         codec_index = HIFI_CODEC;
508
509                 codec_info = &machine->codec_info[codec_index];
510                 bb_info = &machine->codec_info[BASEBAND];
511
512                 /* allocate a dam for voice call recording */
513
514                 i2s->call_record_dam_ifc = tegra30_dam_allocate_controller();
515                 tegra30_dam_allocate_channel(i2s->call_record_dam_ifc,
516                         TEGRA30_DAM_CHIN0_SRC);
517                 tegra30_dam_allocate_channel(i2s->call_record_dam_ifc,
518                         TEGRA30_DAM_CHIN1);
519                 tegra30_dam_enable_clock(i2s->call_record_dam_ifc);
520
521                 /* configure the dam */
522                 tegra_aic326x_set_dam_cif(i2s->call_record_dam_ifc,
523                         codec_info->rate, codec_info->channels,
524                         codec_info->bitsize, 1, bb_info->rate,
525                         bb_info->channels, bb_info->bitsize);
526
527                 /* setup the connections for voice call record */
528
529                 tegra30_ahub_unset_rx_cif_source(i2s->rxcif);
530                 tegra30_ahub_set_rx_cif_source(TEGRA30_AHUB_RXCIF_DAM0_RX0 +
531                         (i2s->call_record_dam_ifc*2),
532                         TEGRA30_AHUB_TXCIF_I2S0_TX0 + bb_info->i2s_id);
533                 tegra30_ahub_set_rx_cif_source(TEGRA30_AHUB_RXCIF_DAM0_RX1 +
534                         (i2s->call_record_dam_ifc*2),
535                         TEGRA30_AHUB_TXCIF_I2S0_TX0 + codec_info->i2s_id);
536                 tegra30_ahub_set_rx_cif_source(i2s->rxcif,
537                         TEGRA30_AHUB_TXCIF_DAM0_TX0 + i2s->call_record_dam_ifc);
538
539                 /* enable the dam*/
540
541                 tegra30_dam_enable(i2s->call_record_dam_ifc, TEGRA30_DAM_ENABLE,
542                                 TEGRA30_DAM_CHIN1);
543                 tegra30_dam_enable(i2s->call_record_dam_ifc, TEGRA30_DAM_ENABLE,
544                                 TEGRA30_DAM_CHIN0_SRC);
545         }
546
547         return 0;
548 }
549
550 static void tegra_aic326x_shutdown(struct snd_pcm_substream *substream)
551 {
552         struct snd_soc_pcm_runtime *rtd = substream->private_data;
553         struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
554         struct tegra30_i2s *i2s = snd_soc_dai_get_drvdata(cpu_dai);
555
556         if (!i2s->is_dam_used)
557                 return;
558
559         if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
560                 /* disable the dam*/
561                 tegra30_dam_enable(i2s->dam_ifc, TEGRA30_DAM_DISABLE,
562                                 TEGRA30_DAM_CHIN1);
563
564                 /* disconnect the ahub connections*/
565                 tegra30_ahub_unset_rx_cif_source(TEGRA30_AHUB_RXCIF_DAM0_RX1 +
566                                         (i2s->dam_ifc*2));
567
568                 /* disable the dam and free the controller */
569                 tegra30_dam_disable_clock(i2s->dam_ifc);
570                 tegra30_dam_free_channel(i2s->dam_ifc, TEGRA30_DAM_CHIN1);
571                 i2s->dam_ch_refcount--;
572                 if (!i2s->dam_ch_refcount)
573                         tegra30_dam_free_controller(i2s->dam_ifc);
574          } else {
575
576                 if (!i2s->is_call_mode_rec)
577                         return 0;
578
579                 i2s->is_call_mode_rec = 0;
580
581                 /* disable the dam*/
582                 tegra30_dam_enable(i2s->call_record_dam_ifc,
583                         TEGRA30_DAM_DISABLE, TEGRA30_DAM_CHIN1);
584                 tegra30_dam_enable(i2s->call_record_dam_ifc,
585                         TEGRA30_DAM_DISABLE, TEGRA30_DAM_CHIN0_SRC);
586
587                 /* disconnect the ahub connections*/
588                 tegra30_ahub_unset_rx_cif_source(i2s->rxcif);
589                 tegra30_ahub_unset_rx_cif_source(TEGRA30_AHUB_RXCIF_DAM0_RX0 +
590                         (i2s->call_record_dam_ifc*2));
591                 tegra30_ahub_unset_rx_cif_source(TEGRA30_AHUB_RXCIF_DAM0_RX1 +
592                         (i2s->call_record_dam_ifc*2));
593
594                 /* free the dam channels and dam controller */
595                 tegra30_dam_disable_clock(i2s->call_record_dam_ifc);
596                 tegra30_dam_free_channel(i2s->call_record_dam_ifc,
597                         TEGRA30_DAM_CHIN1);
598                 tegra30_dam_free_channel(i2s->call_record_dam_ifc,
599                         TEGRA30_DAM_CHIN0_SRC);
600                 tegra30_dam_free_controller(i2s->call_record_dam_ifc);
601          }
602
603         return;
604 }
605 #endif
606
607
608 static int tegra_aic326x_hw_free(struct snd_pcm_substream *substream)
609 {
610         struct snd_soc_pcm_runtime *rtd = substream->private_data;
611         struct tegra_aic326x *machine = snd_soc_card_get_drvdata(rtd->card);
612
613         tegra_asoc_utils_lock_clk_rate(&machine->util_data, 0);
614
615         return 0;
616 }
617
618 static int tegra_aic326x_voice_call_hw_params(
619                         struct snd_pcm_substream *substream,
620                         struct snd_pcm_hw_params *params)
621 {
622         struct snd_soc_pcm_runtime *rtd = substream->private_data;
623         struct snd_soc_dai *codec_dai = rtd->codec_dai;
624         struct snd_soc_codec *codec = rtd->codec;
625         struct snd_soc_card *card = codec->card;
626         struct tegra_aic326x *machine = snd_soc_card_get_drvdata(card);
627         int srate, mclk;
628         int err, pcmdiv, vxclkdiv;;
629
630         srate = params_rate(params);
631         mclk = tegra_aic326x_get_mclk(srate);
632         if (mclk < 0)
633                 return mclk;
634
635         err = tegra_asoc_utils_set_rate(&machine->util_data, srate, mclk);
636         if (err < 0) {
637                 if (!(machine->util_data.set_mclk % mclk))
638                         mclk = machine->util_data.set_mclk;
639                 else {
640                         dev_err(card->dev, "Can't configure clocks\n");
641                         return err;
642                 }
643         }
644
645         tegra_asoc_utils_lock_clk_rate(&machine->util_data, 1);
646
647         if(machine_is_tegra_enterprise()) {
648                 err = snd_soc_dai_set_fmt(codec_dai,
649                                         SND_SOC_DAIFMT_I2S |
650                                         SND_SOC_DAIFMT_NB_NF |
651                                         SND_SOC_DAIFMT_CBS_CFS);
652         } else {
653                 err = snd_soc_dai_set_fmt(codec_dai,
654                                         SND_SOC_DAIFMT_DSP_B |
655                                         SND_SOC_DAIFMT_NB_NF |
656                                         SND_SOC_DAIFMT_CBS_CFS);
657         }
658
659         if (err < 0) {
660                 dev_err(card->dev, "codec_dai fmt not set\n");
661                 return err;
662         }
663
664         err = snd_soc_dai_set_sysclk(codec_dai, 0, mclk,
665                                         SND_SOC_CLOCK_IN);
666         if (err < 0) {
667                 dev_err(card->dev, "codec_dai clock not set\n");
668                 return err;
669         }
670
671         if(!machine_is_tegra_enterprise()) {
672                 if (params_rate(params) == 8000) {
673                         /* Change these Settings for 8KHz*/
674                         pcmdiv = 1;
675                         /* BB expecting 2048Khz bclk */
676                         vxclkdiv = 27;
677                 } else if (params_rate(params) == 16000) {
678                         pcmdiv = 1;
679                         /* BB expecting 2048Khz bclk */
680                         vxclkdiv = 27;
681                 } else {
682                         dev_err(card->dev, "codec_dai unsupported voice rate\n");
683                         return -EINVAL;
684                 }
685         }
686
687         //snd_soc_dai_set_clkdiv(codec_dai, ASI2_BCLK_N, vxclkdiv);
688         //snd_soc_dai_set_clkdiv(codec_dai, ASI2_WCLK_N, pcmdiv);
689
690 #ifndef CONFIG_ARCH_TEGRA_2x_SOC
691         /* codec configuration */
692         machine->codec_info[HIFI_CODEC].rate = params_rate(params);
693         machine->codec_info[HIFI_CODEC].channels = params_channels(params);
694         machine->codec_info[HIFI_CODEC].bitsize = 16;
695         machine->codec_info[HIFI_CODEC].is_i2smaster = 1;
696         machine->codec_info[HIFI_CODEC].is_format_dsp = 0;
697
698         /* baseband configuration */
699         machine->codec_info[BASEBAND].bitsize = 16;
700         machine->codec_info[BASEBAND].is_i2smaster = 1;
701         machine->codec_info[BASEBAND].is_format_dsp = 1;
702 #endif
703
704         machine->is_device_bt = 0;
705
706         return 0;
707 }
708
709 static void tegra_aic326x_voice_call_shutdown(
710                                         struct snd_pcm_substream *substream)
711 {
712         struct snd_soc_pcm_runtime *rtd = substream->private_data;
713         struct tegra_aic326x *machine  =
714                         snd_soc_card_get_drvdata(rtd->codec->card);
715
716 #ifndef CONFIG_ARCH_TEGRA_2x_SOC
717         machine->codec_info[HIFI_CODEC].rate = 0;
718         machine->codec_info[HIFI_CODEC].channels = 0;
719 #endif
720
721         machine->is_device_bt = 0;
722 }
723
724 static int tegra_aic326x_bt_voice_call_hw_params(
725                         struct snd_pcm_substream *substream,
726                         struct snd_pcm_hw_params *params)
727 {
728         struct snd_soc_pcm_runtime *rtd = substream->private_data;
729         struct snd_soc_card *card = rtd->card;
730         struct tegra_aic326x *machine = snd_soc_card_get_drvdata(card);
731         int err, srate, mclk, min_mclk;
732
733         srate = params_rate(params);
734
735         mclk = tegra_aic326x_get_mclk(srate);
736         if (mclk < 0)
737                 return mclk;
738
739         min_mclk = 64 * srate;
740
741         err = tegra_asoc_utils_set_rate(&machine->util_data, srate, mclk);
742         if (err < 0) {
743                 if (!(machine->util_data.set_mclk % min_mclk))
744                         mclk = machine->util_data.set_mclk;
745                 else {
746                         dev_err(card->dev, "Can't configure clocks\n");
747                         return err;
748                 }
749         }
750
751         tegra_asoc_utils_lock_clk_rate(&machine->util_data, 1);
752
753 #ifndef CONFIG_ARCH_TEGRA_2x_SOC
754         /* codec configuration */
755         machine->codec_info[BT_SCO].rate = params_rate(params);
756         machine->codec_info[BT_SCO].channels = params_channels(params);
757         machine->codec_info[BT_SCO].bitsize = 16;
758         machine->codec_info[BT_SCO].is_i2smaster = 1;
759         machine->codec_info[BT_SCO].is_format_dsp = 1;
760
761         /* baseband configuration */
762         machine->codec_info[BASEBAND].bitsize = 16;
763         machine->codec_info[BASEBAND].is_i2smaster = 1;
764         machine->codec_info[BASEBAND].is_format_dsp = 1;
765 #endif
766
767         machine->is_device_bt = 1;
768
769         return 0;
770 }
771
772 static void tegra_aic326x_bt_voice_call_shutdown(
773                                 struct snd_pcm_substream *substream)
774 {
775         struct snd_soc_pcm_runtime *rtd = substream->private_data;
776         struct tegra_aic326x *machine  =
777                         snd_soc_card_get_drvdata(rtd->codec->card);
778
779 #ifndef CONFIG_ARCH_TEGRA_2x_SOC
780         machine->codec_info[BT_SCO].rate = 0;
781         machine->codec_info[BT_SCO].channels = 0;
782 #endif
783
784         machine->is_device_bt = 0;
785 }
786
787 static struct snd_soc_ops tegra_aic326x_hifi_ops = {
788         .hw_params = tegra_aic326x_hw_params,
789         .hw_free = tegra_aic326x_hw_free,
790 #ifndef CONFIG_ARCH_TEGRA_2x_SOC
791         .startup = tegra_aic326x_startup,
792         .shutdown = tegra_aic326x_shutdown,
793 #endif
794 };
795
796 static struct snd_soc_ops tegra_aic326x_spdif_ops = {
797         .hw_params = tegra_aic326x_spdif_hw_params,
798         .hw_free = tegra_aic326x_hw_free,
799 };
800
801 static struct snd_soc_ops tegra_aic326x_voice_call_ops = {
802         .hw_params = tegra_aic326x_voice_call_hw_params,
803         .shutdown = tegra_aic326x_voice_call_shutdown,
804         .hw_free = tegra_aic326x_hw_free,
805 };
806
807 static struct snd_soc_ops tegra_aic326x_bt_voice_call_ops = {
808         .hw_params = tegra_aic326x_bt_voice_call_hw_params,
809         .shutdown = tegra_aic326x_bt_voice_call_shutdown,
810         .hw_free = tegra_aic326x_hw_free,
811 };
812
813 static struct snd_soc_ops tegra_aic326x_bt_ops = {
814         .hw_params = tegra_aic326x_bt_hw_params,
815         .hw_free = tegra_aic326x_hw_free,
816 #ifndef CONFIG_ARCH_TEGRA_2x_SOC
817         .startup = tegra_aic326x_startup,
818         .shutdown = tegra_aic326x_shutdown,
819 #endif
820 };
821
822 static struct snd_soc_jack tegra_aic326x_hp_jack;
823
824 #ifdef CONFIG_SWITCH
825 static struct switch_dev aic326x_wired_switch_dev = {
826         .name = "h2w",
827 };
828
829 /* These values are copied from WiredAccessoryObserver */
830 enum headset_state {
831         BIT_NO_HEADSET = 0,
832         BIT_HEADSET = (1 << 0),
833         BIT_HEADSET_NO_MIC = (1 << 1),
834 };
835
836 static int aic326x_headset_switch_notify(struct notifier_block *self,
837         unsigned long action, void *dev)
838 {
839         int state = 0;
840
841         switch (action) {
842         case SND_JACK_HEADPHONE:
843                 state |= BIT_HEADSET_NO_MIC;
844                 break;
845         case SND_JACK_HEADSET:
846                 state |= BIT_HEADSET;
847                 break;
848         default:
849                 state |= BIT_NO_HEADSET;
850         }
851
852         switch_set_state(&aic326x_wired_switch_dev, state);
853
854         return NOTIFY_OK;
855 }
856
857 static struct notifier_block aic326x_headset_switch_nb = {
858         .notifier_call = aic326x_headset_switch_notify,
859 };
860 #else
861 static struct snd_soc_jack_pin tegra_aic326x_hp_jack_pins[] = {
862         {
863                 .pin = "Headphone Jack",
864                 .mask = SND_JACK_HEADPHONE,
865         },
866 };
867 #endif
868
869 static int tegra_aic326x_event_int_spk(struct snd_soc_dapm_widget *w,
870                                         struct snd_kcontrol *k, int event)
871 {
872         struct snd_soc_dapm_context *dapm = w->dapm;
873         struct snd_soc_card *card = dapm->card;
874         struct tegra_aic326x *machine = snd_soc_card_get_drvdata(card);
875         struct tegra_aic326x_platform_data *pdata = machine->pdata;
876
877         if (!(machine->gpio_requested & GPIO_SPKR_EN))
878                 return 0;
879
880         gpio_set_value_cansleep(pdata->gpio_spkr_en,
881                                 SND_SOC_DAPM_EVENT_ON(event));
882
883         return 0;
884 }
885
886 static int tegra_aic326x_event_hp(struct snd_soc_dapm_widget *w,
887                                         struct snd_kcontrol *k, int event)
888 {
889         struct snd_soc_dapm_context *dapm = w->dapm;
890         struct snd_soc_card *card = dapm->card;
891         struct tegra_aic326x *machine = snd_soc_card_get_drvdata(card);
892         struct tegra_aic326x_platform_data *pdata = machine->pdata;
893
894         if (!(machine->gpio_requested & GPIO_HP_MUTE))
895                 return 0;
896
897         gpio_set_value_cansleep(pdata->gpio_hp_mute,
898                                 !SND_SOC_DAPM_EVENT_ON(event));
899
900         return 0;
901 }
902
903 static const struct snd_soc_dapm_widget tegra_aic326x_dapm_widgets[] = {
904         SND_SOC_DAPM_SPK("Int Spk", tegra_aic326x_event_int_spk),
905         SND_SOC_DAPM_HP("Earpiece", NULL),
906         SND_SOC_DAPM_HP("Headphone Jack", tegra_aic326x_event_hp),
907         SND_SOC_DAPM_MIC("Mic Jack", NULL),
908         SND_SOC_DAPM_INPUT("Ext Mic"),
909         SND_SOC_DAPM_LINE("Linein", NULL),
910         SND_SOC_DAPM_MIC("Int Mic", NULL),
911 };
912
913 static const struct snd_soc_dapm_route aic326x_audio_map[] = {
914         {"Int Spk", NULL, "SPKL"},
915         {"Int Spk", NULL, "SPKR"},
916         {"Earpiece", NULL, "RECP"},
917         {"Earpiece", NULL, "RECM"},
918         {"Headphone Jack", NULL, "HPL"},
919         {"Headphone Jack", NULL, "HPR"},
920         /* internal (IN2L/IN2R) mic is stero */
921         {"Mic Bias Int" ,NULL, "Int Mic"},
922         {"IN2L", NULL, "Mic Bias Int"},
923         {"Mic Bias Int" ,NULL, "Int Mic"},
924         {"IN2R", NULL, "Mic Bias Int"},
925         {"Mic Bias Ext" ,NULL, "Mic Jack"},
926         {"CM1L" ,NULL, "Mic Jack"},
927         {"IN1L", NULL, "Mic Bias Ext"},
928         {"IN1L", NULL, "CM1L"},
929 };
930
931 static const struct snd_kcontrol_new tegra_aic326x_controls[] = {
932         SOC_DAPM_PIN_SWITCH("Int Spk"),
933         SOC_DAPM_PIN_SWITCH("Earpiece"),
934         SOC_DAPM_PIN_SWITCH("Headphone Jack"),
935         SOC_DAPM_PIN_SWITCH("Mic Jack"),
936         SOC_DAPM_PIN_SWITCH("Ext Mic"),
937         SOC_DAPM_PIN_SWITCH("Linein"),
938         SOC_DAPM_PIN_SWITCH("Int Mic"),
939 };
940
941 static int tegra_aic326x_init(struct snd_soc_pcm_runtime *rtd)
942 {
943         struct snd_soc_codec *codec = rtd->codec;
944         struct snd_soc_dapm_context *dapm = &codec->dapm;
945         struct snd_soc_card *card = codec->card;
946         struct tegra_aic326x *machine = snd_soc_card_get_drvdata(card);
947         struct tegra_aic326x_platform_data *pdata = machine->pdata;
948 #ifndef CONFIG_ARCH_TEGRA_2x_SOC
949         struct tegra30_i2s *i2s = snd_soc_dai_get_drvdata(rtd->cpu_dai);
950 #endif
951         int ret;
952
953 #ifndef CONFIG_ARCH_TEGRA_2x_SOC
954         if (machine->codec_info[BASEBAND].i2s_id != -1)
955                 i2s->is_dam_used = true;
956 #endif
957
958         if (machine->init_done)
959                 return 0;
960
961         machine->init_done = true;
962
963 #ifndef CONFIG_ARCH_TEGRA_2x_SOC
964         machine->pcard = card;
965 #endif
966
967         if (machine_is_whistler()) {
968                 machine->audio_reg = regulator_get(NULL, "avddio_audio");
969                 if (IS_ERR(machine->audio_reg)) {
970                         dev_err(card->dev, "cannot get avddio_audio reg\n");
971                         ret = PTR_ERR(machine->audio_reg);
972                         return ret;
973                 }
974
975                 ret = regulator_enable(machine->audio_reg);
976                 if (ret) {
977                         dev_err(card->dev, "cannot enable avddio_audio reg\n");
978                         regulator_put(machine->audio_reg);
979                         machine->audio_reg = NULL;
980                         return ret;
981                 }
982         }
983
984         if (gpio_is_valid(pdata->gpio_spkr_en)) {
985                 ret = gpio_request(pdata->gpio_spkr_en, "spkr_en");
986                 if (ret) {
987                         dev_err(card->dev, "cannot get spkr_en gpio\n");
988                         return ret;
989                 }
990                 machine->gpio_requested |= GPIO_SPKR_EN;
991
992                 gpio_direction_output(pdata->gpio_spkr_en, 0);
993         }
994
995         if (gpio_is_valid(pdata->gpio_hp_mute)) {
996                 ret = gpio_request(pdata->gpio_hp_mute, "hp_mute");
997                 if (ret) {
998                         dev_err(card->dev, "cannot get hp_mute gpio\n");
999                         return ret;
1000                 }
1001                 machine->gpio_requested |= GPIO_HP_MUTE;
1002
1003                 gpio_direction_output(pdata->gpio_hp_mute, 0);
1004         }
1005
1006         if (gpio_is_valid(pdata->gpio_int_mic_en)) {
1007                 ret = gpio_request(pdata->gpio_int_mic_en, "int_mic_en");
1008                 if (ret) {
1009                         dev_err(card->dev, "cannot get int_mic_en gpio\n");
1010                         return ret;
1011                 }
1012                 machine->gpio_requested |= GPIO_INT_MIC_EN;
1013
1014                 /* Disable int mic; enable signal is active-high */
1015                 gpio_direction_output(pdata->gpio_int_mic_en, 0);
1016         }
1017
1018         if (gpio_is_valid(pdata->gpio_ext_mic_en)) {
1019                 ret = gpio_request(pdata->gpio_ext_mic_en, "ext_mic_en");
1020                 if (ret) {
1021                         dev_err(card->dev, "cannot get ext_mic_en gpio\n");
1022                         return ret;
1023                 }
1024                 machine->gpio_requested |= GPIO_EXT_MIC_EN;
1025
1026                 /* Enable ext mic; enable signal is active-low */
1027                 gpio_direction_output(pdata->gpio_ext_mic_en, 0);
1028         }
1029
1030         ret = snd_soc_add_controls(codec, tegra_aic326x_controls,
1031                                    ARRAY_SIZE(tegra_aic326x_controls));
1032         if (ret < 0)
1033                 return ret;
1034
1035         snd_soc_dapm_new_controls(dapm, tegra_aic326x_dapm_widgets,
1036                                         ARRAY_SIZE(tegra_aic326x_dapm_widgets));
1037
1038         snd_soc_dapm_add_routes(dapm, aic326x_audio_map,
1039                                         ARRAY_SIZE(aic326x_audio_map));
1040
1041         ret = snd_soc_jack_new(codec, "Headset Jack", SND_JACK_HEADSET,
1042                         &tegra_aic326x_hp_jack);
1043         if (ret < 0)
1044                 return ret;
1045
1046 #ifdef CONFIG_SWITCH
1047         snd_soc_jack_notifier_register(&tegra_aic326x_hp_jack,
1048                 &aic326x_headset_switch_nb);
1049 #else /*gpio based headset detection*/
1050         snd_soc_jack_add_pins(&tegra_aic326x_hp_jack,
1051                 ARRAY_SIZE(tegra_aic326x_hp_jack_pins),
1052                 tegra_aic326x_hp_jack_pins);
1053 #endif
1054
1055         aic326x_headset_detect(codec, &tegra_aic326x_hp_jack,
1056                 SND_JACK_HEADSET);
1057
1058         /* Add call mode switch control */
1059         ret = snd_ctl_add(codec->card->snd_card,
1060                         snd_ctl_new1(&tegra_aic326x_call_mode_control,
1061                                 machine));
1062         if (ret < 0)
1063                 return ret;
1064
1065         snd_soc_dapm_force_enable_pin(dapm, "MICBIAS_EXT ON");
1066         snd_soc_dapm_force_enable_pin(dapm,"MICBIAS_INT ON");
1067         snd_soc_dapm_sync(dapm);
1068
1069         return 0;
1070 }
1071
1072 static struct snd_soc_dai_link tegra_aic326x_dai[] = {
1073         [DAI_LINK_HIFI] = {
1074                 .name = "AIC3262",
1075                 .stream_name = "AIC3262 PCM HIFI",
1076                 .codec_name = "aic3262-codec.4-0018",
1077                 .platform_name = "tegra-pcm-audio",
1078 #ifdef CONFIG_ARCH_TEGRA_2x_SOC
1079                 .cpu_dai_name = "tegra20-i2s.0",
1080 #else
1081                 .cpu_dai_name = "tegra30-i2s.0",
1082 #endif
1083                 .codec_dai_name = "aic3262-asi1",
1084                 .init = tegra_aic326x_init,
1085                 .ops = &tegra_aic326x_hifi_ops,
1086                 },
1087         [DAI_LINK_SPDIF] = {
1088                 .name = "SPDIF",
1089                 .stream_name = "SPDIF PCM",
1090                 .codec_name = "spdif-dit.0",
1091                 .platform_name = "tegra-pcm-audio",
1092 #ifdef CONFIG_ARCH_TEGRA_2x_SOC
1093                 .cpu_dai_name = "tegra20-spdif",
1094 #else
1095                 .cpu_dai_name = "tegra30-spdif",
1096 #endif
1097                 .codec_dai_name = "dit-hifi",
1098                 .ops = &tegra_aic326x_spdif_ops,
1099                 },
1100         [DAI_LINK_BTSCO] = {
1101                 .name = "BT-SCO",
1102                 .stream_name = "BT SCO PCM",
1103                 .codec_name = "spdif-dit.1",
1104                 .platform_name = "tegra-pcm-audio",
1105 #ifdef CONFIG_ARCH_TEGRA_2x_SOC
1106                 .cpu_dai_name = "tegra20-i2s.1",
1107 #else
1108                 .cpu_dai_name = "tegra30-i2s.3",
1109 #endif
1110                 .codec_dai_name = "dit-hifi",
1111                 .init = tegra_aic326x_init,
1112                 .ops = &tegra_aic326x_bt_ops,
1113                 },
1114         [DAI_LINK_VOICE_CALL] = {
1115                         .name = "VOICE CALL",
1116                         .stream_name = "VOICE CALL PCM",
1117                         .codec_name = "aic3262-codec.4-0018",
1118                         .platform_name = "tegra-pcm-audio",
1119                         .cpu_dai_name = "dit-hifi",
1120                         .codec_dai_name = "aic3262-asi2",
1121                         .ops = &tegra_aic326x_voice_call_ops,
1122                 },
1123         [DAI_LINK_BT_VOICE_CALL] = {
1124                         .name = "BT VOICE CALL",
1125                         .stream_name = "BT VOICE CALL PCM",
1126                         .codec_name = "spdif-dit.2",
1127                         .platform_name = "tegra-pcm-audio",
1128                         .cpu_dai_name = "dit-hifi",
1129                         .codec_dai_name = "dit-hifi",
1130                         .ops = &tegra_aic326x_bt_voice_call_ops,
1131                 },
1132 };
1133
1134 static struct snd_soc_card snd_soc_tegra_aic326x = {
1135         .name = "tegra-aic326x",
1136         .dai_link = tegra_aic326x_dai,
1137         .num_links = ARRAY_SIZE(tegra_aic326x_dai),
1138 };
1139
1140 static __devinit int tegra_aic326x_driver_probe(struct platform_device *pdev)
1141 {
1142         struct snd_soc_card *card = &snd_soc_tegra_aic326x;
1143         struct tegra_aic326x *machine;
1144         struct tegra_aic326x_platform_data *pdata;
1145         int ret, i;
1146
1147         pdata = pdev->dev.platform_data;
1148         if (!pdata) {
1149                 dev_err(&pdev->dev, "No platform data supplied\n");
1150                 return -EINVAL;
1151         }
1152
1153         machine = kzalloc(sizeof(struct tegra_aic326x), GFP_KERNEL);
1154         if (!machine) {
1155                 dev_err(&pdev->dev, "Can't allocate tegra_aic326x struct\n");
1156                 return -ENOMEM;
1157         }
1158
1159         machine->pdata = pdata;
1160
1161         ret = tegra_asoc_utils_init(&machine->util_data, &pdev->dev);
1162         if (ret)
1163                 goto err_free_machine;
1164
1165         card->dev = &pdev->dev;
1166         platform_set_drvdata(pdev, card);
1167         snd_soc_card_set_drvdata(card, machine);
1168
1169 #ifdef CONFIG_SWITCH
1170         /* Add h2w switch class support */
1171         ret = switch_dev_register(&aic326x_wired_switch_dev);
1172         if (ret < 0) {
1173                 dev_err(&pdev->dev, "not able to register switch device %d\n",
1174                         ret);
1175                 goto err_fini_utils;
1176         }
1177 #endif
1178
1179 #ifndef CONFIG_ARCH_TEGRA_2x_SOC
1180         for (i = 0; i < NUM_I2S_DEVICES ; i++)
1181                 machine->codec_info[i].i2s_id = pdata->audio_port_id[i];
1182
1183         machine->codec_info[BASEBAND].rate = pdata->baseband_param.rate;
1184         machine->codec_info[BASEBAND].channels = pdata->baseband_param.channels;
1185
1186         tegra_aic326x_dai[DAI_LINK_HIFI].cpu_dai_name =
1187         tegra_i2s_dai_name[machine->codec_info[HIFI_CODEC].i2s_id];
1188
1189         tegra_aic326x_dai[DAI_LINK_BTSCO].cpu_dai_name =
1190         tegra_i2s_dai_name[machine->codec_info[BT_SCO].i2s_id];
1191 #endif
1192
1193         if(machine_is_tegra_enterprise()) {
1194                 tegra_aic326x_dai[DAI_LINK_HIFI].codec_name = "aic3262-codec.0-0018";
1195                 tegra_aic326x_dai[DAI_LINK_VOICE_CALL].codec_name = "aic3262-codec.0-0018";
1196                 tegra_aic326x_dai[DAI_LINK_VOICE_CALL].codec_dai_name = "aic3262-asi1";
1197         }
1198
1199         ret = snd_soc_register_card(card);
1200         if (ret) {
1201                 dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n",
1202                         ret);
1203                 goto err_switch_unregister;
1204         }
1205
1206         if (!card->instantiated) {
1207                 dev_err(&pdev->dev, "No TI AIC3262 codec\n");
1208                 goto err_unregister_card;
1209         }
1210
1211         return 0;
1212
1213 err_unregister_card:
1214         snd_soc_unregister_card(card);
1215 err_switch_unregister:
1216 #ifdef CONFIG_SWITCH
1217         switch_dev_unregister(&aic326x_wired_switch_dev);
1218 #endif
1219 err_fini_utils:
1220         tegra_asoc_utils_fini(&machine->util_data);
1221 err_free_machine:
1222         kfree(machine);
1223         return ret;
1224 }
1225
1226 static int __devexit tegra_aic326x_driver_remove(struct platform_device *pdev)
1227 {
1228         struct snd_soc_card *card = platform_get_drvdata(pdev);
1229         struct tegra_aic326x *machine = snd_soc_card_get_drvdata(card);
1230         struct tegra_aic326x_platform_data *pdata = machine->pdata;
1231
1232         snd_soc_unregister_card(card);
1233
1234 #ifdef CONFIG_SWITCH
1235         switch_dev_unregister(&aic326x_wired_switch_dev);
1236 #endif
1237
1238         tegra_asoc_utils_fini(&machine->util_data);
1239
1240         if (machine->gpio_requested & GPIO_EXT_MIC_EN)
1241                 gpio_free(pdata->gpio_ext_mic_en);
1242         if (machine->gpio_requested & GPIO_INT_MIC_EN)
1243                 gpio_free(pdata->gpio_int_mic_en);
1244         if (machine->gpio_requested & GPIO_HP_MUTE)
1245                 gpio_free(pdata->gpio_hp_mute);
1246         if (machine->gpio_requested & GPIO_SPKR_EN)
1247                 gpio_free(pdata->gpio_spkr_en);
1248
1249         kfree(machine);
1250
1251         return 0;
1252 }
1253
1254 static struct platform_driver tegra_aic326x_driver = {
1255         .driver = {
1256                 .name = DRV_NAME,
1257                 .owner = THIS_MODULE,
1258                 .pm = &snd_soc_pm_ops,
1259         },
1260         .probe = tegra_aic326x_driver_probe,
1261         .remove = __devexit_p(tegra_aic326x_driver_remove),
1262 };
1263
1264 static int __init tegra_aic326x_modinit(void)
1265 {
1266         return platform_driver_register(&tegra_aic326x_driver);
1267 }
1268 module_init(tegra_aic326x_modinit);
1269
1270 static void __exit tegra_aic326x_modexit(void)
1271 {
1272         platform_driver_unregister(&tegra_aic326x_driver);
1273 }
1274 module_exit(tegra_aic326x_modexit);
1275
1276 /* Module information */
1277 MODULE_AUTHOR("Vinod G. <vinodg@nvidia.com>");
1278 MODULE_DESCRIPTION("Tegra+AIC3262 machine ASoC driver");
1279 MODULE_DESCRIPTION("Tegra ALSA SoC");
1280 MODULE_LICENSE("GPL");
1281