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