2 * tegra_max98088.c - Tegra machine ASoC driver for boards using MAX98088 codec.
4 * Author: Sumit Bhattacharya <sumitb@nvidia.com>
5 * Copyright (C) 2011 - NVIDIA, Inc.
7 * Based on code copyright/by:
9 * (c) 2010, 2011 Nvidia Graphics Pvt. Ltd.
11 * Copyright 2007 Wolfson Microelectronics PLC.
12 * Author: Graeme Gregory
13 * graeme.gregory@wolfsonmicro.com or linux@wolfsonmicro.com
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * version 2 as published by the Free Software Foundation.
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
31 #include <asm/mach-types.h>
33 #include <linux/clk.h>
34 #include <linux/module.h>
35 #include <linux/platform_device.h>
36 #include <linux/slab.h>
37 #include <linux/gpio.h>
38 #include <linux/regulator/consumer.h>
40 #include <linux/switch.h>
43 #include <mach/tegra_asoc_pdata.h>
45 #include <sound/core.h>
46 #include <sound/jack.h>
47 #include <sound/pcm.h>
48 #include <sound/pcm_params.h>
49 #include <sound/soc.h>
51 #include "../codecs/max98088.h"
53 #include "tegra_pcm.h"
54 #include "tegra_asoc_utils.h"
55 #ifndef CONFIG_ARCH_TEGRA_2x_SOC
56 #include "tegra30_ahub.h"
57 #include "tegra30_i2s.h"
58 #include "tegra30_dam.h"
61 #define DRV_NAME "tegra-snd-max98088"
63 #define GPIO_SPKR_EN BIT(0)
64 #define GPIO_HP_MUTE BIT(1)
65 #define GPIO_INT_MIC_EN BIT(2)
66 #define GPIO_EXT_MIC_EN BIT(3)
68 #define DAI_LINK_HIFI 0
69 #define DAI_LINK_SPDIF 1
70 #define DAI_LINK_BTSCO 2
71 #define DAI_LINK_VOICE_CALL 3
72 #define DAI_LINK_BT_VOICE_CALL 4
73 #define NUM_DAI_LINKS 5
75 #ifndef CONFIG_ARCH_TEGRA_2x_SOC
76 const char *tegra_max98088_i2s_dai_name[TEGRA30_NR_I2S_IFC] = {
85 extern int g_is_call_mode;
87 struct tegra_max98088 {
88 struct tegra_asoc_utils_data util_data;
89 struct tegra_asoc_platform_data *pdata;
94 #ifndef CONFIG_ARCH_TEGRA_2x_SOC
95 struct codec_config codec_info[NUM_I2S_DEVICES];
97 enum snd_soc_bias_level bias_level;
98 struct snd_soc_card *pcard;
99 volatile int clock_enabled;
102 static int tegra_call_mode_info(struct snd_kcontrol *kcontrol,
103 struct snd_ctl_elem_info *uinfo)
105 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
107 uinfo->value.integer.min = 0;
108 uinfo->value.integer.max = 1;
112 static int tegra_call_mode_get(struct snd_kcontrol *kcontrol,
113 struct snd_ctl_elem_value *ucontrol)
115 struct tegra_max98088 *machine = snd_kcontrol_chip(kcontrol);
117 ucontrol->value.integer.value[0] = machine->is_call_mode;
122 static int tegra_call_mode_put(struct snd_kcontrol *kcontrol,
123 struct snd_ctl_elem_value *ucontrol)
125 struct tegra_max98088 *machine = snd_kcontrol_chip(kcontrol);
126 int is_call_mode_new = ucontrol->value.integer.value[0];
130 if (machine->is_call_mode == is_call_mode_new)
133 if (machine->is_device_bt)
134 codec_index = BT_SCO;
136 codec_index = HIFI_CODEC;
138 if (is_call_mode_new) {
139 #ifndef CONFIG_ARCH_TEGRA_2x_SOC
140 if (machine->codec_info[codec_index].rate == 0 ||
141 machine->codec_info[codec_index].channels == 0)
144 for (i = 0; i < machine->pcard->num_links; i++)
145 machine->pcard->dai_link[i].ignore_suspend = 1;
147 tegra30_make_voice_call_connections(
148 &machine->codec_info[codec_index],
149 &machine->codec_info[BASEBAND]);
152 #ifndef CONFIG_ARCH_TEGRA_2x_SOC
153 tegra30_break_voice_call_connections(
154 &machine->codec_info[codec_index],
155 &machine->codec_info[BASEBAND]);
157 for (i = 0; i < machine->pcard->num_links; i++)
158 machine->pcard->dai_link[i].ignore_suspend = 0;
162 machine->is_call_mode = is_call_mode_new;
163 g_is_call_mode = machine->is_call_mode;
168 struct snd_kcontrol_new tegra_call_mode_control = {
169 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
170 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
171 .name = "Call Mode Switch",
172 .private_value = 0xffff,
173 .info = tegra_call_mode_info,
174 .get = tegra_call_mode_get,
175 .put = tegra_call_mode_put
178 #ifndef CONFIG_ARCH_TEGRA_2x_SOC
179 static int tegra_max98088_set_dam_cif(int dam_ifc, int srate,
180 int channels, int bit_size, int src_on, int src_srate,
181 int src_channels, int src_bit_size)
183 tegra30_dam_set_gain(dam_ifc, TEGRA30_DAM_CHIN1, 0x1000);
184 tegra30_dam_set_samplerate(dam_ifc, TEGRA30_DAM_CHOUT,
186 tegra30_dam_set_samplerate(dam_ifc, TEGRA30_DAM_CHIN1,
188 tegra30_dam_set_acif(dam_ifc, TEGRA30_DAM_CHIN1,
189 channels, bit_size, channels,
191 tegra30_dam_set_acif(dam_ifc, TEGRA30_DAM_CHOUT,
192 channels, bit_size, channels,
196 tegra30_dam_set_gain(dam_ifc, TEGRA30_DAM_CHIN0_SRC, 0x1000);
197 tegra30_dam_set_samplerate(dam_ifc, TEGRA30_DAM_CHIN0_SRC,
199 tegra30_dam_set_acif(dam_ifc, TEGRA30_DAM_CHIN0_SRC,
200 src_channels, src_bit_size, 1, 16);
207 static int tegra_max98088_hw_params(struct snd_pcm_substream *substream,
208 struct snd_pcm_hw_params *params)
210 struct snd_soc_pcm_runtime *rtd = substream->private_data;
211 struct snd_soc_dai *codec_dai = rtd->codec_dai;
212 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
213 struct snd_soc_codec *codec = rtd->codec;
214 struct snd_soc_card *card = codec->card;
215 struct tegra_max98088 *machine = snd_soc_card_get_drvdata(card);
216 #ifndef CONFIG_ARCH_TEGRA_2x_SOC
217 struct tegra30_i2s *i2s = snd_soc_dai_get_drvdata(cpu_dai);
219 int srate, mclk, sample_size, i2s_daifmt;
224 switch (params_format(params)) {
225 case SNDRV_PCM_FORMAT_S16_LE:
232 srate = params_rate(params);
255 #if defined(CONFIG_ARCH_TEGRA_2x_SOC)
256 clk = clk_get_sys(NULL, "cdev1");
258 clk = clk_get_sys("extern1", NULL);
261 dev_err(card->dev, "Can't retrieve clk cdev1\n");
266 rate = clk_get_rate(clk);
267 printk("extern1 rate=%d\n",rate);
269 #if TEGRA30_I2S_MASTER_PLAYBACK
270 i2s_daifmt = SND_SOC_DAIFMT_I2S |
271 SND_SOC_DAIFMT_NB_NF |
272 SND_SOC_DAIFMT_CBS_CFS;
274 i2s_daifmt = SND_SOC_DAIFMT_I2S |
275 SND_SOC_DAIFMT_NB_NF |
276 SND_SOC_DAIFMT_CBM_CFM;
280 err = tegra_asoc_utils_set_rate(&machine->util_data, srate, mclk);
282 if (!(machine->util_data.set_mclk % mclk))
283 mclk = machine->util_data.set_mclk;
285 dev_err(card->dev, "Can't configure clocks\n");
290 tegra_asoc_utils_lock_clk_rate(&machine->util_data, 1);
292 err = snd_soc_dai_set_fmt(codec_dai,i2s_daifmt);
294 dev_err(card->dev, "codec_dai fmt not set\n");
298 err = snd_soc_dai_set_fmt(cpu_dai, i2s_daifmt);
300 dev_err(card->dev, "cpu_dai fmt not set\n");
304 err = snd_soc_dai_set_sysclk(codec_dai, 0, mclk,
307 dev_err(card->dev, "codec_dai clock not set\n");
311 #ifndef CONFIG_ARCH_TEGRA_2x_SOC
312 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
313 tegra_max98088_set_dam_cif(i2s->dam_ifc, srate,
314 params_channels(params), sample_size, 0, 0, 0, 0);
320 static int tegra_spdif_hw_params(struct snd_pcm_substream *substream,
321 struct snd_pcm_hw_params *params)
323 struct snd_soc_pcm_runtime *rtd = substream->private_data;
324 struct snd_soc_card *card = rtd->card;
325 struct tegra_max98088 *machine = snd_soc_card_get_drvdata(card);
326 int srate, mclk, min_mclk;
329 srate = params_rate(params);
348 min_mclk = 128 * srate;
350 err = tegra_asoc_utils_set_rate(&machine->util_data, srate, mclk);
352 if (!(machine->util_data.set_mclk % min_mclk))
353 mclk = machine->util_data.set_mclk;
355 dev_err(card->dev, "Can't configure clocks\n");
360 tegra_asoc_utils_lock_clk_rate(&machine->util_data, 1);
365 static int tegra_bt_hw_params(struct snd_pcm_substream *substream,
366 struct snd_pcm_hw_params *params)
368 struct snd_soc_pcm_runtime *rtd = substream->private_data;
369 #ifndef CONFIG_ARCH_TEGRA_2x_SOC
370 struct tegra30_i2s *i2s = snd_soc_dai_get_drvdata(rtd->cpu_dai);
372 struct snd_soc_card *card = rtd->card;
373 struct tegra_max98088 *machine = snd_soc_card_get_drvdata(card);
374 int err, srate, mclk, min_mclk, sample_size;
376 switch (params_format(params)) {
377 case SNDRV_PCM_FORMAT_S16_LE:
384 srate = params_rate(params);
403 min_mclk = 64 * srate;
405 err = tegra_asoc_utils_set_rate(&machine->util_data, srate, mclk);
407 if (!(machine->util_data.set_mclk % min_mclk))
408 mclk = machine->util_data.set_mclk;
410 dev_err(card->dev, "Can't configure clocks\n");
415 tegra_asoc_utils_lock_clk_rate(&machine->util_data, 1);
417 err = snd_soc_dai_set_fmt(rtd->cpu_dai,
418 SND_SOC_DAIFMT_DSP_A |
419 SND_SOC_DAIFMT_NB_NF |
420 SND_SOC_DAIFMT_CBS_CFS);
422 dev_err(rtd->codec->card->dev, "cpu_dai fmt not set\n");
426 #ifndef CONFIG_ARCH_TEGRA_2x_SOC
427 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
428 tegra_max98088_set_dam_cif(i2s->dam_ifc, params_rate(params),
429 params_channels(params), sample_size, 0, 0, 0, 0);
435 static int tegra_hw_free(struct snd_pcm_substream *substream)
437 struct snd_soc_pcm_runtime *rtd = substream->private_data;
438 struct tegra_max98088 *machine = snd_soc_card_get_drvdata(rtd->card);
440 tegra_asoc_utils_lock_clk_rate(&machine->util_data, 0);
445 #ifndef CONFIG_ARCH_TEGRA_2x_SOC
446 static int tegra_max98088_startup(struct snd_pcm_substream *substream)
448 struct snd_soc_pcm_runtime *rtd = substream->private_data;
449 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
450 struct tegra30_i2s *i2s = snd_soc_dai_get_drvdata(cpu_dai);
451 struct tegra_max98088 *machine = snd_soc_card_get_drvdata(rtd->card);
452 struct codec_config *codec_info;
453 struct codec_config *bb_info;
456 if (!i2s->is_dam_used)
459 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
460 /*dam configuration*/
461 if (!i2s->dam_ch_refcount)
462 i2s->dam_ifc = tegra30_dam_allocate_controller();
464 tegra30_dam_allocate_channel(i2s->dam_ifc, TEGRA30_DAM_CHIN1);
465 i2s->dam_ch_refcount++;
466 tegra30_dam_enable_clock(i2s->dam_ifc);
468 tegra30_ahub_set_rx_cif_source(TEGRA30_AHUB_RXCIF_DAM0_RX1 +
469 (i2s->dam_ifc*2), i2s->txcif);
472 *make the dam tx to i2s rx connection if this is the only client
473 *using i2s for playback
475 if (i2s->playback_ref_count == 1)
476 tegra30_ahub_set_rx_cif_source(
477 TEGRA30_AHUB_RXCIF_I2S0_RX0 + i2s->id,
478 TEGRA30_AHUB_TXCIF_DAM0_TX0 + i2s->dam_ifc);
481 tegra30_dam_enable(i2s->dam_ifc, TEGRA30_DAM_ENABLE,
485 i2s->is_call_mode_rec = machine->is_call_mode;
487 if (!i2s->is_call_mode_rec)
490 if (machine->is_device_bt)
491 codec_index = BT_SCO;
493 codec_index = HIFI_CODEC;
495 codec_info = &machine->codec_info[codec_index];
496 bb_info = &machine->codec_info[BASEBAND];
498 /* allocate a dam for voice call recording */
500 i2s->call_record_dam_ifc = tegra30_dam_allocate_controller();
501 tegra30_dam_allocate_channel(i2s->call_record_dam_ifc,
502 TEGRA30_DAM_CHIN0_SRC);
503 tegra30_dam_allocate_channel(i2s->call_record_dam_ifc,
505 tegra30_dam_enable_clock(i2s->call_record_dam_ifc);
507 /* configure the dam */
508 tegra_max98088_set_dam_cif(i2s->call_record_dam_ifc,
509 codec_info->rate, codec_info->channels,
510 codec_info->bitsize, 1, bb_info->rate,
511 bb_info->channels, bb_info->bitsize);
513 /* setup the connections for voice call record */
515 tegra30_ahub_unset_rx_cif_source(i2s->rxcif);
516 tegra30_ahub_set_rx_cif_source(TEGRA30_AHUB_RXCIF_DAM0_RX0 +
517 (i2s->call_record_dam_ifc*2),
518 TEGRA30_AHUB_TXCIF_I2S0_TX0 + bb_info->i2s_id);
519 tegra30_ahub_set_rx_cif_source(TEGRA30_AHUB_RXCIF_DAM0_RX1 +
520 (i2s->call_record_dam_ifc*2),
521 TEGRA30_AHUB_TXCIF_I2S0_TX0 + codec_info->i2s_id);
522 tegra30_ahub_set_rx_cif_source(i2s->rxcif,
523 TEGRA30_AHUB_TXCIF_DAM0_TX0 + i2s->call_record_dam_ifc);
527 tegra30_dam_enable(i2s->call_record_dam_ifc, TEGRA30_DAM_ENABLE,
529 tegra30_dam_enable(i2s->call_record_dam_ifc, TEGRA30_DAM_ENABLE,
530 TEGRA30_DAM_CHIN0_SRC);
536 static void tegra_max98088_shutdown(struct snd_pcm_substream *substream)
538 struct snd_soc_pcm_runtime *rtd = substream->private_data;
539 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
540 struct tegra30_i2s *i2s = snd_soc_dai_get_drvdata(cpu_dai);
542 if (!i2s->is_dam_used)
545 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
547 tegra30_dam_enable(i2s->dam_ifc, TEGRA30_DAM_DISABLE,
550 /* disconnect the ahub connections*/
551 tegra30_ahub_unset_rx_cif_source(TEGRA30_AHUB_RXCIF_DAM0_RX1 +
554 /* disable the dam and free the controller */
555 tegra30_dam_disable_clock(i2s->dam_ifc);
556 tegra30_dam_free_channel(i2s->dam_ifc, TEGRA30_DAM_CHIN1);
557 i2s->dam_ch_refcount--;
558 if (!i2s->dam_ch_refcount)
559 tegra30_dam_free_controller(i2s->dam_ifc);
562 if (!i2s->is_call_mode_rec)
565 i2s->is_call_mode_rec = 0;
568 tegra30_dam_enable(i2s->call_record_dam_ifc,
569 TEGRA30_DAM_DISABLE, TEGRA30_DAM_CHIN1);
570 tegra30_dam_enable(i2s->call_record_dam_ifc,
571 TEGRA30_DAM_DISABLE, TEGRA30_DAM_CHIN0_SRC);
573 /* disconnect the ahub connections*/
574 tegra30_ahub_unset_rx_cif_source(i2s->rxcif);
575 tegra30_ahub_unset_rx_cif_source(TEGRA30_AHUB_RXCIF_DAM0_RX0 +
576 (i2s->call_record_dam_ifc*2));
577 tegra30_ahub_unset_rx_cif_source(TEGRA30_AHUB_RXCIF_DAM0_RX1 +
578 (i2s->call_record_dam_ifc*2));
580 /* free the dam channels and dam controller */
581 tegra30_dam_disable_clock(i2s->call_record_dam_ifc);
582 tegra30_dam_free_channel(i2s->call_record_dam_ifc,
584 tegra30_dam_free_channel(i2s->call_record_dam_ifc,
585 TEGRA30_DAM_CHIN0_SRC);
586 tegra30_dam_free_controller(i2s->call_record_dam_ifc);
593 static int tegra_voice_call_hw_params(struct snd_pcm_substream *substream,
594 struct snd_pcm_hw_params *params)
596 struct snd_soc_pcm_runtime *rtd = substream->private_data;
597 struct snd_soc_dai *codec_dai = rtd->codec_dai;
598 struct snd_soc_codec *codec = rtd->codec;
599 struct snd_soc_card *card = codec->card;
600 struct tegra_max98088 *machine = snd_soc_card_get_drvdata(card);
604 srate = params_rate(params);
626 err = tegra_asoc_utils_set_rate(&machine->util_data, srate, mclk);
628 if (!(machine->util_data.set_mclk % mclk))
629 mclk = machine->util_data.set_mclk;
631 dev_err(card->dev, "Can't configure clocks\n");
636 tegra_asoc_utils_lock_clk_rate(&machine->util_data, 1);
638 err = snd_soc_dai_set_fmt(codec_dai,
640 SND_SOC_DAIFMT_NB_NF |
641 SND_SOC_DAIFMT_CBS_CFS);
643 dev_err(card->dev, "codec_dai fmt not set\n");
647 err = snd_soc_dai_set_sysclk(codec_dai, 0, mclk,
650 dev_err(card->dev, "codec_dai clock not set\n");
654 #ifndef CONFIG_ARCH_TEGRA_2x_SOC
655 /* codec configuration */
656 machine->codec_info[HIFI_CODEC].rate = params_rate(params);
657 machine->codec_info[HIFI_CODEC].channels = params_channels(params);
658 machine->codec_info[HIFI_CODEC].bitsize = 16;
659 machine->codec_info[HIFI_CODEC].is_i2smaster = 1;
660 machine->codec_info[HIFI_CODEC].is_format_dsp = 0;
662 /* baseband configuration */
663 machine->codec_info[BASEBAND].bitsize = 16;
664 machine->codec_info[BASEBAND].is_i2smaster = 1;
665 machine->codec_info[BASEBAND].is_format_dsp = 1;
668 machine->is_device_bt = 0;
673 static void tegra_voice_call_shutdown(struct snd_pcm_substream *substream)
675 struct snd_soc_pcm_runtime *rtd = substream->private_data;
676 struct tegra_max98088 *machine =
677 snd_soc_card_get_drvdata(rtd->codec->card);
679 #ifndef CONFIG_ARCH_TEGRA_2x_SOC
680 machine->codec_info[HIFI_CODEC].rate = 0;
681 machine->codec_info[HIFI_CODEC].channels = 0;
687 static int tegra_bt_voice_call_hw_params(struct snd_pcm_substream *substream,
688 struct snd_pcm_hw_params *params)
690 struct snd_soc_pcm_runtime *rtd = substream->private_data;
691 struct snd_soc_card *card = rtd->card;
692 struct tegra_max98088 *machine = snd_soc_card_get_drvdata(card);
693 int err, srate, mclk, min_mclk;
695 srate = params_rate(params);
714 min_mclk = 64 * srate;
716 err = tegra_asoc_utils_set_rate(&machine->util_data, srate, mclk);
718 if (!(machine->util_data.set_mclk % min_mclk))
719 mclk = machine->util_data.set_mclk;
721 dev_err(card->dev, "Can't configure clocks\n");
726 tegra_asoc_utils_lock_clk_rate(&machine->util_data, 1);
728 #ifndef CONFIG_ARCH_TEGRA_2x_SOC
729 /* codec configuration */
730 machine->codec_info[BT_SCO].rate = params_rate(params);
731 machine->codec_info[BT_SCO].channels = params_channels(params);
732 machine->codec_info[BT_SCO].bitsize = 16;
733 machine->codec_info[BT_SCO].is_i2smaster = 1;
734 machine->codec_info[BT_SCO].is_format_dsp = 1;
736 /* baseband configuration */
737 machine->codec_info[BASEBAND].bitsize = 16;
738 machine->codec_info[BASEBAND].is_i2smaster = 1;
739 machine->codec_info[BASEBAND].is_format_dsp = 1;
742 machine->is_device_bt = 1;
747 static void tegra_bt_voice_call_shutdown(struct snd_pcm_substream *substream)
749 struct snd_soc_pcm_runtime *rtd = substream->private_data;
750 struct tegra_max98088 *machine =
751 snd_soc_card_get_drvdata(rtd->codec->card);
753 #ifndef CONFIG_ARCH_TEGRA_2x_SOC
754 machine->codec_info[BT_SCO].rate = 0;
755 machine->codec_info[BT_SCO].channels = 0;
761 static struct snd_soc_ops tegra_max98088_ops = {
762 .hw_params = tegra_max98088_hw_params,
763 .hw_free = tegra_hw_free,
764 #ifndef CONFIG_ARCH_TEGRA_2x_SOC
765 .startup = tegra_max98088_startup,
766 .shutdown = tegra_max98088_shutdown,
770 static struct snd_soc_ops tegra_spdif_ops = {
771 .hw_params = tegra_spdif_hw_params,
772 .hw_free = tegra_hw_free,
775 static struct snd_soc_ops tegra_voice_call_ops = {
776 .hw_params = tegra_voice_call_hw_params,
777 .shutdown = tegra_voice_call_shutdown,
778 .hw_free = tegra_hw_free,
781 static struct snd_soc_ops tegra_bt_voice_call_ops = {
782 .hw_params = tegra_bt_voice_call_hw_params,
783 .shutdown = tegra_bt_voice_call_shutdown,
784 .hw_free = tegra_hw_free,
787 static struct snd_soc_ops tegra_bt_ops = {
788 .hw_params = tegra_bt_hw_params,
789 .hw_free = tegra_hw_free,
790 #ifndef CONFIG_ARCH_TEGRA_2x_SOC
791 .startup = tegra_max98088_startup,
792 .shutdown = tegra_max98088_shutdown,
796 static struct snd_soc_jack tegra_max98088_hp_jack;
799 static struct switch_dev wired_switch_dev = {
803 /* These values are copied from WiredAccessoryObserver */
806 BIT_HEADSET = (1 << 0),
807 BIT_HEADSET_NO_MIC = (1 << 1),
810 static int headset_switch_notify(struct notifier_block *self,
811 unsigned long action, void *dev)
816 case SND_JACK_HEADPHONE:
817 state |= BIT_HEADSET_NO_MIC;
819 case SND_JACK_HEADSET:
820 state |= BIT_HEADSET;
823 state |= BIT_NO_HEADSET;
826 switch_set_state(&wired_switch_dev, state);
831 static struct notifier_block headset_switch_nb = {
832 .notifier_call = headset_switch_notify,
835 static struct snd_soc_jack_pin tegra_max98088_hp_jack_pins[] = {
837 .pin = "Headphone Jack",
838 .mask = SND_JACK_HEADPHONE,
843 static int tegra_max98088_event_int_spk(struct snd_soc_dapm_widget *w,
844 struct snd_kcontrol *k, int event)
846 struct snd_soc_dapm_context *dapm = w->dapm;
847 struct snd_soc_card *card = dapm->card;
848 struct tegra_max98088 *machine = snd_soc_card_get_drvdata(card);
849 struct tegra_asoc_platform_data *pdata = machine->pdata;
851 if (!(machine->gpio_requested & GPIO_SPKR_EN))
854 gpio_set_value_cansleep(pdata->gpio_spkr_en,
855 SND_SOC_DAPM_EVENT_ON(event));
860 static int tegra_max98088_event_hp(struct snd_soc_dapm_widget *w,
861 struct snd_kcontrol *k, int event)
863 struct snd_soc_dapm_context *dapm = w->dapm;
864 struct snd_soc_card *card = dapm->card;
865 struct tegra_max98088 *machine = snd_soc_card_get_drvdata(card);
866 struct tegra_asoc_platform_data *pdata = machine->pdata;
868 if (!(machine->gpio_requested & GPIO_HP_MUTE))
871 gpio_set_value_cansleep(pdata->gpio_hp_mute,
872 !SND_SOC_DAPM_EVENT_ON(event));
877 static const struct snd_soc_dapm_widget tegra_max98088_dapm_widgets[] = {
878 SND_SOC_DAPM_SPK("Int Spk", tegra_max98088_event_int_spk),
879 SND_SOC_DAPM_OUTPUT("Earpiece"),
880 SND_SOC_DAPM_HP("Headphone Jack", tegra_max98088_event_hp),
881 SND_SOC_DAPM_MIC("Mic Jack", NULL),
882 SND_SOC_DAPM_INPUT("Int Mic"),
885 static const struct snd_soc_dapm_route enterprise_audio_map[] = {
886 {"Int Spk", NULL, "SPKL"},
887 {"Int Spk", NULL, "SPKR"},
888 {"Earpiece", NULL, "RECL"},
889 {"Earpiece", NULL, "RECR"},
890 {"Headphone Jack", NULL, "HPL"},
891 {"Headphone Jack", NULL, "HPR"},
892 {"MICBIAS", NULL, "Mic Jack"},
893 {"MIC2", NULL, "MICBIAS"},
894 {"MICBIAS", NULL, "Int Mic"},
895 {"MIC1", NULL, "MICBIAS"},
898 static const struct snd_kcontrol_new tegra_max98088_controls[] = {
899 SOC_DAPM_PIN_SWITCH("Int Spk"),
900 SOC_DAPM_PIN_SWITCH("Earpiece"),
901 SOC_DAPM_PIN_SWITCH("Headphone Jack"),
902 SOC_DAPM_PIN_SWITCH("Mic Jack"),
903 SOC_DAPM_PIN_SWITCH("Int Mic"),
906 static int tegra_max98088_init(struct snd_soc_pcm_runtime *rtd)
908 struct snd_soc_codec *codec = rtd->codec;
909 struct snd_soc_dapm_context *dapm = &codec->dapm;
910 struct snd_soc_card *card = codec->card;
911 struct tegra_max98088 *machine = snd_soc_card_get_drvdata(card);
912 struct tegra_asoc_platform_data *pdata = machine->pdata;
913 #ifndef CONFIG_ARCH_TEGRA_2x_SOC
914 struct tegra30_i2s *i2s = snd_soc_dai_get_drvdata(rtd->cpu_dai);
918 #ifndef CONFIG_ARCH_TEGRA_2x_SOC
919 if (machine->codec_info[BASEBAND].i2s_id != -1)
920 i2s->is_dam_used = true;
923 if (machine->init_done)
926 machine->init_done = true;
928 machine->pcard = card;
929 machine->bias_level = SND_SOC_BIAS_STANDBY;
930 machine->clock_enabled = 1;
932 if (gpio_is_valid(pdata->gpio_spkr_en)) {
933 ret = gpio_request(pdata->gpio_spkr_en, "spkr_en");
935 dev_err(card->dev, "cannot get spkr_en gpio\n");
938 machine->gpio_requested |= GPIO_SPKR_EN;
940 gpio_direction_output(pdata->gpio_spkr_en, 0);
943 if (gpio_is_valid(pdata->gpio_hp_mute)) {
944 ret = gpio_request(pdata->gpio_hp_mute, "hp_mute");
946 dev_err(card->dev, "cannot get hp_mute gpio\n");
949 machine->gpio_requested |= GPIO_HP_MUTE;
951 gpio_direction_output(pdata->gpio_hp_mute, 0);
954 if (gpio_is_valid(pdata->gpio_int_mic_en)) {
955 ret = gpio_request(pdata->gpio_int_mic_en, "int_mic_en");
957 dev_err(card->dev, "cannot get int_mic_en gpio\n");
960 machine->gpio_requested |= GPIO_INT_MIC_EN;
962 /* Disable int mic; enable signal is active-high */
963 gpio_direction_output(pdata->gpio_int_mic_en, 0);
966 if (gpio_is_valid(pdata->gpio_ext_mic_en)) {
967 ret = gpio_request(pdata->gpio_ext_mic_en, "ext_mic_en");
969 dev_err(card->dev, "cannot get ext_mic_en gpio\n");
972 machine->gpio_requested |= GPIO_EXT_MIC_EN;
974 /* Enable ext mic; enable signal is active-low */
975 gpio_direction_output(pdata->gpio_ext_mic_en, 0);
978 ret = snd_soc_add_card_controls(card, tegra_max98088_controls,
979 ARRAY_SIZE(tegra_max98088_controls));
983 snd_soc_dapm_new_controls(dapm, tegra_max98088_dapm_widgets,
984 ARRAY_SIZE(tegra_max98088_dapm_widgets));
986 snd_soc_dapm_add_routes(dapm, enterprise_audio_map,
987 ARRAY_SIZE(enterprise_audio_map));
989 ret = snd_soc_jack_new(codec, "Headset Jack", SND_JACK_HEADSET,
990 &tegra_max98088_hp_jack);
995 snd_soc_jack_notifier_register(&tegra_max98088_hp_jack,
997 #else /*gpio based headset detection*/
998 snd_soc_jack_add_pins(&tegra_max98088_hp_jack,
999 ARRAY_SIZE(tegra_max98088_hp_jack_pins),
1000 tegra_max98088_hp_jack_pins);
1003 max98088_headset_detect(codec, &tegra_max98088_hp_jack,
1006 /* Add call mode switch control */
1007 ret = snd_ctl_add(codec->card->snd_card,
1008 snd_ctl_new1(&tegra_call_mode_control, machine));
1012 ret = tegra_asoc_utils_register_ctls(&machine->util_data);
1016 snd_soc_dapm_nc_pin(dapm, "INA1");
1017 snd_soc_dapm_nc_pin(dapm, "INA2");
1018 snd_soc_dapm_nc_pin(dapm, "INB1");
1019 snd_soc_dapm_nc_pin(dapm, "INB2");
1020 snd_soc_dapm_sync(dapm);
1025 static struct snd_soc_dai_link tegra_max98088_dai[NUM_DAI_LINKS] = {
1028 .stream_name = "MAX98088 HIFI",
1029 .codec_name = "max98088.0-0010",
1030 .platform_name = "tegra-pcm-audio",
1031 .codec_dai_name = "HiFi",
1032 .init = tegra_max98088_init,
1033 .ops = &tegra_max98088_ops,
1035 [DAI_LINK_SPDIF] = {
1037 .stream_name = "SPDIF PCM",
1038 .codec_name = "spdif-dit.0",
1039 .platform_name = "tegra-pcm-audio",
1040 .cpu_dai_name = "tegra30-spdif",
1041 .codec_dai_name = "dit-hifi",
1042 .ops = &tegra_spdif_ops,
1044 [DAI_LINK_BTSCO] = {
1046 .stream_name = "BT SCO PCM",
1047 .codec_name = "spdif-dit.1",
1048 .platform_name = "tegra-pcm-audio",
1049 .codec_dai_name = "dit-hifi",
1050 .init = tegra_max98088_init,
1051 .ops = &tegra_bt_ops,
1053 [DAI_LINK_VOICE_CALL] = {
1054 .name = "VOICE CALL",
1055 .stream_name = "VOICE CALL PCM",
1056 .codec_name = "max98088.0-0010",
1057 .platform_name = "tegra-pcm-audio",
1058 .cpu_dai_name = "dit-hifi",
1059 .codec_dai_name = "HiFi",
1060 .ops = &tegra_voice_call_ops,
1062 [DAI_LINK_BT_VOICE_CALL] = {
1063 .name = "BT VOICE CALL",
1064 .stream_name = "BT VOICE CALL PCM",
1065 .codec_name = "spdif-dit.2",
1066 .platform_name = "tegra-pcm-audio",
1067 .cpu_dai_name = "dit-hifi",
1068 .codec_dai_name = "dit-hifi",
1069 .ops = &tegra_bt_voice_call_ops,
1073 static int tegra30_soc_set_bias_level(struct snd_soc_card *card,
1074 struct snd_soc_dapm_context *dapm,
1075 enum snd_soc_bias_level level)
1077 struct tegra_max98088 *machine = snd_soc_card_get_drvdata(card);
1079 if (machine->bias_level == SND_SOC_BIAS_OFF &&
1080 level != SND_SOC_BIAS_OFF && (!machine->clock_enabled)) {
1081 machine->clock_enabled = 1;
1082 tegra_asoc_utils_clk_enable(&machine->util_data);
1083 machine->bias_level = level;
1089 static int tegra30_soc_set_bias_level_post(struct snd_soc_card *card,
1090 struct snd_soc_dapm_context *dapm,
1091 enum snd_soc_bias_level level)
1093 struct tegra_max98088 *machine = snd_soc_card_get_drvdata(card);
1095 if (machine->bias_level != SND_SOC_BIAS_OFF &&
1096 level == SND_SOC_BIAS_OFF && (machine->clock_enabled)) {
1097 machine->clock_enabled = 0;
1098 tegra_asoc_utils_clk_disable(&machine->util_data);
1101 machine->bias_level = level;
1106 static struct snd_soc_card snd_soc_tegra_max98088 = {
1107 .name = "tegra-max98088",
1108 .owner = THIS_MODULE,
1109 .dai_link = tegra_max98088_dai,
1110 .num_links = ARRAY_SIZE(tegra_max98088_dai),
1111 .set_bias_level = tegra30_soc_set_bias_level,
1112 .set_bias_level_post = tegra30_soc_set_bias_level_post,
1115 static __devinit int tegra_max98088_driver_probe(struct platform_device *pdev)
1117 struct snd_soc_card *card = &snd_soc_tegra_max98088;
1118 struct tegra_max98088 *machine;
1119 struct tegra_asoc_platform_data *pdata;
1122 pdata = pdev->dev.platform_data;
1124 dev_err(&pdev->dev, "No platform data supplied\n");
1128 machine = kzalloc(sizeof(struct tegra_max98088), GFP_KERNEL);
1130 dev_err(&pdev->dev, "Can't allocate tegra_max98088 struct\n");
1134 machine->pdata = pdata;
1136 ret = tegra_asoc_utils_init(&machine->util_data, &pdev->dev, card);
1138 goto err_free_machine;
1140 card->dev = &pdev->dev;
1141 platform_set_drvdata(pdev, card);
1142 snd_soc_card_set_drvdata(card, machine);
1144 #ifdef CONFIG_SWITCH
1145 /* Add h2w switch class support */
1146 ret = switch_dev_register(&wired_switch_dev);
1148 dev_err(&pdev->dev, "not able to register switch device\n");
1149 goto err_fini_utils;
1153 #ifndef CONFIG_ARCH_TEGRA_2x_SOC
1154 for (i = 0; i < NUM_I2S_DEVICES ; i++)
1155 machine->codec_info[i].i2s_id = pdata->audio_port_id[i];
1157 machine->codec_info[BASEBAND].rate = pdata->baseband_param.rate;
1158 machine->codec_info[BASEBAND].channels = pdata->baseband_param.channels;
1159 machine->codec_info[BASEBAND].is_format_dsp = 0;
1161 if ((pdata->baseband_param.bit_format == TEGRA_DAIFMT_DSP_A) ||
1162 (pdata->baseband_param.bit_format == TEGRA_DAIFMT_DSP_B)) {
1163 machine->codec_info[BASEBAND].is_format_dsp = 1;
1166 tegra_max98088_dai[DAI_LINK_HIFI].cpu_dai_name =
1167 tegra_max98088_i2s_dai_name[machine->codec_info[HIFI_CODEC].i2s_id];
1169 tegra_max98088_dai[DAI_LINK_BTSCO].cpu_dai_name =
1170 tegra_max98088_i2s_dai_name[machine->codec_info[BT_SCO].i2s_id];
1173 card->dapm.idle_bias_off = 1;
1174 ret = snd_soc_register_card(card);
1176 dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n",
1178 goto err_switch_unregister;
1181 if (!card->instantiated) {
1182 dev_err(&pdev->dev, "No MAX98088 codec\n");
1183 goto err_unregister_card;
1188 err_unregister_card:
1189 snd_soc_unregister_card(card);
1190 err_switch_unregister:
1191 #ifdef CONFIG_SWITCH
1192 switch_dev_unregister(&wired_switch_dev);
1195 tegra_asoc_utils_fini(&machine->util_data);
1201 static int __devexit tegra_max98088_driver_remove(struct platform_device *pdev)
1203 struct snd_soc_card *card = platform_get_drvdata(pdev);
1204 struct tegra_max98088 *machine = snd_soc_card_get_drvdata(card);
1205 struct tegra_asoc_platform_data *pdata = machine->pdata;
1207 snd_soc_unregister_card(card);
1209 #ifdef CONFIG_SWITCH
1210 switch_dev_unregister(&wired_switch_dev);
1213 tegra_asoc_utils_fini(&machine->util_data);
1215 if (machine->gpio_requested & GPIO_EXT_MIC_EN)
1216 gpio_free(pdata->gpio_ext_mic_en);
1217 if (machine->gpio_requested & GPIO_INT_MIC_EN)
1218 gpio_free(pdata->gpio_int_mic_en);
1219 if (machine->gpio_requested & GPIO_HP_MUTE)
1220 gpio_free(pdata->gpio_hp_mute);
1221 if (machine->gpio_requested & GPIO_SPKR_EN)
1222 gpio_free(pdata->gpio_spkr_en);
1229 static struct platform_driver tegra_max98088_driver = {
1232 .owner = THIS_MODULE,
1233 .pm = &snd_soc_pm_ops,
1235 .probe = tegra_max98088_driver_probe,
1236 .remove = __devexit_p(tegra_max98088_driver_remove),
1239 static int __init tegra_max98088_modinit(void)
1241 return platform_driver_register(&tegra_max98088_driver);
1243 module_init(tegra_max98088_modinit);
1245 static void __exit tegra_max98088_modexit(void)
1247 platform_driver_unregister(&tegra_max98088_driver);
1249 module_exit(tegra_max98088_modexit);
1251 MODULE_AUTHOR("Sumit Bhattacharya <sumitb@nvidia.com>");
1252 MODULE_DESCRIPTION("Tegra+MAX98088 machine ASoC driver");
1253 MODULE_LICENSE("GPL");
1254 MODULE_ALIAS("platform:" DRV_NAME);