asoc:tegra: correct the codec name and its dai
[linux-2.6.git] / sound / soc / tegra / tegra_rt5640.c
1 /*
2  * tegra_rt5640.c - Tegra machine ASoC driver for boards using ALC5640 codec.
3  *
4  * Author: Johnny Qiu <joqiu@nvidia.com>
5  * Copyright (c) 2011-2013, NVIDIA CORPORATION.  All rights reserved.
6  *
7  * Based on code copyright/by:
8  *
9  * Copyright 2007 Wolfson Microelectronics PLC.
10  * Author: Graeme Gregory
11  *         graeme.gregory@wolfsonmicro.com or linux@wolfsonmicro.com
12  *
13  * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved.
14  * This program is free software; you can redistribute it and/or
15  * modify it under the terms of the GNU General Public License
16  * version 2 as published by the Free Software Foundation.
17  *
18  * This program is distributed in the hope that it will be useful, but
19  * WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21  * General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
26  * 02110-1301 USA
27  *
28  */
29
30 #include <asm/mach-types.h>
31
32 #include <linux/clk.h>
33 #include <linux/module.h>
34 #include <linux/platform_device.h>
35 #include <linux/slab.h>
36 #include <linux/gpio.h>
37 #include <linux/regulator/consumer.h>
38 #include <linux/delay.h>
39 #include <linux/edp.h>
40 #ifdef CONFIG_SWITCH
41 #include <linux/switch.h>
42 #endif
43 #include <mach/tegra_asoc_pdata.h>
44 #include <mach/gpio-tegra.h>
45 #include <mach/tegra_rt5640_pdata.h>
46
47 #include <sound/core.h>
48 #include <sound/jack.h>
49 #include <sound/pcm.h>
50 #include <sound/pcm_params.h>
51 #include <sound/soc.h>
52 #include "../codecs/rt5639.h"
53 #include "../codecs/rt5640.h"
54
55 #include "tegra_pcm.h"
56 #include "tegra_asoc_utils.h"
57 #include <linux/tfa9887.h>
58 #include "tegra30_ahub.h"
59 #include "tegra30_i2s.h"
60 #include "tegra30_dam.h"
61
62 #define DRV_NAME "tegra-snd-rt5640"
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 #define GPIO_HP_DET     BIT(4)
69
70 #define DAI_LINK_HIFI           0
71 #define DAI_LINK_SPDIF          1
72 #define DAI_LINK_BTSCO          2
73 #define DAI_LINK_VOICE_CALL     3
74 #define DAI_LINK_BT_VOICE_CALL  4
75 #define NUM_DAI_LINKS   5
76
77 struct tegra30_i2s *i2s_tfa = NULL;
78 struct snd_soc_codec *codec_rt;
79 const char *tegra_rt5640_i2s_dai_name[TEGRA30_NR_I2S_IFC] = {
80         "tegra30-i2s.0",
81         "tegra30-i2s.1",
82         "tegra30-i2s.2",
83         "tegra30-i2s.3",
84         "tegra30-i2s.4",
85 };
86
87 extern int g_is_call_mode;
88
89 struct tegra_rt5640 {
90         struct tegra_asoc_utils_data util_data;
91         struct tegra_asoc_platform_data *pdata;
92         struct regulator *spk_reg;
93         bool init_done;
94         int is_call_mode;
95         int is_device_bt;
96 #ifndef CONFIG_ARCH_TEGRA_2x_SOC
97         struct codec_config codec_info[NUM_I2S_DEVICES];
98 #endif
99         struct regulator *dmic_reg;
100         struct regulator *cdc_en;
101         struct snd_soc_card *pcard;
102         struct edp_client *spk_edp_client;
103         int gpio_requested;
104 #ifdef CONFIG_SWITCH
105         int jack_status;
106 #endif
107         enum snd_soc_bias_level bias_level;
108         volatile int clock_enabled;
109 };
110
111 static int tegra_call_mode_info(struct snd_kcontrol *kcontrol,
112                         struct snd_ctl_elem_info *uinfo)
113 {
114         uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
115         uinfo->count = 1;
116         uinfo->value.integer.min = 0;
117         uinfo->value.integer.max = 1;
118         return 0;
119 }
120
121 static int tegra_call_mode_get(struct snd_kcontrol *kcontrol,
122                 struct snd_ctl_elem_value *ucontrol)
123 {
124         struct tegra_rt5640 *machine = snd_kcontrol_chip(kcontrol);
125
126         ucontrol->value.integer.value[0] = machine->is_call_mode;
127
128         return 0;
129 }
130
131 static int tegra_call_mode_put(struct snd_kcontrol *kcontrol,
132                 struct snd_ctl_elem_value *ucontrol)
133 {
134         struct tegra_rt5640 *machine = snd_kcontrol_chip(kcontrol);
135         int is_call_mode_new = ucontrol->value.integer.value[0];
136         int codec_index;
137         unsigned int i;
138         int uses_voice_codec;
139
140         if (machine->is_call_mode == is_call_mode_new)
141                 return 0;
142         if (machine->is_device_bt) {
143                 codec_index = BT_SCO;
144                 uses_voice_codec = 0;
145         } else {
146                 codec_index = VOICE_CODEC;
147                 uses_voice_codec = 0;
148         }
149
150         if (is_call_mode_new) {
151                 if (machine->codec_info[codec_index].rate == 0 ||
152                         machine->codec_info[codec_index].channels == 0)
153                                 return -EINVAL;
154
155                 for (i = 0; i < machine->pcard->num_links; i++)
156                         machine->pcard->dai_link[i].ignore_suspend = 1;
157
158                 tegra30_make_voice_call_connections(
159                         &machine->codec_info[codec_index],
160                         &machine->codec_info[BASEBAND], uses_voice_codec);
161         } else {
162                 tegra30_break_voice_call_connections(
163                         &machine->codec_info[codec_index],
164                         &machine->codec_info[BASEBAND], uses_voice_codec);
165
166                 for (i = 0; i < machine->pcard->num_links; i++)
167                         machine->pcard->dai_link[i].ignore_suspend = 0;
168         }
169
170         machine->is_call_mode = is_call_mode_new;
171         g_is_call_mode = machine->is_call_mode;
172
173         return 1;
174 }
175
176 struct snd_kcontrol_new tegra_rt5640_call_mode_control = {
177         .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
178         .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
179         .name = "Call Mode Switch",
180         .private_value = 0xffff,
181         .info = tegra_call_mode_info,
182         .get = tegra_call_mode_get,
183         .put = tegra_call_mode_put
184 };
185
186 #ifndef CONFIG_ARCH_TEGRA_2x_SOC
187 static int tegra_rt5640_set_dam_cif(int dam_ifc, int srate,
188                         int channels, int bit_size, int src_on, int src_srate,
189                         int src_channels, int src_bit_size)
190 {
191         tegra30_dam_set_gain(dam_ifc, TEGRA30_DAM_CHIN1, 0x1000);
192         tegra30_dam_set_samplerate(dam_ifc, TEGRA30_DAM_CHOUT,
193                                 srate);
194         tegra30_dam_set_samplerate(dam_ifc, TEGRA30_DAM_CHIN1,
195                                 srate);
196 #ifndef CONFIG_ARCH_TEGRA_3x_SOC
197         tegra30_dam_set_acif(dam_ifc, TEGRA30_DAM_CHIN1,
198                 channels, bit_size, channels,
199                                 32);
200         tegra30_dam_set_acif(dam_ifc, TEGRA30_DAM_CHOUT,
201                 channels, bit_size, channels,
202                                 32);
203 #else
204         tegra30_dam_set_acif(dam_ifc, TEGRA30_DAM_CHIN1,
205                 channels, bit_size, channels,
206                                 bit_size);
207         tegra30_dam_set_acif(dam_ifc, TEGRA30_DAM_CHOUT,
208                 channels, bit_size, channels,
209                                 bit_size);
210 #endif
211
212         tegra30_dam_set_gain(dam_ifc, TEGRA30_DAM_CHIN0_SRC, 0x1000);
213         if (src_on) {
214                 tegra30_dam_set_samplerate(dam_ifc, TEGRA30_DAM_CHIN0_SRC,
215                         src_srate);
216 #ifndef CONFIG_ARCH_TEGRA_3x_SOC
217                 tegra30_dam_set_acif(dam_ifc, TEGRA30_DAM_CHIN0_SRC,
218                         src_channels, src_bit_size, 1, 32);
219 #else
220                 tegra30_dam_set_acif(dam_ifc, TEGRA30_DAM_CHIN0_SRC,
221                         src_channels, src_bit_size, 1, 16);
222 #endif
223         }
224
225         return 0;
226 }
227 #endif
228
229 void tegra_asoc_enable_clocks(void);
230 void tegra_asoc_disable_clocks(void);
231
232 static int tegra_rt5640_hw_params(struct snd_pcm_substream *substream,
233                                         struct snd_pcm_hw_params *params)
234 {
235         struct snd_soc_pcm_runtime *rtd = substream->private_data;
236         struct snd_soc_dai *codec_dai = rtd->codec_dai;
237         struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
238         struct snd_soc_codec *codec = rtd->codec;
239         struct snd_soc_card *card = codec->card;
240         struct tegra_rt5640 *machine = snd_soc_card_get_drvdata(card);
241         struct tegra_asoc_platform_data *pdata = machine->pdata;
242         struct tegra30_i2s *i2s = snd_soc_dai_get_drvdata(cpu_dai);
243         int srate, mclk, sample_size, i2s_daifmt;
244         int err, rate;
245         static unsigned initTfa = 0;
246
247         switch (params_format(params)) {
248         case SNDRV_PCM_FORMAT_S16_LE:
249                 sample_size = 16;
250                 break;
251         case SNDRV_PCM_FORMAT_S24_LE:
252                 sample_size = 24;
253                 break;
254         default:
255                 return -EINVAL;
256         }
257         srate = params_rate(params);
258         mclk = 256 * srate;
259
260         i2s_daifmt = SND_SOC_DAIFMT_NB_NF;
261         i2s_daifmt |= pdata->i2s_param[HIFI_CODEC].is_i2s_master ?
262                         SND_SOC_DAIFMT_CBS_CFS : SND_SOC_DAIFMT_CBM_CFM;
263
264         switch (pdata->i2s_param[HIFI_CODEC].i2s_mode) {
265                 case TEGRA_DAIFMT_I2S :
266                         i2s_daifmt |= SND_SOC_DAIFMT_I2S;
267                         break;
268                 case TEGRA_DAIFMT_DSP_A :
269                         i2s_daifmt |= SND_SOC_DAIFMT_DSP_A;
270                         break;
271                 case TEGRA_DAIFMT_DSP_B :
272                         i2s_daifmt |= SND_SOC_DAIFMT_DSP_B;
273                         break;
274                 case TEGRA_DAIFMT_LEFT_J :
275                         i2s_daifmt |= SND_SOC_DAIFMT_LEFT_J;
276                         break;
277                 case TEGRA_DAIFMT_RIGHT_J :
278                         i2s_daifmt |= SND_SOC_DAIFMT_RIGHT_J;
279                         break;
280                 default :
281                         dev_err(card->dev, "Can't configure i2s format\n");
282                         return -EINVAL;
283         }
284
285         err = tegra_asoc_utils_set_rate(&machine->util_data, srate, mclk);
286         if (err < 0) {
287                 if (!(machine->util_data.set_mclk % mclk)) {
288                         mclk = machine->util_data.set_mclk;
289                 } else {
290                         dev_err(card->dev, "Can't configure clocks\n");
291                         return err;
292                 }
293         }
294
295         tegra_asoc_utils_lock_clk_rate(&machine->util_data, 1);
296
297         rate = clk_get_rate(machine->util_data.clk_cdev1);
298
299         err = snd_soc_dai_set_fmt(codec_dai, i2s_daifmt);
300         if (err < 0) {
301                 dev_err(card->dev, "codec_dai fmt not set\n");
302                 return err;
303         }
304
305         err = snd_soc_dai_set_fmt(cpu_dai, i2s_daifmt);
306         if (err < 0) {
307                 dev_err(card->dev, "cpu_dai fmt not set\n");
308                 return err;
309         }
310
311         if (pdata->i2s_param[HIFI_CODEC].is_i2s_master) {
312                 err = snd_soc_dai_set_sysclk(codec_dai, 0, rate,
313                                 SND_SOC_CLOCK_IN);
314                 if (err < 0) {
315                         dev_err(card->dev, "codec_dai clock not set\n");
316                         return err;
317                 }
318         } else {
319                 err = snd_soc_dai_set_pll(codec_dai, RT5640_SCLK_S_PLL1,
320                                 RT5640_PLL1_S_MCLK, rate, 512 * srate);
321                 if (err < 0) {
322                         dev_err(card->dev, "codec_dai pll not set\n");
323                         return err;
324                 }
325
326                 err = snd_soc_dai_set_sysclk(codec_dai, RT5640_SCLK_S_PLL1,
327                                 512 * srate, SND_SOC_CLOCK_IN);
328                 if (err < 0) {
329                         dev_err(card->dev, "codec_dai clock not set\n");
330                         return err;
331                 }
332         }
333
334         if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK && i2s->is_dam_used)
335                 tegra_rt5640_set_dam_cif(i2s->dam_ifc, srate,
336                         params_channels(params), sample_size, 0, 0, 0, 0);
337
338         if(machine_is_roth()) {
339                 if(initTfa == 1) {
340                         i2s_tfa = i2s;
341                         tegra_asoc_enable_clocks();
342                         pr_info("INIT TFA\n");
343                         Tfa9887_Init(srate);
344                         tegra_asoc_disable_clocks();
345                 }
346                 initTfa++;
347         }
348         return 0;
349 }
350
351 static int tegra_bt_sco_hw_params(struct snd_pcm_substream *substream,
352                                         struct snd_pcm_hw_params *params)
353 {
354         struct snd_soc_pcm_runtime *rtd = substream->private_data;
355         struct snd_soc_card *card = rtd->card;
356         struct tegra_rt5640 *machine = snd_soc_card_get_drvdata(card);
357         struct tegra_asoc_platform_data *pdata = machine->pdata;
358         int srate, mclk, min_mclk, i2s_daifmt;
359         int err;
360
361         srate = params_rate(params);
362         switch (srate) {
363         case 11025:
364         case 22050:
365         case 44100:
366         case 88200:
367                 mclk = 11289600;
368                 break;
369         case 8000:
370         case 16000:
371         case 32000:
372         case 48000:
373         case 64000:
374         case 96000:
375                 mclk = 12288000;
376                 break;
377         default:
378                 return -EINVAL;
379         }
380         min_mclk = 64 * srate;
381
382         err = tegra_asoc_utils_set_rate(&machine->util_data, srate, mclk);
383         if (err < 0) {
384                 if (!(machine->util_data.set_mclk % min_mclk))
385                         mclk = machine->util_data.set_mclk;
386                 else {
387                         dev_err(card->dev, "Can't configure clocks\n");
388                         return err;
389                 }
390         }
391
392         tegra_asoc_utils_lock_clk_rate(&machine->util_data, 1);
393
394         i2s_daifmt = SND_SOC_DAIFMT_NB_NF;
395         i2s_daifmt |= pdata->i2s_param[BT_SCO].is_i2s_master ?
396                         SND_SOC_DAIFMT_CBS_CFS : SND_SOC_DAIFMT_CBM_CFM;
397
398         switch (pdata->i2s_param[BT_SCO].i2s_mode) {
399                 case TEGRA_DAIFMT_I2S :
400                         i2s_daifmt |= SND_SOC_DAIFMT_I2S;
401                         break;
402                 case TEGRA_DAIFMT_DSP_A :
403                         i2s_daifmt |= SND_SOC_DAIFMT_DSP_A;
404                         break;
405                 case TEGRA_DAIFMT_DSP_B :
406                         i2s_daifmt |= SND_SOC_DAIFMT_DSP_B;
407                         break;
408                 case TEGRA_DAIFMT_LEFT_J :
409                         i2s_daifmt |= SND_SOC_DAIFMT_LEFT_J;
410                         break;
411                 case TEGRA_DAIFMT_RIGHT_J :
412                         i2s_daifmt |= SND_SOC_DAIFMT_RIGHT_J;
413                         break;
414                 default :
415                         dev_err(card->dev, "Can't configure i2s format\n");
416                         return -EINVAL;
417         }
418
419         err = snd_soc_dai_set_fmt(rtd->cpu_dai, i2s_daifmt);
420         if (err < 0) {
421                 dev_err(card->dev, "cpu_dai fmt not set\n");
422                 return err;
423         }
424
425         return 0;
426 }
427
428 static int tegra_spdif_hw_params(struct snd_pcm_substream *substream,
429                                         struct snd_pcm_hw_params *params)
430 {
431         struct snd_soc_pcm_runtime *rtd = substream->private_data;
432         struct snd_soc_card *card = rtd->card;
433         struct tegra_rt5640 *machine = snd_soc_card_get_drvdata(card);
434         int srate, mclk, min_mclk;
435         int err;
436
437         srate = params_rate(params);
438         switch (srate) {
439         case 11025:
440         case 22050:
441         case 44100:
442         case 88200:
443                 mclk = 11289600;
444                 break;
445         case 8000:
446         case 16000:
447         case 32000:
448         case 48000:
449         case 64000:
450         case 96000:
451                 mclk = 12288000;
452                 break;
453         default:
454                 return -EINVAL;
455         }
456         min_mclk = 128 * srate;
457
458         err = tegra_asoc_utils_set_rate(&machine->util_data, srate, mclk);
459         if (err < 0) {
460                 if (!(machine->util_data.set_mclk % min_mclk))
461                         mclk = machine->util_data.set_mclk;
462                 else {
463                         dev_err(card->dev, "Can't configure clocks\n");
464                         return err;
465                 }
466         }
467
468         tegra_asoc_utils_lock_clk_rate(&machine->util_data, 1);
469
470         return 0;
471 }
472
473 static int tegra_hw_free(struct snd_pcm_substream *substream)
474 {
475         struct snd_soc_pcm_runtime *rtd = substream->private_data;
476         struct tegra_rt5640 *machine = snd_soc_card_get_drvdata(rtd->card);
477
478         tegra_asoc_utils_lock_clk_rate(&machine->util_data, 0);
479
480         return 0;
481 }
482 #ifndef CONFIG_ARCH_TEGRA_2x_SOC
483 static int tegra_rt5640_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_rt5640 *machine = snd_soc_card_get_drvdata(rtd->card);
489         struct codec_config *codec_info;
490         struct codec_config *bb_info;
491         struct codec_config *hifi_info;
492         int codec_index;
493
494         if (!i2s->is_dam_used)
495                 return 0;
496
497         if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
498                 /*dam configuration*/
499                 if (!i2s->dam_ch_refcount)
500                         i2s->dam_ifc = tegra30_dam_allocate_controller();
501                 if (i2s->dam_ifc < 0)
502                         return i2s->dam_ifc;
503                 tegra30_dam_allocate_channel(i2s->dam_ifc, TEGRA30_DAM_CHIN1);
504                 i2s->dam_ch_refcount++;
505                 tegra30_dam_enable_clock(i2s->dam_ifc);
506
507                 tegra30_ahub_set_rx_cif_source(TEGRA30_AHUB_RXCIF_DAM0_RX1 +
508                                 (i2s->dam_ifc*2), i2s->txcif);
509
510                 /*
511                 *make the dam tx to i2s rx connection if this is the only client
512                 *using i2s for playback
513                 */
514                 if (i2s->playback_ref_count == 1)
515                         tegra30_ahub_set_rx_cif_source(
516                                 TEGRA30_AHUB_RXCIF_I2S0_RX0 + i2s->id,
517                                 TEGRA30_AHUB_TXCIF_DAM0_TX0 + i2s->dam_ifc);
518
519                 /* enable the dam*/
520                 tegra30_dam_enable(i2s->dam_ifc, TEGRA30_DAM_ENABLE,
521                                 TEGRA30_DAM_CHIN1);
522         } else {
523                 i2s->is_call_mode_rec = machine->is_call_mode;
524
525                 if (!i2s->is_call_mode_rec)
526                         return 0;
527
528                 if (machine->is_device_bt)
529                         codec_index = BT_SCO;
530                 else
531                         codec_index = VOICE_CODEC;
532
533                 codec_info = &machine->codec_info[codec_index];
534                 bb_info = &machine->codec_info[BASEBAND];
535                 hifi_info = &machine->codec_info[HIFI_CODEC];
536
537                 /* allocate a dam for voice call recording */
538
539                 i2s->call_record_dam_ifc = tegra30_dam_allocate_controller();
540
541                 if (i2s->call_record_dam_ifc < 0)
542                         return i2s->call_record_dam_ifc;
543
544                 tegra30_dam_allocate_channel(i2s->call_record_dam_ifc,
545                         TEGRA30_DAM_CHIN0_SRC);
546                 tegra30_dam_allocate_channel(i2s->call_record_dam_ifc,
547                         TEGRA30_DAM_CHIN1);
548                 tegra30_dam_enable_clock(i2s->call_record_dam_ifc);
549
550                 /* configure the dam */
551                 tegra_rt5640_set_dam_cif(i2s->call_record_dam_ifc,
552                         codec_info->rate, codec_info->channels,
553                         codec_info->bitsize, 1, bb_info->rate,
554                         bb_info->channels, bb_info->bitsize);
555
556                 /* setup the connections for voice call record */
557                 tegra30_ahub_unset_rx_cif_source(i2s->rxcif);
558                 tegra30_ahub_set_rx_cif_source(TEGRA30_AHUB_RXCIF_DAM0_RX0 +
559                         (i2s->call_record_dam_ifc*2),
560                         TEGRA30_AHUB_TXCIF_I2S0_TX0 + bb_info->i2s_id);
561                 tegra30_ahub_set_rx_cif_source(TEGRA30_AHUB_RXCIF_DAM0_RX1 +
562                         (i2s->call_record_dam_ifc*2),
563                         TEGRA30_AHUB_TXCIF_I2S0_TX0 + codec_info->i2s_id);
564                 tegra30_ahub_set_rx_cif_source(i2s->rxcif,
565                         TEGRA30_AHUB_TXCIF_DAM0_TX0 + i2s->call_record_dam_ifc);
566
567                 /* enable the dam*/
568
569                 tegra30_dam_enable(i2s->call_record_dam_ifc, TEGRA30_DAM_ENABLE,
570                                 TEGRA30_DAM_CHIN1);
571                 tegra30_dam_enable(i2s->call_record_dam_ifc, TEGRA30_DAM_ENABLE,
572                                 TEGRA30_DAM_CHIN0_SRC);
573         }
574
575         return 0;
576 }
577
578 static void tegra_rt5640_shutdown(struct snd_pcm_substream *substream)
579 {
580         struct snd_soc_pcm_runtime *rtd = substream->private_data;
581         struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
582         struct tegra30_i2s *i2s = snd_soc_dai_get_drvdata(cpu_dai);
583
584         if (!i2s->is_dam_used)
585                 return;
586
587         if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
588                 /* disable the dam*/
589                 tegra30_dam_enable(i2s->dam_ifc, TEGRA30_DAM_DISABLE,
590                                 TEGRA30_DAM_CHIN1);
591
592                 /* disconnect the ahub connections*/
593                 tegra30_ahub_unset_rx_cif_source(TEGRA30_AHUB_RXCIF_DAM0_RX1 +
594                                         (i2s->dam_ifc*2));
595
596                 /* disable the dam and free the controller */
597                 tegra30_dam_disable_clock(i2s->dam_ifc);
598                 tegra30_dam_free_channel(i2s->dam_ifc, TEGRA30_DAM_CHIN1);
599                 i2s->dam_ch_refcount--;
600                 if (!i2s->dam_ch_refcount)
601                         tegra30_dam_free_controller(i2s->dam_ifc);
602          } else {
603                 if (!i2s->is_call_mode_rec)
604                         return;
605
606                 i2s->is_call_mode_rec = 0;
607
608                 /* disable the dam*/
609                 tegra30_dam_enable(i2s->call_record_dam_ifc,
610                         TEGRA30_DAM_DISABLE, TEGRA30_DAM_CHIN1);
611                 tegra30_dam_enable(i2s->call_record_dam_ifc,
612                         TEGRA30_DAM_DISABLE, TEGRA30_DAM_CHIN0_SRC);
613
614                 /* disconnect the ahub connections*/
615                 tegra30_ahub_unset_rx_cif_source(i2s->rxcif);
616                 tegra30_ahub_unset_rx_cif_source(TEGRA30_AHUB_RXCIF_DAM0_RX0 +
617                         (i2s->call_record_dam_ifc*2));
618                 tegra30_ahub_unset_rx_cif_source(TEGRA30_AHUB_RXCIF_DAM0_RX1 +
619                         (i2s->call_record_dam_ifc*2));
620
621                 /* free the dam channels and dam controller */
622                 tegra30_dam_disable_clock(i2s->call_record_dam_ifc);
623                 tegra30_dam_free_channel(i2s->call_record_dam_ifc,
624                         TEGRA30_DAM_CHIN1);
625                 tegra30_dam_free_channel(i2s->call_record_dam_ifc,
626                         TEGRA30_DAM_CHIN0_SRC);
627                 tegra30_dam_free_controller(i2s->call_record_dam_ifc);
628          }
629
630         return;
631 }
632 #endif
633
634 static int tegra_voice_call_hw_params(struct snd_pcm_substream *substream,
635                         struct snd_pcm_hw_params *params)
636 {
637         struct snd_soc_pcm_runtime *rtd = substream->private_data;
638         struct snd_soc_dai *codec_dai = rtd->codec_dai;
639         struct snd_soc_codec *codec = rtd->codec;
640         struct snd_soc_card *card = codec->card;
641         struct tegra_rt5640 *machine = snd_soc_card_get_drvdata(card);
642         struct tegra_asoc_platform_data *pdata = machine->pdata;
643         int srate, mclk, i2s_daifmt;
644         int err, rate;
645
646         srate = params_rate(params);
647         switch (srate) {
648         case 8000:
649         case 16000:
650         case 24000:
651         case 32000:
652         case 48000:
653         case 64000:
654         case 96000:
655                 mclk = 12288000;
656                 break;
657         case 11025:
658         case 22050:
659         case 44100:
660         case 88200:
661                 mclk = 11289600;
662                 break;
663         default:
664                 return -EINVAL;
665                 break;
666         }
667
668         i2s_daifmt = SND_SOC_DAIFMT_NB_NF;
669         i2s_daifmt |= pdata->i2s_param[VOICE_CODEC].is_i2s_master ?
670                         SND_SOC_DAIFMT_CBS_CFS : SND_SOC_DAIFMT_CBM_CFM;
671
672         switch (pdata->i2s_param[VOICE_CODEC].i2s_mode) {
673         case TEGRA_DAIFMT_I2S:
674                 i2s_daifmt |= SND_SOC_DAIFMT_I2S;
675                 break;
676         case TEGRA_DAIFMT_DSP_A:
677                 i2s_daifmt |= SND_SOC_DAIFMT_DSP_A;
678                 break;
679         case TEGRA_DAIFMT_DSP_B:
680                 i2s_daifmt |= SND_SOC_DAIFMT_DSP_B;
681                 break;
682         case TEGRA_DAIFMT_LEFT_J:
683                 i2s_daifmt |= SND_SOC_DAIFMT_LEFT_J;
684                 break;
685         case TEGRA_DAIFMT_RIGHT_J:
686                 i2s_daifmt |= SND_SOC_DAIFMT_RIGHT_J;
687                 break;
688         default:
689                 dev_err(card->dev, "Can't configure i2s format\n");
690                 return -EINVAL;
691         }
692
693         err = tegra_asoc_utils_set_rate(&machine->util_data, srate, mclk);
694         if (err < 0) {
695                 if (!(machine->util_data.set_mclk % mclk))
696                         mclk = machine->util_data.set_mclk;
697                 else {
698                         dev_err(card->dev, "Can't configure clocks\n");
699                         return err;
700                 }
701         }
702
703         tegra_asoc_utils_lock_clk_rate(&machine->util_data, 1);
704
705         rate = clk_get_rate(machine->util_data.clk_cdev1);
706
707         err = snd_soc_dai_set_fmt(codec_dai, i2s_daifmt);
708         if (err < 0) {
709                 dev_err(card->dev, "codec_dai fmt not set\n");
710                 return err;
711         }
712 /*
713         err = snd_soc_dai_set_fmt(cpu_dai, i2s_daifmt);
714         if (err < 0) {
715                 dev_err(card->dev, "cpu_dai fmt not set\n");
716                 return err;
717         }
718 */
719         err = snd_soc_dai_set_sysclk(codec_dai, 0, rate, SND_SOC_CLOCK_IN);
720         if (err < 0) {
721                 dev_err(card->dev, "codec_dai clock not set\n");
722                 return err;
723         }
724
725 #ifndef CONFIG_ARCH_TEGRA_2x_SOC
726         /* codec configuration */
727         machine->codec_info[VOICE_CODEC].rate = params_rate(params);
728         machine->codec_info[VOICE_CODEC].channels = params_channels(params);
729 #endif
730
731         machine->is_device_bt = 0;
732
733         return 0;
734 }
735
736 static void tegra_voice_call_shutdown(struct snd_pcm_substream *substream)
737 {
738         struct snd_soc_pcm_runtime *rtd = substream->private_data;
739         struct tegra_rt5640 *machine  =
740                         snd_soc_card_get_drvdata(rtd->codec->card);
741
742 #ifndef CONFIG_ARCH_TEGRA_2x_SOC
743         machine->codec_info[VOICE_CODEC].rate = 0;
744         machine->codec_info[VOICE_CODEC].channels = 0;
745 #endif
746         machine->is_device_bt = 0;
747         return;
748 }
749
750 static int tegra_bt_voice_call_hw_params(struct snd_pcm_substream *substream,
751                         struct snd_pcm_hw_params *params)
752 {
753         struct snd_soc_pcm_runtime *rtd = substream->private_data;
754         struct snd_soc_card *card = rtd->card;
755         struct tegra_rt5640 *machine = snd_soc_card_get_drvdata(card);
756         int err, srate, mclk, min_mclk;
757
758         srate = params_rate(params);
759         switch (srate) {
760         case 11025:
761         case 22050:
762         case 44100:
763         case 88200:
764                 mclk = 11289600;
765                 break;
766         case 8000:
767         case 16000:
768         case 32000:
769         case 48000:
770         case 64000:
771         case 96000:
772                 mclk = 12288000;
773                 break;
774         default:
775                 return -EINVAL;
776         }
777         min_mclk = 64 * srate;
778
779         err = tegra_asoc_utils_set_rate(&machine->util_data, srate, mclk);
780         if (err < 0) {
781                 if (!(machine->util_data.set_mclk % min_mclk))
782                         mclk = machine->util_data.set_mclk;
783                 else {
784                         dev_err(card->dev, "Can't configure clocks\n");
785                         return err;
786                 }
787         }
788
789         tegra_asoc_utils_lock_clk_rate(&machine->util_data, 1);
790
791 #ifndef CONFIG_ARCH_TEGRA_2x_SOC
792         /* codec configuration */
793         machine->codec_info[BT_SCO].rate = params_rate(params);
794         machine->codec_info[BT_SCO].channels = params_channels(params);
795 #endif
796
797         machine->is_device_bt = 1;
798
799         return 0;
800 }
801
802 static void tegra_bt_voice_call_shutdown(struct snd_pcm_substream *substream)
803 {
804         struct snd_soc_pcm_runtime *rtd = substream->private_data;
805         struct tegra_rt5640 *machine  =
806                         snd_soc_card_get_drvdata(rtd->codec->card);
807
808 #ifndef CONFIG_ARCH_TEGRA_2x_SOC
809         machine->codec_info[BT_SCO].rate = 0;
810         machine->codec_info[BT_SCO].channels = 0;
811 #endif
812
813         machine->is_device_bt = 0;
814 }
815 static struct snd_soc_ops tegra_rt5640_ops = {
816         .hw_params = tegra_rt5640_hw_params,
817         .hw_free = tegra_hw_free,
818 #ifndef CONFIG_ARCH_TEGRA_2x_SOC
819         .startup = tegra_rt5640_startup,
820         .shutdown = tegra_rt5640_shutdown,
821 #endif
822 };
823
824 static struct snd_soc_ops tegra_rt5640_bt_sco_ops = {
825         .hw_params = tegra_bt_sco_hw_params,
826         .hw_free = tegra_hw_free,
827 #ifndef CONFIG_ARCH_TEGRA_2x_SOC
828         .startup = tegra_rt5640_startup,
829         .shutdown = tegra_rt5640_shutdown,
830 #endif
831 };
832
833 static struct snd_soc_ops tegra_spdif_ops = {
834         .hw_params = tegra_spdif_hw_params,
835         .hw_free = tegra_hw_free,
836 };
837
838 static struct snd_soc_ops tegra_voice_call_ops = {
839         .hw_params = tegra_voice_call_hw_params,
840         .shutdown = tegra_voice_call_shutdown,
841         .hw_free = tegra_hw_free,
842 };
843
844 static struct snd_soc_ops tegra_bt_voice_call_ops = {
845         .hw_params = tegra_bt_voice_call_hw_params,
846         .shutdown = tegra_bt_voice_call_shutdown,
847         .hw_free = tegra_hw_free,
848 };
849
850 static struct snd_soc_jack tegra_rt5640_hp_jack;
851
852 static struct snd_soc_jack_gpio tegra_rt5640_hp_jack_gpio = {
853         .name = "headphone detect",
854         .report = SND_JACK_HEADPHONE,
855         .debounce_time = 150,
856         .invert = 1,
857 };
858
859 #ifdef CONFIG_SWITCH
860 /* These values are copied from Android WiredAccessoryObserver */
861 enum headset_state {
862         BIT_NO_HEADSET = 0,
863         BIT_HEADSET = (1 << 0),
864         BIT_HEADSET_NO_MIC = (1 << 1),
865 };
866
867 static struct switch_dev tegra_rt5640_headset_switch = {
868         .name = "h2w",
869 };
870
871 static int tegra_rt5640_jack_notifier(struct notifier_block *self,
872                               unsigned long action, void *dev)
873 {
874         struct snd_soc_jack *jack = dev;
875         struct snd_soc_codec *codec = jack->codec;
876         struct snd_soc_card *card = codec->card;
877         struct tegra_rt5640 *machine = snd_soc_card_get_drvdata(card);
878         struct tegra_asoc_platform_data *pdata = machine->pdata;
879         enum headset_state state = BIT_NO_HEADSET;
880         unsigned char status_jack = 0;
881
882         if (jack == &tegra_rt5640_hp_jack) {
883                 if (action) {
884                         /* Enable ext mic; enable signal is active-low */
885                         if (gpio_is_valid(pdata->gpio_ext_mic_en))
886                                 gpio_direction_output(pdata->gpio_ext_mic_en, 0);
887                         if (!strncmp(machine->pdata->codec_name, "rt5639", 6))
888                                 status_jack = rt5639_headset_detect(codec, 1);
889                         else if (!strncmp(machine->pdata->codec_name, "rt5640",
890                                                                             6))
891                                 status_jack = rt5640_headset_detect(codec, 1);
892
893                         machine->jack_status &= ~SND_JACK_HEADPHONE;
894                         machine->jack_status &= ~SND_JACK_MICROPHONE;
895                         if (status_jack == RT5639_HEADPHO_DET ||
896                             status_jack == RT5640_HEADPHO_DET)
897                                         machine->jack_status |=
898                                                         SND_JACK_HEADPHONE;
899                         else if (status_jack == RT5639_HEADSET_DET ||
900                                  status_jack == RT5640_HEADSET_DET) {
901                                         machine->jack_status |=
902                                                         SND_JACK_HEADPHONE;
903                                         machine->jack_status |=
904                                                         SND_JACK_MICROPHONE;
905                         }
906                 } else {
907                         /* Disable ext mic; enable signal is active-low */
908                         if (gpio_is_valid(pdata->gpio_ext_mic_en))
909                                 gpio_direction_output(pdata->gpio_ext_mic_en, 1);
910                         if (!strncmp(machine->pdata->codec_name, "rt5639", 6))
911                                 rt5639_headset_detect(codec, 0);
912                         else if (!strncmp(machine->pdata->codec_name, "rt5640",
913                                                                             6))
914                                 rt5640_headset_detect(codec, 0);
915
916                         machine->jack_status &= ~SND_JACK_HEADPHONE;
917                         machine->jack_status &= ~SND_JACK_MICROPHONE;
918                 }
919         }
920
921         switch (machine->jack_status) {
922         case SND_JACK_HEADPHONE:
923                 state = BIT_HEADSET_NO_MIC;
924                 break;
925         case SND_JACK_HEADSET:
926                 state = BIT_HEADSET;
927                 break;
928         case SND_JACK_MICROPHONE:
929                 /* mic: would not report */
930         default:
931                 state = BIT_NO_HEADSET;
932         }
933
934         switch_set_state(&tegra_rt5640_headset_switch, state);
935
936         return NOTIFY_OK;
937 }
938
939 static struct notifier_block tegra_rt5640_jack_detect_nb = {
940         .notifier_call = tegra_rt5640_jack_notifier,
941 };
942 #else
943 static struct snd_soc_jack_pin tegra_rt5640_hp_jack_pins[] = {
944         {
945                 .pin = "Headphone Jack",
946                 .mask = SND_JACK_HEADPHONE,
947         },
948 };
949
950 #endif
951
952 static void tegra_speaker_edp_set_volume(struct snd_soc_codec *codec,
953                                          int l_vol,
954                                          int r_vol)
955 {
956         tegra_asoc_enable_clocks();
957         snd_soc_update_bits(codec,
958                             RT5640_SPK_VOL,
959                             RT5640_L_VOL_MASK,
960                             l_vol << RT5640_L_VOL_SFT);
961         snd_soc_update_bits(codec,
962                             RT5640_SPK_VOL,
963                             RT5640_R_VOL_MASK,
964                             r_vol << RT5640_R_VOL_SFT);
965         tegra_asoc_disable_clocks();
966 }
967
968 static void tegra_speaker_throttle(unsigned int new_state,  void *priv_data)
969 {
970         struct tegra_rt5640 *machine = priv_data;
971         struct snd_soc_card *card;
972         struct snd_soc_codec *codec;
973         int *edp_vol;
974
975         if (!machine)
976                 return;
977
978         card = machine->pcard;
979         codec = card->rtd[DAI_LINK_HIFI].codec;
980         edp_vol = machine->pdata->edp_vol;
981
982         /* set codec volume to reflect the new E-state */
983         switch (new_state) {
984         case TEGRA_SPK_EDP_NEG_1:
985         case TEGRA_SPK_EDP_ZERO:
986         case TEGRA_SPK_EDP_1:
987                 tegra_speaker_edp_set_volume(codec, edp_vol[new_state],
988                                 edp_vol[new_state]);
989                 dev_info(card->dev, "%s new_state=%d, edp_vol=0x%x\n",
990                                 __func__, new_state, edp_vol[new_state]);
991                 break;
992         default:
993                 pr_err("%s: New E-state %d don't support!\n",
994                         __func__, new_state);
995                 break;
996         }
997
998 }
999
1000 static int tegra_rt5640_event_int_spk(struct snd_soc_dapm_widget *w,
1001                                         struct snd_kcontrol *k, int event)
1002 {
1003         struct snd_soc_dapm_context *dapm = w->dapm;
1004         struct snd_soc_card *card = dapm->card;
1005         struct tegra_rt5640 *machine = snd_soc_card_get_drvdata(card);
1006         struct tegra_asoc_platform_data *pdata = machine->pdata;
1007         struct snd_soc_codec *codec = card->rtd[DAI_LINK_HIFI].codec;
1008         unsigned int approved = TEGRA_SPK_EDP_NUM_STATES;
1009         int *edp_vol = pdata->edp_vol;
1010         int ret;
1011
1012         if (machine->spk_reg) {
1013                 if (SND_SOC_DAPM_EVENT_ON(event)) {
1014                         regulator_enable(machine->spk_reg);
1015                 }
1016                 else {
1017                         regulator_disable(machine->spk_reg);
1018                 }
1019         }
1020         if(machine_is_roth()) {
1021                 if (SND_SOC_DAPM_EVENT_ON(event)) {
1022                         if(i2s_tfa) {
1023                                 if (codec_rt)
1024                                         snd_soc_update_bits(codec_rt, RT5640_PWR_DIG1, 0x0001, 0x0000);
1025                                 tegra_asoc_enable_clocks();
1026                                 Tfa9887_Powerdown(0);
1027                                 tegra_asoc_disable_clocks();
1028                         }
1029                 }
1030                 else {
1031                                 Tfa9887_Powerdown(1);
1032                 }
1033         }
1034
1035         if (machine->spk_edp_client == NULL)
1036                 goto err_null_spk_edp_client;
1037
1038         if (SND_SOC_DAPM_EVENT_ON(event)) {
1039                 ret = edp_update_client_request(machine->spk_edp_client,
1040                                                 TEGRA_SPK_EDP_NEG_1,
1041                                                 &approved);
1042                 approved = approved < TEGRA_SPK_EDP_NUM_STATES ?
1043                                 approved : TEGRA_SPK_EDP_NEG_1;
1044                 tegra_speaker_edp_set_volume(codec,
1045                                 edp_vol[approved], edp_vol[approved]);
1046                 dev_info(card->dev, "%s approved=%d, edp_vol=0x%x\n",
1047                                 __func__, approved, edp_vol[approved]);
1048         } else {
1049                 ret = edp_update_client_request(machine->spk_edp_client,
1050                                                 TEGRA_SPK_EDP_1,
1051                                                 NULL);
1052                 if (ret) {
1053                         dev_err(card->dev,
1054                                 "E+1 state transition failed\n");
1055                 }
1056         }
1057
1058 err_null_spk_edp_client:
1059         if (!(machine->gpio_requested & GPIO_SPKR_EN))
1060                 return 0;
1061
1062         gpio_set_value_cansleep(pdata->gpio_spkr_en,
1063                                 !!SND_SOC_DAPM_EVENT_ON(event));
1064
1065         return 0;
1066 }
1067
1068 static int tegra_rt5640_event_hp(struct snd_soc_dapm_widget *w,
1069                                         struct snd_kcontrol *k, int event)
1070 {
1071         struct snd_soc_dapm_context *dapm = w->dapm;
1072         struct snd_soc_card *card = dapm->card;
1073         struct tegra_rt5640 *machine = snd_soc_card_get_drvdata(card);
1074         struct tegra_asoc_platform_data *pdata = machine->pdata;
1075
1076         if (!(machine->gpio_requested & GPIO_HP_MUTE))
1077                 return 0;
1078
1079         gpio_set_value_cansleep(pdata->gpio_hp_mute,
1080                                 !SND_SOC_DAPM_EVENT_ON(event));
1081
1082         return 0;
1083 }
1084
1085 static int tegra_rt5640_event_int_mic(struct snd_soc_dapm_widget *w,
1086                                         struct snd_kcontrol *k, int event)
1087 {
1088         struct snd_soc_dapm_context *dapm = w->dapm;
1089         struct snd_soc_card *card = dapm->card;
1090         struct tegra_rt5640 *machine = snd_soc_card_get_drvdata(card);
1091         struct tegra_asoc_platform_data *pdata = machine->pdata;
1092
1093         if (machine->dmic_reg) {
1094                 if (SND_SOC_DAPM_EVENT_ON(event))
1095                         regulator_enable(machine->dmic_reg);
1096                 else
1097                         regulator_disable(machine->dmic_reg);
1098         }
1099
1100         if (!(machine->gpio_requested & GPIO_INT_MIC_EN))
1101                 return 0;
1102
1103         gpio_set_value_cansleep(pdata->gpio_int_mic_en,
1104                                 !!SND_SOC_DAPM_EVENT_ON(event));
1105
1106         return 0;
1107 }
1108
1109 static int tegra_rt5640_event_ext_mic(struct snd_soc_dapm_widget *w,
1110                                         struct snd_kcontrol *k, int event)
1111 {
1112         struct snd_soc_dapm_context *dapm = w->dapm;
1113         struct snd_soc_card *card = dapm->card;
1114         struct tegra_rt5640 *machine = snd_soc_card_get_drvdata(card);
1115         struct tegra_asoc_platform_data *pdata = machine->pdata;
1116
1117         if (!(machine->gpio_requested & GPIO_EXT_MIC_EN))
1118                 return 0;
1119
1120         gpio_set_value_cansleep(pdata->gpio_ext_mic_en,
1121                                 !SND_SOC_DAPM_EVENT_ON(event));
1122
1123         return 0;
1124 }
1125
1126 static const struct snd_soc_dapm_widget tegra_rt5640_dapm_widgets[] = {
1127         SND_SOC_DAPM_SPK("Int Spk", tegra_rt5640_event_int_spk),
1128         SND_SOC_DAPM_HP("Headphone Jack", tegra_rt5640_event_hp),
1129         SND_SOC_DAPM_MIC("Mic Jack", tegra_rt5640_event_ext_mic),
1130         SND_SOC_DAPM_MIC("Int Mic", tegra_rt5640_event_int_mic),
1131 };
1132
1133 static const struct snd_soc_dapm_route tegra_rt5640_audio_map[] = {
1134         {"Headphone Jack", NULL, "HPOR"},
1135         {"Headphone Jack", NULL, "HPOL"},
1136         {"Int Spk", NULL, "SPORP"},
1137         {"Int Spk", NULL, "SPORN"},
1138         {"Int Spk", NULL, "SPOLP"},
1139         {"Int Spk", NULL, "SPOLN"},
1140         {"micbias1", NULL, "Mic Jack"},
1141         {"IN1P", NULL, "micbias1"},
1142         {"IN1N", NULL, "micbias1"},
1143         {"micbias1", NULL, "Int Mic"},
1144         {"IN2P", NULL, "micbias1"},
1145         {"DMIC L1", NULL, "Int Mic"},
1146         {"DMIC L2", NULL, "Int Mic"},
1147         {"DMIC R1", NULL, "Int Mic"},
1148         {"DMIC R2", NULL, "Int Mic"},
1149 };
1150
1151 static const struct snd_soc_dapm_route tegra_rt5640_no_micbias_audio_map[] = {
1152         {"Headphone Jack", NULL, "HPOR"},
1153         {"Headphone Jack", NULL, "HPOL"},
1154         {"Int Spk", NULL, "SPORP"},
1155         {"Int Spk", NULL, "SPORN"},
1156         {"Int Spk", NULL, "SPOLP"},
1157         {"Int Spk", NULL, "SPOLN"},
1158         {"micbias1", NULL, "Mic Jack"},
1159         {"IN2P", NULL, "micbias1"},
1160         {"DMIC L1", NULL, "Int Mic"},
1161         {"DMIC L2", NULL, "Int Mic"},
1162         {"DMIC R1", NULL, "Int Mic"},
1163         {"DMIC R2", NULL, "Int Mic"},
1164 };
1165
1166 static const struct snd_kcontrol_new tegra_rt5640_controls[] = {
1167         SOC_DAPM_PIN_SWITCH("Int Spk"),
1168         SOC_DAPM_PIN_SWITCH("Headphone Jack"),
1169         SOC_DAPM_PIN_SWITCH("Mic Jack"),
1170         SOC_DAPM_PIN_SWITCH("Int Mic"),
1171 };
1172
1173 static int tegra_rt5640_init(struct snd_soc_pcm_runtime *rtd)
1174 {
1175         struct snd_soc_codec *codec = rtd->codec;
1176         struct snd_soc_dapm_context *dapm = &codec->dapm;
1177         struct snd_soc_card *card = codec->card;
1178         struct tegra_rt5640 *machine = snd_soc_card_get_drvdata(card);
1179         struct tegra_asoc_platform_data *pdata = machine->pdata;
1180 #ifndef CONFIG_ARCH_TEGRA_2x_SOC
1181         struct tegra30_i2s *i2s = snd_soc_dai_get_drvdata(rtd->cpu_dai);
1182 #endif
1183         int ret;
1184
1185 #ifndef CONFIG_ARCH_TEGRA_2x_SOC
1186         if (machine->codec_info[BASEBAND].i2s_id != -1)
1187                         i2s->is_dam_used = true;
1188 #endif
1189
1190         if ((i2s->id == machine->codec_info[HIFI_CODEC].i2s_id) &&
1191                 (i2s->id != machine->codec_info[VOICE_CODEC].i2s_id))
1192                 i2s->is_dam_used = false;
1193         i2s->is_dam_used = true;
1194
1195         if (machine->init_done)
1196                 return 0;
1197
1198         machine->init_done = true;
1199
1200
1201         codec_rt = codec;
1202
1203         if (gpio_is_valid(pdata->gpio_spkr_en)) {
1204                 ret = gpio_request(pdata->gpio_spkr_en, "spkr_en");
1205                 if (ret) {
1206                         dev_err(card->dev, "cannot get spkr_en gpio\n");
1207                         return ret;
1208                 }
1209                 machine->gpio_requested |= GPIO_SPKR_EN;
1210
1211                 gpio_direction_output(pdata->gpio_spkr_en, 0);
1212         }
1213
1214         if (gpio_is_valid(pdata->gpio_hp_mute)) {
1215                 ret = gpio_request(pdata->gpio_hp_mute, "hp_mute");
1216                 if (ret) {
1217                         dev_err(card->dev, "cannot get hp_mute gpio\n");
1218                         return ret;
1219                 }
1220                 machine->gpio_requested |= GPIO_HP_MUTE;
1221
1222                 gpio_direction_output(pdata->gpio_hp_mute, 0);
1223         }
1224
1225         if (gpio_is_valid(pdata->gpio_int_mic_en)) {
1226                 ret = gpio_request(pdata->gpio_int_mic_en, "int_mic_en");
1227                 if (ret) {
1228                         dev_err(card->dev, "cannot get int_mic_en gpio\n");
1229                 } else {
1230                         machine->gpio_requested |= GPIO_INT_MIC_EN;
1231
1232                         /* Disable int mic; enable signal is active-high */
1233                         gpio_direction_output(pdata->gpio_int_mic_en, 0);
1234                 }
1235         }
1236
1237         if (gpio_is_valid(pdata->gpio_ext_mic_en)) {
1238                 ret = gpio_request(pdata->gpio_ext_mic_en, "ext_mic_en");
1239                 if (ret) {
1240                         dev_err(card->dev, "cannot get ext_mic_en gpio\n");
1241                 } else {
1242                         machine->gpio_requested |= GPIO_EXT_MIC_EN;
1243
1244                         /* Disable ext mic; enable signal is active-low */
1245                         gpio_direction_output(pdata->gpio_ext_mic_en, 1);
1246                 }
1247         }
1248
1249         if (gpio_is_valid(pdata->gpio_hp_det)) {
1250                 tegra_rt5640_hp_jack_gpio.gpio = pdata->gpio_hp_det;
1251                 snd_soc_jack_new(codec, "Headphone Jack", SND_JACK_HEADPHONE,
1252                                 &tegra_rt5640_hp_jack);
1253 #ifndef CONFIG_SWITCH
1254                 snd_soc_jack_add_pins(&tegra_rt5640_hp_jack,
1255                                         ARRAY_SIZE(tegra_rt5640_hp_jack_pins),
1256                                         tegra_rt5640_hp_jack_pins);
1257 #else
1258                 snd_soc_jack_notifier_register(&tegra_rt5640_hp_jack,
1259                                         &tegra_rt5640_jack_detect_nb);
1260 #endif
1261                 snd_soc_jack_add_gpios(&tegra_rt5640_hp_jack,
1262                                         1,
1263                                         &tegra_rt5640_hp_jack_gpio);
1264                 machine->gpio_requested |= GPIO_HP_DET;
1265         }
1266
1267         /* Add call mode switch control */
1268         ret = snd_ctl_add(codec->card->snd_card,
1269                 snd_ctl_new1(&tegra_rt5640_call_mode_control, machine));
1270         ret = tegra_asoc_utils_register_ctls(&machine->util_data);
1271         if (ret < 0)
1272                 return ret;
1273
1274         /* FIXME: Calculate automatically based on DAPM routes? */
1275         snd_soc_dapm_nc_pin(dapm, "LOUTL");
1276         snd_soc_dapm_nc_pin(dapm, "LOUTR");
1277
1278         snd_soc_dapm_sync(dapm);
1279
1280         return 0;
1281 }
1282
1283 static struct snd_soc_dai_link tegra_rt5640_dai[NUM_DAI_LINKS] = {
1284         [DAI_LINK_HIFI] = {
1285                 .name = "RT5640",
1286                 .stream_name = "RT5640 PCM",
1287                 .codec_name = "rt5640.4-001c",
1288                 .platform_name = "tegra-pcm-audio",
1289                 .cpu_dai_name = "tegra30-i2s.1",
1290                 .codec_dai_name = "rt5640-aif1",
1291                 .init = tegra_rt5640_init,
1292                 .ops = &tegra_rt5640_ops,
1293         },
1294         [DAI_LINK_SPDIF] = {
1295                 .name = "SPDIF",
1296                 .stream_name = "SPDIF PCM",
1297                 .codec_name = "spdif-dit.0",
1298                 .platform_name = "tegra-pcm-audio",
1299                 .cpu_dai_name = "tegra30-spdif",
1300                 .codec_dai_name = "dit-hifi",
1301                 .ops = &tegra_spdif_ops,
1302         },
1303         [DAI_LINK_BTSCO] = {
1304                 .name = "BT-SCO",
1305                 .stream_name = "BT SCO PCM",
1306                 .codec_name = "spdif-dit.1",
1307                 .platform_name = "tegra-pcm-audio",
1308                 .cpu_dai_name = "tegra30-i2s.3",
1309                 .codec_dai_name = "dit-hifi",
1310                 .ops = &tegra_rt5640_bt_sco_ops,
1311         },
1312         [DAI_LINK_VOICE_CALL] = {
1313                 .name = "VOICE CALL",
1314                 .stream_name = "VOICE CALL PCM",
1315                 .codec_name = "rt5639.0-001c",
1316                 .platform_name = "tegra-pcm-audio",
1317                 .cpu_dai_name = "dit-hifi",
1318                 .codec_dai_name = "rt5639-aif1",
1319                 .ops = &tegra_voice_call_ops,
1320         },
1321         [DAI_LINK_BT_VOICE_CALL] = {
1322                 .name = "BT VOICE CALL",
1323                 .stream_name = "BT VOICE CALL PCM",
1324                 .codec_name = "spdif-dit.1",
1325                 .platform_name = "tegra-pcm-audio",
1326                 .cpu_dai_name = "dit-hifi",
1327                 .codec_dai_name = "dit-hifi",
1328                 .ops = &tegra_bt_voice_call_ops,
1329         },
1330 };
1331
1332 static int tegra_rt5640_resume_pre(struct snd_soc_card *card)
1333 {
1334         int val;
1335         struct snd_soc_jack_gpio *gpio = &tegra_rt5640_hp_jack_gpio;
1336
1337         if (gpio_is_valid(gpio->gpio)) {
1338                 val = gpio_get_value(gpio->gpio);
1339                 val = gpio->invert ? !val : val;
1340                 snd_soc_jack_report(gpio->jack, val, gpio->report);
1341         }
1342
1343         return 0;
1344 }
1345
1346 static int tegra_rt5640_set_bias_level(struct snd_soc_card *card,
1347         struct snd_soc_dapm_context *dapm, enum snd_soc_bias_level level)
1348 {
1349         struct tegra_rt5640 *machine = snd_soc_card_get_drvdata(card);
1350
1351         if (machine->bias_level == SND_SOC_BIAS_OFF &&
1352                 level != SND_SOC_BIAS_OFF && (!machine->clock_enabled)) {
1353                 machine->clock_enabled = 1;
1354                 tegra_asoc_utils_clk_enable(&machine->util_data);
1355                 machine->bias_level = level;
1356         }
1357
1358         return 0;
1359 }
1360
1361 static int tegra_rt5640_set_bias_level_post(struct snd_soc_card *card,
1362         struct snd_soc_dapm_context *dapm, enum snd_soc_bias_level level)
1363 {
1364         struct tegra_rt5640 *machine = snd_soc_card_get_drvdata(card);
1365
1366         if (machine->bias_level != SND_SOC_BIAS_OFF &&
1367                 level == SND_SOC_BIAS_OFF && machine->clock_enabled) {
1368                 machine->clock_enabled = 0;
1369                 tegra_asoc_utils_clk_disable(&machine->util_data);
1370         }
1371
1372         machine->bias_level = level;
1373
1374         return 0 ;
1375 }
1376
1377 static struct snd_soc_card snd_soc_tegra_rt5640 = {
1378         .name = "tegra-rt5640",
1379         .owner = THIS_MODULE,
1380         .dai_link = tegra_rt5640_dai,
1381         .num_links = ARRAY_SIZE(tegra_rt5640_dai),
1382         .resume_pre = tegra_rt5640_resume_pre,
1383         .set_bias_level = tegra_rt5640_set_bias_level,
1384         .set_bias_level_post = tegra_rt5640_set_bias_level_post,
1385         .controls = tegra_rt5640_controls,
1386         .num_controls = ARRAY_SIZE(tegra_rt5640_controls),
1387         .dapm_widgets = tegra_rt5640_dapm_widgets,
1388         .num_dapm_widgets = ARRAY_SIZE(tegra_rt5640_dapm_widgets),
1389         .dapm_routes = tegra_rt5640_audio_map,
1390         .num_dapm_routes = ARRAY_SIZE(tegra_rt5640_audio_map),
1391         .fully_routed = true,
1392 };
1393
1394 void tegra_asoc_enable_clocks()
1395 {
1396         struct snd_soc_card *card = &snd_soc_tegra_rt5640;
1397         struct tegra_rt5640 *machine = snd_soc_card_get_drvdata(card);
1398         int reg;
1399         struct tegra30_i2s *i2s = i2s_tfa;
1400         if (!i2s || !machine)
1401                 return;
1402
1403         reg = i2s->reg_ctrl | TEGRA30_I2S_CTRL_XFER_EN_TX;
1404         if (!(i2s->reg_ctrl & TEGRA30_I2S_CTRL_XFER_EN_TX)) {
1405                 tegra_asoc_utils_clk_enable(&machine->util_data);
1406                 clk_enable(i2s->clk_i2s);
1407                 tegra30_ahub_enable_clocks();
1408                 tegra30_ahub_enable_tx_fifo(i2s->txcif);
1409                 __raw_writel(reg, i2s->regs + TEGRA30_I2S_CTRL);
1410         }
1411 }
1412 EXPORT_SYMBOL_GPL(tegra_asoc_enable_clocks);
1413
1414 void tegra_asoc_disable_clocks()
1415 {
1416         struct snd_soc_card *card = &snd_soc_tegra_rt5640;
1417         struct tegra_rt5640 *machine = snd_soc_card_get_drvdata(card);
1418         int dcnt = 10;
1419         struct tegra30_i2s *i2s = i2s_tfa;
1420         if (!i2s || !machine)
1421                 return;
1422
1423         if (!(i2s->reg_ctrl & TEGRA30_I2S_CTRL_XFER_EN_TX)) {
1424                 __raw_writel(i2s->reg_ctrl, i2s->regs + TEGRA30_I2S_CTRL);
1425                 while (!tegra30_ahub_tx_fifo_is_empty(i2s->id) && dcnt--)
1426                         udelay(100);
1427
1428                 tegra30_ahub_disable_tx_fifo(i2s->txcif);
1429                 tegra30_ahub_disable_clocks();
1430                 clk_disable(i2s->clk_i2s);
1431                 tegra_asoc_utils_clk_disable(&machine->util_data);
1432         }
1433 }
1434 EXPORT_SYMBOL_GPL(tegra_asoc_disable_clocks);
1435
1436
1437 static __devinit int tegra_rt5640_driver_probe(struct platform_device *pdev)
1438 {
1439         struct snd_soc_card *card = &snd_soc_tegra_rt5640;
1440         struct tegra_rt5640 *machine;
1441         struct tegra_asoc_platform_data *pdata;
1442         struct snd_soc_codec *codec;
1443         struct edp_manager *battery_manager = NULL;
1444         int ret;
1445         int i;
1446         pdata = pdev->dev.platform_data;
1447         if (!pdata) {
1448                 dev_err(&pdev->dev, "No platform data supplied\n");
1449                 return -EINVAL;
1450         }
1451
1452         if (pdata->micbias_gpio_absent) {
1453                 card->dapm_routes =
1454                         tegra_rt5640_no_micbias_audio_map;
1455                 card->num_dapm_routes =
1456                         ARRAY_SIZE(tegra_rt5640_no_micbias_audio_map);
1457         }
1458
1459         if (pdata->codec_name)
1460                 card->dai_link->codec_name = pdata->codec_name;
1461
1462         if (pdata->codec_dai_name)
1463                 card->dai_link->codec_dai_name = pdata->codec_dai_name;
1464
1465         machine = kzalloc(sizeof(struct tegra_rt5640), GFP_KERNEL);
1466         if (!machine) {
1467                 dev_err(&pdev->dev, "Can't allocate tegra_rt5640 struct\n");
1468                 return -ENOMEM;
1469         }
1470
1471         if (gpio_is_valid(pdata->gpio_ldo1_en)) {
1472                 ret = gpio_request(pdata->gpio_ldo1_en, "rt5640");
1473                 if (ret) {
1474                         dev_err(&pdev->dev, "Fail gpio_request AUDIO_LDO1\n");
1475                 }
1476
1477                 ret = gpio_direction_output(pdata->gpio_ldo1_en, 1);
1478                 if (ret)
1479                         dev_err(&pdev->dev, "Fail gpio_direction AUDIO_LDO1\n");
1480
1481                 msleep(200);
1482         }
1483
1484         if (gpio_is_valid(pdata->gpio_codec1)) {
1485                 ret = gpio_request(pdata->gpio_codec1, "rt5640");
1486                 if (ret)
1487                         dev_err(&pdev->dev, "Fail gpio_request GPIO_CODEC1\n");
1488
1489                 ret = gpio_direction_output(pdata->gpio_codec1, 1);
1490                 if (ret)
1491                         dev_err(&pdev->dev, "Fail gpio_direction GPIO_CODEC1\n");
1492
1493                 msleep(200);
1494         }
1495
1496         if (gpio_is_valid(pdata->gpio_codec2)) {
1497                 ret = gpio_request(pdata->gpio_codec2, "rt5640");
1498                 if (ret)
1499                         dev_err(&pdev->dev, "Fail gpio_request GPIO_CODEC2\n");
1500
1501                 ret = gpio_direction_output(pdata->gpio_codec2, 1);
1502                 if (ret)
1503                         dev_err(&pdev->dev, "Fail gpio_direction GPIO_CODEC2\n");
1504
1505                 msleep(200);
1506         }
1507
1508         if (gpio_is_valid(pdata->gpio_codec3)) {
1509                 ret = gpio_request(pdata->gpio_codec3, "rt5640");
1510                 if (ret)
1511                         dev_err(&pdev->dev, "Fail gpio_request GPIO_CODEC3\n");
1512
1513                 ret = gpio_direction_output(pdata->gpio_codec3, 1);
1514                 if (ret)
1515                         dev_err(&pdev->dev, "Fail gpio_direction GPIO_CODEC3\n");
1516
1517                 msleep(200);
1518         }
1519
1520         machine->pdata = pdata;
1521         machine->pcard = card;
1522
1523         ret = tegra_asoc_utils_init(&machine->util_data, &pdev->dev, card);
1524         if (ret)
1525                 goto err_free_machine;
1526
1527         machine->bias_level = SND_SOC_BIAS_STANDBY;
1528         machine->clock_enabled = 1;
1529
1530         if (!gpio_is_valid(pdata->gpio_ldo1_en)) {
1531                 machine->cdc_en = regulator_get(&pdev->dev, "ldo1_en");
1532                 if (IS_ERR(machine->cdc_en)) {
1533                         dev_err(&pdev->dev, "ldo1_en regulator not found %ld\n",
1534                                         PTR_ERR(machine->cdc_en));
1535                         machine->cdc_en = 0;
1536                 } else {
1537                         regulator_enable(machine->cdc_en);
1538                 }
1539         }
1540
1541         machine->spk_reg = regulator_get(&pdev->dev, "vdd_spk");
1542         if (IS_ERR(machine->spk_reg)) {
1543                 dev_info(&pdev->dev, "No speaker regulator found\n");
1544                 machine->spk_reg = 0;
1545         }
1546
1547 #ifdef CONFIG_SWITCH
1548         /* Addd h2w swith class support */
1549         ret = tegra_asoc_switch_register(&tegra_rt5640_headset_switch);
1550         if (ret < 0)
1551                 goto err_fini_utils;
1552 #endif
1553
1554         card->dev = &pdev->dev;
1555         platform_set_drvdata(pdev, card);
1556         snd_soc_card_set_drvdata(card, machine);
1557 #ifndef CONFIG_ARCH_TEGRA_2x_SOC
1558         for (i = 0; i < NUM_I2S_DEVICES ; i++) {
1559                 machine->codec_info[i].i2s_id =
1560                         pdata->i2s_param[i].audio_port_id;
1561                 machine->codec_info[i].bitsize =
1562                         pdata->i2s_param[i].sample_size;
1563                 machine->codec_info[i].is_i2smaster =
1564                         pdata->i2s_param[i].is_i2s_master;
1565                 machine->codec_info[i].rate =
1566                         pdata->i2s_param[i].rate;
1567                 machine->codec_info[i].channels =
1568                         pdata->i2s_param[i].channels;
1569                 machine->codec_info[i].i2s_mode =
1570                         pdata->i2s_param[i].i2s_mode;
1571                 machine->codec_info[i].bit_clk =
1572                         pdata->i2s_param[i].bit_clk;
1573         }
1574 #endif
1575         card->dapm.idle_bias_off = 1;
1576         ret = snd_soc_register_card(card);
1577         if (ret) {
1578                 dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n",
1579                         ret);
1580                 goto err_unregister_switch;
1581         }
1582
1583         if (!card->instantiated) {
1584                 ret = -ENODEV;
1585                 dev_err(&pdev->dev, "sound card not instantiated (%d)\n",
1586                         ret);
1587                 goto err_unregister_card;
1588         }
1589
1590         if (pdata->use_codec_jd_irq) {
1591                 codec = card->rtd[DAI_LINK_HIFI].codec;
1592                 if (!strncmp(pdata->codec_name, "rt5639", 6))
1593                         rt5639_irq_jd_reg_init(codec);
1594         }
1595
1596 #ifndef CONFIG_ARCH_TEGRA_2x_SOC
1597         ret = tegra_asoc_utils_set_parent(&machine->util_data,
1598                                 pdata->i2s_param[HIFI_CODEC].is_i2s_master);
1599         if (ret) {
1600                 dev_err(&pdev->dev, "tegra_asoc_utils_set_parent failed (%d)\n",
1601                         ret);
1602                 goto err_unregister_card;
1603         }
1604 #endif
1605
1606
1607         if (!pdata->edp_support)
1608                 return 0;
1609
1610         machine->spk_edp_client = devm_kzalloc(&pdev->dev,
1611                                 sizeof(struct edp_client), GFP_KERNEL);
1612         if (IS_ERR_OR_NULL(machine->spk_edp_client)) {
1613                 dev_err(&pdev->dev, "could not allocate edp client\n");
1614                 return 0;
1615         }
1616
1617         strncpy(machine->spk_edp_client->name, "speaker", EDP_NAME_LEN - 1);
1618         machine->spk_edp_client->name[EDP_NAME_LEN - 1] = '\0';
1619         machine->spk_edp_client->states = pdata->edp_states;
1620         machine->spk_edp_client->num_states = TEGRA_SPK_EDP_NUM_STATES;
1621         machine->spk_edp_client->e0_index = TEGRA_SPK_EDP_ZERO;
1622         machine->spk_edp_client->priority = EDP_MAX_PRIO + 2;
1623         machine->spk_edp_client->throttle = tegra_speaker_throttle;
1624         machine->spk_edp_client->private_data = machine;
1625
1626         battery_manager = edp_get_manager("battery");
1627         if (!battery_manager) {
1628                 dev_err(&pdev->dev, "unable to get edp manager\n");
1629         } else {
1630                 /* register speaker edp client */
1631                 ret = edp_register_client(battery_manager,
1632                         machine->spk_edp_client);
1633                 if (ret) {
1634                         dev_err(&pdev->dev, "unable to register edp client\n");
1635                                 devm_kfree(&pdev->dev, machine->spk_edp_client);
1636                                 machine->spk_edp_client = NULL;
1637                 }
1638                 codec = card->rtd[DAI_LINK_HIFI].codec;
1639                 /* set codec volume to -16.5dB (78%), E0 state */
1640                 tegra_speaker_edp_set_volume(codec, 0x13, 0x13);
1641
1642                 /* request E0 */
1643                 ret = edp_update_client_request(machine->spk_edp_client,
1644                                                 TEGRA_SPK_EDP_ZERO,
1645                                                 NULL);
1646                 if (ret) {
1647                         dev_err(&pdev->dev,
1648                                 "unable to set E0 EDP state\n");
1649                         edp_unregister_client(machine->spk_edp_client);
1650                         devm_kfree(&pdev->dev, machine->spk_edp_client);
1651                         machine->spk_edp_client = NULL;
1652                 }
1653         }
1654
1655         return 0;
1656
1657 err_unregister_card:
1658         snd_soc_unregister_card(card);
1659 err_unregister_switch:
1660 #ifdef CONFIG_SWITCH
1661         tegra_asoc_switch_unregister(&tegra_rt5640_headset_switch);
1662 err_fini_utils:
1663 #endif
1664         tegra_asoc_utils_fini(&machine->util_data);
1665 err_free_machine:
1666         kfree(machine);
1667         return ret;
1668 }
1669
1670 static int __devexit tegra_rt5640_driver_remove(struct platform_device *pdev)
1671 {
1672         struct snd_soc_card *card = platform_get_drvdata(pdev);
1673         struct tegra_rt5640 *machine = snd_soc_card_get_drvdata(card);
1674         struct tegra_asoc_platform_data *pdata = machine->pdata;
1675
1676         if (machine->gpio_requested & GPIO_HP_DET)
1677                 snd_soc_jack_free_gpios(&tegra_rt5640_hp_jack,
1678                                         1,
1679                                         &tegra_rt5640_hp_jack_gpio);
1680         if (machine->gpio_requested & GPIO_EXT_MIC_EN)
1681                 gpio_free(pdata->gpio_ext_mic_en);
1682         if (machine->gpio_requested & GPIO_INT_MIC_EN)
1683                 gpio_free(pdata->gpio_int_mic_en);
1684         if (machine->gpio_requested & GPIO_HP_MUTE)
1685                 gpio_free(pdata->gpio_hp_mute);
1686         if (machine->gpio_requested & GPIO_SPKR_EN)
1687                 gpio_free(pdata->gpio_spkr_en);
1688         machine->gpio_requested = 0;
1689
1690         if (machine->spk_reg)
1691                 regulator_put(machine->spk_reg);
1692         if (machine->dmic_reg)
1693                 regulator_put(machine->dmic_reg);
1694
1695         if (machine->cdc_en) {
1696                 regulator_disable(machine->cdc_en);
1697                 regulator_put(machine->cdc_en);
1698         }
1699
1700         if (gpio_is_valid(pdata->gpio_ldo1_en)) {
1701                 gpio_set_value(pdata->gpio_ldo1_en, 0);
1702                 gpio_free(pdata->gpio_ldo1_en);
1703         }
1704
1705         snd_soc_unregister_card(card);
1706
1707         tegra_asoc_utils_fini(&machine->util_data);
1708
1709 #ifdef CONFIG_SWITCH
1710         tegra_asoc_switch_unregister(&tegra_rt5640_headset_switch);
1711 #endif
1712         kfree(machine);
1713
1714         return 0;
1715 }
1716
1717 static struct platform_driver tegra_rt5640_driver = {
1718         .driver = {
1719                 .name = DRV_NAME,
1720                 .owner = THIS_MODULE,
1721                 .pm = &snd_soc_pm_ops,
1722         },
1723         .probe = tegra_rt5640_driver_probe,
1724         .remove = __devexit_p(tegra_rt5640_driver_remove),
1725 };
1726
1727 static int __init tegra_rt5640_modinit(void)
1728 {
1729         return platform_driver_register(&tegra_rt5640_driver);
1730 }
1731 module_init(tegra_rt5640_modinit);
1732
1733 static void __exit tegra_rt5640_modexit(void)
1734 {
1735         platform_driver_unregister(&tegra_rt5640_driver);
1736 }
1737 module_exit(tegra_rt5640_modexit);
1738
1739 MODULE_AUTHOR("Johnny Qiu <joqiu@nvidia.com>");
1740 MODULE_DESCRIPTION("Tegra+RT5640 machine ASoC driver");
1741 MODULE_LICENSE("GPL");
1742 MODULE_ALIAS("platform:" DRV_NAME);