4 * Copyright (c) 2011 Samsung Electronics Co. Ltd
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version.
11 #include <linux/platform_device.h>
12 #include <linux/clk.h>
14 #include <linux/gpio.h>
15 #include <linux/delay.h>
16 #include <linux/slab.h>
17 #include <linux/workqueue.h>
18 #include <linux/input.h>
19 #include <linux/wakelock.h>
20 #include <linux/suspend.h>
22 #include <sound/soc.h>
23 #include <sound/soc-dapm.h>
24 #include <sound/pcm.h>
25 #include <sound/pcm_params.h>
26 #include <sound/jack.h>
28 #include <mach/regs-clock.h>
30 #include <mach/midas-sound.h>
31 #ifdef CONFIG_MACH_GC1
32 #include <mach/gc1-jack.h>
35 #include <linux/mfd/wm8994/core.h>
36 #include <linux/mfd/wm8994/registers.h>
37 #include <linux/mfd/wm8994/pdata.h>
38 #include <linux/mfd/wm8994/gpio.h>
40 #if defined(CONFIG_SND_USE_MUIC_SWITCH)
41 #include <linux/mfd/max77693-private.h>
46 #include "s3c-i2s-v2.h"
47 #include "../codecs/wm8994.h"
50 #define MIDAS_DEFAULT_MCLK1 24000000
51 #define MIDAS_DEFAULT_MCLK2 32768
52 #define MIDAS_DEFAULT_SYNC_CLK 11289600
54 #define WM1811_JACKDET_MODE_NONE 0x0000
55 #define WM1811_JACKDET_MODE_JACK 0x0100
56 #define WM1811_JACKDET_MODE_MIC 0x0080
57 #define WM1811_JACKDET_MODE_AUDIO 0x0180
59 #define WM1811_JACKDET_BTN0 0x04
60 #define WM1811_JACKDET_BTN1 0x10
61 #define WM1811_JACKDET_BTN2 0x08
64 static struct wm8958_micd_rate midas_det_rates[] = {
65 { MIDAS_DEFAULT_MCLK2, true, 0, 0 },
66 { MIDAS_DEFAULT_MCLK2, false, 0, 0 },
67 { MIDAS_DEFAULT_SYNC_CLK, true, 7, 7 },
68 { MIDAS_DEFAULT_SYNC_CLK, false, 7, 7 },
71 static struct wm8958_micd_rate midas_jackdet_rates[] = {
72 { MIDAS_DEFAULT_MCLK2, true, 0, 0 },
73 { MIDAS_DEFAULT_MCLK2, false, 0, 0 },
74 { MIDAS_DEFAULT_SYNC_CLK, true, 12, 12 },
75 { MIDAS_DEFAULT_SYNC_CLK, false, 7, 8 },
79 const char *aif2_mode_text[] = {
83 static int kpcs_mode = 2;
84 const char *kpcs_mode_text[] = {
88 static int input_clamp;
89 const char *input_clamp_text[] = {
93 static int lineout_mode;
94 const char *lineout_mode_text[] = {
98 #ifndef CONFIG_SEC_DEV_JACK
99 /* To support PBA function test */
100 static struct class *jack_class;
101 static struct device *jack_dev;
104 #ifdef SND_USE_BIAS_LEVEL
105 static bool midas_fll1_active;
106 struct snd_soc_dai *midas_aif1_dai;
109 struct wm1811_machine_priv {
110 struct snd_soc_jack jack;
111 struct snd_soc_codec *codec;
112 struct delayed_work mic_work;
113 struct wake_lock jackdet_wake_lock;
116 #ifdef CONFIG_MACH_GC1
117 static struct snd_soc_codec *wm1811_codec;
119 void set_wm1811_micbias2(bool on)
121 if (wm1811_codec == NULL) {
122 pr_err(KERN_ERR "WM1811 MICBIAS2 set error!\n");
127 snd_soc_update_bits(wm1811_codec, WM8994_POWER_MANAGEMENT_1,
128 WM8994_MICB2_ENA, WM8994_MICB2_ENA);
130 snd_soc_update_bits(wm1811_codec, WM8994_POWER_MANAGEMENT_1,
131 WM8994_MICB2_ENA, 0);
136 EXPORT_SYMBOL(set_wm1811_micbias2);
139 static void midas_gpio_init(void)
142 #ifdef CONFIG_SND_SOC_USE_EXTERNAL_MIC_BIAS
143 /* Main Microphone BIAS */
144 err = gpio_request(GPIO_MIC_BIAS_EN, "MAIN MIC");
146 pr_err(KERN_ERR "MIC_BIAS_EN GPIO set error!\n");
149 gpio_direction_output(GPIO_MIC_BIAS_EN, 1);
150 gpio_set_value(GPIO_MIC_BIAS_EN, 0);
151 gpio_free(GPIO_MIC_BIAS_EN);
154 #ifdef CONFIG_SND_USE_SUB_MIC
155 /* Sub Microphone BIAS */
156 err = gpio_request(GPIO_SUB_MIC_BIAS_EN, "SUB MIC");
158 pr_err(KERN_ERR "SUB_MIC_BIAS_EN GPIO set error!\n");
161 gpio_direction_output(GPIO_SUB_MIC_BIAS_EN, 1);
162 gpio_set_value(GPIO_SUB_MIC_BIAS_EN, 0);
163 gpio_free(GPIO_SUB_MIC_BIAS_EN);
166 #ifdef CONFIG_SND_USE_THIRD_MIC
167 /* Third Microphone BIAS */
168 err = gpio_request(GPIO_THIRD_MIC_BIAS_EN, "THIRD MIC");
170 pr_err(KERN_ERR "THIRD_MIC_BIAS_EN GPIO set error!\n");
173 gpio_direction_output(GPIO_THIRD_MIC_BIAS_EN, 1);
174 gpio_set_value(GPIO_THIRD_MIC_BIAS_EN, 0);
175 gpio_free(GPIO_THIRD_MIC_BIAS_EN);
178 #ifdef CONFIG_FM_RADIO
179 /* FM/Third Mic GPIO */
180 err = gpio_request(GPIO_FM_MIC_SW, "GPL0");
182 pr_err(KERN_ERR "FM/THIRD_MIC Switch GPIO set error!\n");
185 gpio_direction_output(GPIO_FM_MIC_SW, 1);
186 gpio_set_value(GPIO_FM_MIC_SW, 0);
187 gpio_free(GPIO_FM_MIC_SW);
190 #ifdef CONFIG_SND_USE_LINEOUT_SWITCH
191 err = gpio_request(GPIO_LINEOUT_EN, "LINEOUT_EN");
193 pr_err(KERN_ERR "LINEOUT_EN GPIO set error!\n");
196 gpio_direction_output(GPIO_LINEOUT_EN, 1);
197 gpio_set_value(GPIO_LINEOUT_EN, 0);
198 gpio_free(GPIO_LINEOUT_EN);
202 static const struct soc_enum lineout_mode_enum[] = {
203 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(lineout_mode_text), lineout_mode_text),
206 static int get_lineout_mode(struct snd_kcontrol *kcontrol,
207 struct snd_ctl_elem_value *ucontrol)
209 ucontrol->value.integer.value[0] = lineout_mode;
213 static int set_lineout_mode(struct snd_kcontrol *kcontrol,
214 struct snd_ctl_elem_value *ucontrol)
216 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
218 lineout_mode = ucontrol->value.integer.value[0];
219 dev_dbg(codec->dev, "set lineout mode : %s\n",
220 lineout_mode_text[lineout_mode]);
224 static const struct soc_enum aif2_mode_enum[] = {
225 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(aif2_mode_text), aif2_mode_text),
228 static const struct soc_enum kpcs_mode_enum[] = {
229 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(kpcs_mode_text), kpcs_mode_text),
232 static const struct soc_enum input_clamp_enum[] = {
233 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(input_clamp_text), input_clamp_text),
236 static int get_aif2_mode(struct snd_kcontrol *kcontrol,
237 struct snd_ctl_elem_value *ucontrol)
239 ucontrol->value.integer.value[0] = aif2_mode;
243 static int set_aif2_mode(struct snd_kcontrol *kcontrol,
244 struct snd_ctl_elem_value *ucontrol)
246 if (aif2_mode == ucontrol->value.integer.value[0])
249 aif2_mode = ucontrol->value.integer.value[0];
251 pr_info("set aif2 mode : %s\n", aif2_mode_text[aif2_mode]);
256 static int get_kpcs_mode(struct snd_kcontrol *kcontrol,
257 struct snd_ctl_elem_value *ucontrol)
259 ucontrol->value.integer.value[0] = kpcs_mode;
263 static int set_kpcs_mode(struct snd_kcontrol *kcontrol,
264 struct snd_ctl_elem_value *ucontrol)
267 kpcs_mode = ucontrol->value.integer.value[0];
269 pr_info("set kpcs mode : %d\n", kpcs_mode);
274 static int get_input_clamp(struct snd_kcontrol *kcontrol,
275 struct snd_ctl_elem_value *ucontrol)
277 ucontrol->value.integer.value[0] = input_clamp;
281 static int set_input_clamp(struct snd_kcontrol *kcontrol,
282 struct snd_ctl_elem_value *ucontrol)
284 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
286 input_clamp = ucontrol->value.integer.value[0];
289 snd_soc_update_bits(codec, WM8994_INPUT_MIXER_1,
290 WM8994_INPUTS_CLAMP, WM8994_INPUTS_CLAMP);
293 snd_soc_update_bits(codec, WM8994_INPUT_MIXER_1,
294 WM8994_INPUTS_CLAMP, 0);
296 pr_info("set fm input_clamp : %s\n", input_clamp_text[input_clamp]);
302 static int midas_ext_micbias(struct snd_soc_dapm_widget *w,
303 struct snd_kcontrol *kcontrol, int event)
305 struct snd_soc_codec *codec = w->codec;
307 dev_dbg(codec->dev, "%s event is %02X", w->name, event);
309 #ifdef CONFIG_SND_SOC_USE_EXTERNAL_MIC_BIAS
311 case SND_SOC_DAPM_PRE_PMU:
312 gpio_set_value(GPIO_MIC_BIAS_EN, 1);
315 case SND_SOC_DAPM_POST_PMD:
316 gpio_set_value(GPIO_MIC_BIAS_EN, 0);
323 static int midas_ext_submicbias(struct snd_soc_dapm_widget *w,
324 struct snd_kcontrol *kcontrol, int event)
326 struct snd_soc_codec *codec = w->codec;
328 dev_dbg(codec->dev, "%s event is %02X", w->name, event);
330 #ifdef CONFIG_SND_USE_SUB_MIC
332 case SND_SOC_DAPM_PRE_PMU:
333 gpio_set_value(GPIO_SUB_MIC_BIAS_EN, 1);
336 case SND_SOC_DAPM_POST_PMD:
337 gpio_set_value(GPIO_SUB_MIC_BIAS_EN, 0);
344 static int midas_ext_thirdmicbias(struct snd_soc_dapm_widget *w,
345 struct snd_kcontrol *kcontrol, int event)
347 struct snd_soc_codec *codec = w->codec;
349 dev_dbg(codec->dev, "%s event is %02X", w->name, event);
351 #ifdef CONFIG_SND_USE_THIRD_MIC
353 case SND_SOC_DAPM_PRE_PMU:
354 gpio_set_value(GPIO_THIRD_MIC_BIAS_EN, 1);
356 case SND_SOC_DAPM_POST_PMD:
357 gpio_set_value(GPIO_THIRD_MIC_BIAS_EN, 0);
365 * midas_ext_spkmode :
366 * For phone device have 1 external speaker
367 * should mix LR data in a speaker mixer (mono setting)
369 static int midas_ext_spkmode(struct snd_soc_dapm_widget *w,
370 struct snd_kcontrol *kcontrol, int event)
373 #ifndef CONFIG_SND_USE_STEREO_SPEAKER
374 struct snd_soc_codec *codec = w->codec;
376 ret = snd_soc_update_bits(codec, WM8994_SPKOUT_MIXERS,
377 WM8994_SPKMIXR_TO_SPKOUTL_MASK,
378 WM8994_SPKMIXR_TO_SPKOUTL);
383 static int midas_lineout_switch(struct snd_soc_dapm_widget *w,
384 struct snd_kcontrol *kcontrol, int event)
386 struct snd_soc_codec *codec = w->codec;
388 dev_dbg(codec->dev, "%s event is %02X", w->name, event);
390 #if defined(CONFIG_SND_USE_MUIC_SWITCH)
392 case SND_SOC_DAPM_POST_PMU:
394 max77693_muic_set_audio_switch(1);
396 case SND_SOC_DAPM_PRE_PMD:
397 max77693_muic_set_audio_switch(0);
402 #ifdef CONFIG_SND_USE_LINEOUT_SWITCH
404 case SND_SOC_DAPM_POST_PMU:
405 gpio_set_value(GPIO_LINEOUT_EN, 1);
407 case SND_SOC_DAPM_PRE_PMD:
408 gpio_set_value(GPIO_LINEOUT_EN, 0);
415 static void midas_micd_set_rate(struct snd_soc_codec *codec)
417 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
418 int best, i, sysclk, val;
420 const struct wm8958_micd_rate *rates = NULL;
423 idle = !wm8994->jack_mic;
425 sysclk = snd_soc_read(codec, WM8994_CLOCKING_1);
426 if (sysclk & WM8994_SYSCLK_SRC)
427 sysclk = wm8994->aifclk[1];
429 sysclk = wm8994->aifclk[0];
431 if (wm8994->jackdet) {
432 rates = midas_jackdet_rates;
433 num_rates = ARRAY_SIZE(midas_jackdet_rates);
434 wm8994->pdata->micd_rates = midas_jackdet_rates;
435 wm8994->pdata->num_micd_rates = num_rates;
437 rates = midas_det_rates;
438 num_rates = ARRAY_SIZE(midas_det_rates);
439 wm8994->pdata->micd_rates = midas_det_rates;
440 wm8994->pdata->num_micd_rates = num_rates;
444 for (i = 0; i < num_rates; i++) {
445 if (rates[i].idle != idle)
447 if (abs(rates[i].sysclk - sysclk) <
448 abs(rates[best].sysclk - sysclk))
450 else if (rates[best].idle != idle)
454 val = rates[best].start << WM8958_MICD_BIAS_STARTTIME_SHIFT
455 | rates[best].rate << WM8958_MICD_RATE_SHIFT;
457 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
458 WM8958_MICD_BIAS_STARTTIME_MASK |
459 WM8958_MICD_RATE_MASK, val);
462 #ifdef SND_USE_BIAS_LEVEL
463 static void midas_start_fll1(struct snd_soc_dai *aif1_dai)
466 if (midas_fll1_active)
469 dev_info(aif1_dai->dev, "Moving to audio clocking settings\n");
471 /* Switch AIF1 to MCLK2 while we bring stuff up */
472 ret = snd_soc_dai_set_sysclk(aif1_dai, WM8994_SYSCLK_MCLK2,
473 MIDAS_DEFAULT_MCLK2, SND_SOC_CLOCK_IN);
475 dev_err(aif1_dai->dev, "Unable to switch to MCLK2: %d\n", ret);
477 /* Start the 24MHz clock to provide a high frequency reference to
478 * provide a high frequency reference for the FLL, giving improved
481 midas_snd_set_mclk(true, true);
484 ret = snd_soc_dai_set_pll(aif1_dai, WM8994_FLL1,
485 WM8994_FLL_SRC_MCLK1, MIDAS_DEFAULT_MCLK1,
486 MIDAS_DEFAULT_SYNC_CLK);
488 dev_err(aif1_dai->dev, "Unable to start FLL1: %d\n", ret);
490 /* Then switch AIF1CLK to it */
491 ret = snd_soc_dai_set_sysclk(aif1_dai, WM8994_SYSCLK_FLL1,
492 MIDAS_DEFAULT_SYNC_CLK, SND_SOC_CLOCK_IN);
494 dev_err(aif1_dai->dev, "Unable to switch to FLL1: %d\n", ret);
496 midas_fll1_active = true;
500 static void midas_micdet(u16 status, void *data)
502 struct wm1811_machine_priv *wm1811 = data;
503 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(wm1811->codec);
507 wake_lock_timeout(&wm1811->jackdet_wake_lock, 5 * HZ);
509 /* Either nothing present or just starting detection */
510 if (!(status & WM8958_MICD_STS)) {
511 if (!wm8994->jackdet) {
512 /* If nothing present then clear our statuses */
513 dev_dbg(wm1811->codec->dev, "Detected open circuit\n");
514 wm8994->jack_mic = false;
515 wm8994->mic_detecting = true;
517 midas_micd_set_rate(wm1811->codec);
519 snd_soc_jack_report(wm8994->micdet[0].jack, 0,
527 /* If the measurement is showing a high impedence we've got a
530 if (wm8994->mic_detecting && (status & 0x400)) {
531 dev_info(wm1811->codec->dev, "Detected microphone\n");
533 wm8994->mic_detecting = false;
534 wm8994->jack_mic = true;
536 midas_micd_set_rate(wm1811->codec);
538 snd_soc_jack_report(wm8994->micdet[0].jack, SND_JACK_HEADSET,
542 #ifdef CONFIG_TARGET_LOCALE_KOR
543 if (wm8994->mic_detecting && status & 0x4
544 && wm8994->jack_mic == false) {
546 if (wm8994->mic_detecting && status & 0x4) {
548 dev_info(wm1811->codec->dev, "Detected headphone\n");
549 wm8994->mic_detecting = false;
550 #ifdef CONFIG_TARGET_LOCALE_KOR
551 wm8994->jack_mic = false;
553 midas_micd_set_rate(wm1811->codec);
555 snd_soc_jack_report(wm8994->micdet[0].jack, SND_JACK_HEADPHONE,
558 /* If we have jackdet that will detect removal */
559 if (wm8994->jackdet) {
560 mutex_lock(&wm8994->accdet_lock);
562 snd_soc_update_bits(wm1811->codec, WM8958_MIC_DETECT_1,
565 if (wm8994->active_refcount) {
566 snd_soc_update_bits(wm1811->codec,
568 WM1811_JACKDET_MODE_MASK,
569 WM1811_JACKDET_MODE_AUDIO);
572 mutex_unlock(&wm8994->accdet_lock);
574 if (wm8994->pdata->jd_ext_cap) {
575 mutex_lock(&wm1811->codec->mutex);
576 snd_soc_dapm_disable_pin(&wm1811->codec->dapm,
578 snd_soc_dapm_sync(&wm1811->codec->dapm);
579 mutex_unlock(&wm1811->codec->mutex);
584 /* Report short circuit as a button */
585 if (wm8994->jack_mic) {
587 if (status & WM1811_JACKDET_BTN0)
588 report |= SND_JACK_BTN_0;
590 if (status & WM1811_JACKDET_BTN1)
591 report |= SND_JACK_BTN_1;
593 if (status & WM1811_JACKDET_BTN2)
594 report |= SND_JACK_BTN_2;
596 dev_dbg(wm1811->codec->dev, "Detected Button: %08x (%08X)\n",
599 snd_soc_jack_report(wm8994->micdet[0].jack, report,
604 #ifdef CONFIG_SND_SAMSUNG_I2S_MASTER
605 static int set_epll_rate(unsigned long rate)
607 struct clk *fout_epll;
609 fout_epll = clk_get(NULL, "fout_epll");
610 if (IS_ERR(fout_epll)) {
611 printk(KERN_ERR "%s: failed to get fout_epll\n", __func__);
615 if (rate == clk_get_rate(fout_epll))
618 clk_set_rate(fout_epll, rate);
624 #endif /* CONFIG_SND_SAMSUNG_I2S_MASTER */
626 #ifndef CONFIG_SND_SAMSUNG_I2S_MASTER
627 static int midas_wm1811_aif1_hw_params(struct snd_pcm_substream *substream,
628 struct snd_pcm_hw_params *params)
630 struct snd_soc_pcm_runtime *rtd = substream->private_data;
631 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
632 struct snd_soc_dai *codec_dai = rtd->codec_dai;
633 unsigned int pll_out;
636 dev_info(codec_dai->dev, "%s ++\n", __func__);
637 /* AIF1CLK should be >=3MHz for optimal performance */
638 if (params_rate(params) == 8000 || params_rate(params) == 11025)
639 pll_out = params_rate(params) * 512;
641 pll_out = params_rate(params) * 256;
643 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
644 | SND_SOC_DAIFMT_NB_NF
645 | SND_SOC_DAIFMT_CBM_CFM);
649 /* Set the cpu DAI configuration */
650 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S
651 | SND_SOC_DAIFMT_NB_NF
652 | SND_SOC_DAIFMT_CBM_CFM);
656 #ifndef SND_USE_BIAS_LEVEL
658 ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL1,
659 WM8994_FLL_SRC_MCLK1, MIDAS_DEFAULT_MCLK1,
662 dev_err(codec_dai->dev, "Unable to start FLL1: %d\n", ret);
664 ret = snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_FLL1,
665 pll_out, SND_SOC_CLOCK_IN);
667 dev_err(codec_dai->dev, "Unable to switch to FLL1: %d\n", ret);
671 ret = snd_soc_dai_set_sysclk(cpu_dai, SAMSUNG_I2S_OPCLK,
676 midas_start_fll1(codec_dai);
682 dev_info(codec_dai->dev, "%s --\n", __func__);
686 #else /* CONFIG_SND_SAMSUNG_I2S_MASTER */
687 static int midas_wm1811_aif1_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_dai *codec_dai = rtd->codec_dai;
692 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
693 int bfs, psr, rfs, ret;
696 switch (params_format(params)) {
697 case SNDRV_PCM_FORMAT_U24:
698 case SNDRV_PCM_FORMAT_S24:
701 case SNDRV_PCM_FORMAT_U16_LE:
702 case SNDRV_PCM_FORMAT_S16_LE:
709 switch (params_rate(params)) {
738 rclk = params_rate(params) * rfs;
766 printk(KERN_INFO "Not yet supported!\n");
770 set_epll_rate(rclk * psr);
772 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
773 | SND_SOC_DAIFMT_NB_NF
774 | SND_SOC_DAIFMT_CBS_CFS);
778 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S
779 | SND_SOC_DAIFMT_NB_NF
780 | SND_SOC_DAIFMT_CBS_CFS);
784 ret = snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_MCLK1,
785 rclk, SND_SOC_CLOCK_IN);
789 ret = snd_soc_dai_set_sysclk(cpu_dai, SAMSUNG_I2S_CDCLK,
790 0, SND_SOC_CLOCK_OUT);
794 ret = snd_soc_dai_set_clkdiv(cpu_dai, SAMSUNG_I2S_DIV_BCLK, bfs);
800 #endif /* CONFIG_SND_SAMSUNG_I2S_MASTER */
803 * Midas WM1811 DAI operations.
805 static struct snd_soc_ops midas_wm1811_aif1_ops = {
806 .hw_params = midas_wm1811_aif1_hw_params,
809 static int midas_wm1811_aif2_hw_params(struct snd_pcm_substream *substream,
810 struct snd_pcm_hw_params *params)
812 struct snd_soc_pcm_runtime *rtd = substream->private_data;
813 struct snd_soc_dai *codec_dai = rtd->codec_dai;
818 dev_info(codec_dai->dev, "%s ++\n", __func__);
819 prate = params_rate(params);
820 switch (params_rate(params)) {
825 dev_warn(codec_dai->dev, "Unsupported LRCLK %d, falling back to 8000Hz\n",
826 (int)params_rate(params));
830 #if defined(CONFIG_LTE_MODEM_CMC221) || defined(CONFIG_MACH_M0_CTC)
831 #if defined(CONFIG_MACH_C1_KOR_LGT)
832 /* Set the codec DAI configuration */
833 if (aif2_mode == 0) {
835 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
836 | SND_SOC_DAIFMT_NB_NF
837 | SND_SOC_DAIFMT_CBS_CFS);
839 ret = snd_soc_dai_set_fmt(codec_dai,
841 | SND_SOC_DAIFMT_IB_NF
842 | SND_SOC_DAIFMT_CBS_CFS);
844 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
845 | SND_SOC_DAIFMT_NB_NF
846 | SND_SOC_DAIFMT_CBM_CFM);
849 /* Set the codec DAI configuration */
850 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_DSP_A
851 | SND_SOC_DAIFMT_IB_NF
852 | SND_SOC_DAIFMT_CBS_CFS);
854 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_DSP_A
855 | SND_SOC_DAIFMT_IB_NF
856 | SND_SOC_DAIFMT_CBM_CFM);
859 /* Set the codec DAI configuration, aif2_mode:0 is slave */
861 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
862 | SND_SOC_DAIFMT_NB_NF
863 | SND_SOC_DAIFMT_CBS_CFS);
865 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
866 | SND_SOC_DAIFMT_NB_NF
867 | SND_SOC_DAIFMT_CBM_CFM);
873 #if defined(CONFIG_LTE_MODEM_CMC221)
874 if (kpcs_mode == 1) {
888 #elif defined(CONFIG_MACH_M0_CTC)
903 #ifdef SND_USE_BIAS_LEVEL
904 if (!midas_fll1_active)
905 midas_start_fll1(midas_aif1_dai);
908 if (aif2_mode == 0) {
909 ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL2,
913 ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL2,
914 WM8994_FLL_SRC_MCLK1,
915 MIDAS_DEFAULT_MCLK1, prate * 256);
919 dev_err(codec_dai->dev, "Unable to configure FLL2: %d\n", ret);
921 ret = snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_FLL2,
922 prate * 256, SND_SOC_CLOCK_IN);
924 dev_err(codec_dai->dev, "Unable to switch to FLL2: %d\n", ret);
926 dev_info(codec_dai->dev, "%s --\n", __func__);
930 static struct snd_soc_ops midas_wm1811_aif2_ops = {
931 .hw_params = midas_wm1811_aif2_hw_params,
934 static int midas_wm1811_aif3_hw_params(struct snd_pcm_substream *substream,
935 struct snd_pcm_hw_params *params)
937 pr_err("%s: enter\n", __func__);
941 static struct snd_soc_ops midas_wm1811_aif3_ops = {
942 .hw_params = midas_wm1811_aif3_hw_params,
945 static const struct snd_kcontrol_new midas_controls[] = {
946 SOC_DAPM_PIN_SWITCH("HP"),
947 SOC_DAPM_PIN_SWITCH("SPK"),
948 SOC_DAPM_PIN_SWITCH("RCV"),
949 SOC_DAPM_PIN_SWITCH("FM In"),
950 SOC_DAPM_PIN_SWITCH("LINE"),
951 SOC_DAPM_PIN_SWITCH("HDMI"),
952 SOC_DAPM_PIN_SWITCH("Main Mic"),
953 SOC_DAPM_PIN_SWITCH("Sub Mic"),
954 SOC_DAPM_PIN_SWITCH("Third Mic"),
955 SOC_DAPM_PIN_SWITCH("Headset Mic"),
957 SOC_ENUM_EXT("AIF2 Mode", aif2_mode_enum[0],
958 get_aif2_mode, set_aif2_mode),
960 SOC_ENUM_EXT("KPCS Mode", kpcs_mode_enum[0],
961 get_kpcs_mode, set_kpcs_mode),
963 SOC_ENUM_EXT("Input Clamp", input_clamp_enum[0],
964 get_input_clamp, set_input_clamp),
966 SOC_ENUM_EXT("LineoutSwitch Mode", lineout_mode_enum[0],
967 get_lineout_mode, set_lineout_mode),
971 const struct snd_soc_dapm_widget midas_dapm_widgets[] = {
972 SND_SOC_DAPM_HP("HP", NULL),
973 SND_SOC_DAPM_SPK("SPK", midas_ext_spkmode),
974 SND_SOC_DAPM_SPK("RCV", NULL),
975 SND_SOC_DAPM_LINE("LINE", midas_lineout_switch),
976 SND_SOC_DAPM_LINE("HDMI", NULL),
978 SND_SOC_DAPM_MIC("Headset Mic", NULL),
979 SND_SOC_DAPM_MIC("Main Mic", midas_ext_micbias),
980 SND_SOC_DAPM_MIC("Sub Mic", midas_ext_submicbias),
981 SND_SOC_DAPM_MIC("Third Mic", midas_ext_thirdmicbias),
982 SND_SOC_DAPM_LINE("FM In", NULL),
984 SND_SOC_DAPM_INPUT("S5P RP"),
987 const struct snd_soc_dapm_route midas_dapm_routes[] = {
988 { "HP", NULL, "HPOUT1L" },
989 { "HP", NULL, "HPOUT1R" },
991 { "SPK", NULL, "SPKOUTLN" },
992 { "SPK", NULL, "SPKOUTLP" },
993 { "SPK", NULL, "SPKOUTRN" },
994 { "SPK", NULL, "SPKOUTRP" },
996 { "RCV", NULL, "HPOUT2N" },
997 { "RCV", NULL, "HPOUT2P" },
999 { "LINE", NULL, "LINEOUT2N" },
1000 { "LINE", NULL, "LINEOUT2P" },
1002 { "HDMI", NULL, "LINEOUT1N" },
1003 { "HDMI", NULL, "LINEOUT1P" },
1005 { "IN1LP", NULL, "MICBIAS1" },
1006 { "IN1LN", NULL, "MICBIAS1" },
1007 { "MICBIAS1", NULL, "Main Mic" },
1009 { "IN1RP", NULL, "Sub Mic" },
1010 { "IN1RN", NULL, "Sub Mic" },
1012 { "IN2LP:VXRN", NULL, "MICBIAS2" },
1013 { "MICBIAS2", NULL, "Headset Mic" },
1015 { "AIF1DAC1L", NULL, "S5P RP" },
1016 { "AIF1DAC1R", NULL, "S5P RP" },
1018 { "IN2RN", NULL, "FM In" },
1019 { "IN2RP:VXRP", NULL, "FM In" },
1021 { "IN2RN", NULL, "Third Mic" },
1022 { "IN2RP:VXRP", NULL, "Third Mic" },
1025 static struct snd_soc_dai_driver midas_ext_dai[] = {
1033 .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000,
1034 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1041 .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000,
1042 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1052 .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000,
1053 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1060 .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000,
1061 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1066 #ifndef CONFIG_SEC_DEV_JACK
1067 static ssize_t earjack_state_show(struct device *dev,
1068 struct device_attribute *attr, char *buf)
1070 struct snd_soc_codec *codec = dev_get_drvdata(dev);
1071 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
1075 if ((wm8994->micdet[0].jack->status & SND_JACK_HEADPHONE) ||
1076 (wm8994->micdet[0].jack->status & SND_JACK_HEADSET)) {
1080 return sprintf(buf, "%d\n", report);
1083 static ssize_t earjack_state_store(struct device *dev,
1084 struct device_attribute *attr, const char *buf, size_t size)
1086 pr_info("%s : operate nothing\n", __func__);
1091 static ssize_t earjack_key_state_show(struct device *dev,
1092 struct device_attribute *attr, char *buf)
1094 struct snd_soc_codec *codec = dev_get_drvdata(dev);
1095 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
1099 if (wm8994->micdet[0].jack->status & SND_JACK_BTN_0)
1102 return sprintf(buf, "%d\n", report);
1105 static ssize_t earjack_key_state_store(struct device *dev,
1106 struct device_attribute *attr, const char *buf, size_t size)
1108 pr_info("%s : operate nothing\n", __func__);
1113 static ssize_t earjack_select_jack_show(struct device *dev,
1114 struct device_attribute *attr, char *buf)
1116 pr_info("%s : operate nothing\n", __func__);
1121 static ssize_t earjack_select_jack_store(struct device *dev,
1122 struct device_attribute *attr, const char *buf, size_t size)
1124 struct snd_soc_codec *codec = dev_get_drvdata(dev);
1125 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
1127 wm8994->mic_detecting = false;
1128 wm8994->jack_mic = true;
1130 midas_micd_set_rate(codec);
1132 if ((!size) || (buf[0] != '1')) {
1133 snd_soc_jack_report(wm8994->micdet[0].jack,
1134 0, SND_JACK_HEADSET);
1135 dev_info(codec->dev, "Forced remove microphone\n");
1138 snd_soc_jack_report(wm8994->micdet[0].jack,
1139 SND_JACK_HEADSET, SND_JACK_HEADSET);
1140 dev_info(codec->dev, "Forced detect microphone\n");
1146 static ssize_t reselect_jack_show(struct device *dev,
1147 struct device_attribute *attr, char *buf)
1149 pr_info("%s : operate nothing\n", __func__);
1153 static ssize_t reselect_jack_store(struct device *dev,
1154 struct device_attribute *attr, const char *buf, size_t size)
1156 struct snd_soc_codec *codec = dev_get_drvdata(dev);
1157 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
1160 reg = snd_soc_read(codec, WM8958_MIC_DETECT_3);
1162 dev_info(codec->dev, "Detected open circuit\n");
1164 snd_soc_update_bits(codec, WM8958_MICBIAS2,
1165 WM8958_MICB2_DISCH, WM8958_MICB2_DISCH);
1166 /* Enable debounce while removed */
1167 snd_soc_update_bits(codec, WM1811_JACKDET_CTRL,
1168 WM1811_JACKDET_DB, WM1811_JACKDET_DB);
1170 wm8994->mic_detecting = false;
1171 wm8994->jack_mic = false;
1172 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
1173 WM8958_MICD_ENA, 0);
1175 if (wm8994->active_refcount) {
1176 snd_soc_update_bits(codec,
1178 WM1811_JACKDET_MODE_MASK,
1179 WM1811_JACKDET_MODE_AUDIO);
1181 snd_soc_update_bits(codec,
1183 WM1811_JACKDET_MODE_MASK,
1184 WM1811_JACKDET_MODE_JACK);
1187 snd_soc_jack_report(wm8994->micdet[0].jack, 0,
1188 SND_JACK_MECHANICAL | SND_JACK_HEADSET |
1194 static DEVICE_ATTR(reselect_jack, S_IRUGO | S_IWUSR | S_IWGRP,
1195 reselect_jack_show, reselect_jack_store);
1197 static DEVICE_ATTR(select_jack, S_IRUGO | S_IWUSR | S_IWGRP,
1198 earjack_select_jack_show, earjack_select_jack_store);
1200 static DEVICE_ATTR(key_state, S_IRUGO | S_IWUSR | S_IWGRP,
1201 earjack_key_state_show, earjack_key_state_store);
1203 static DEVICE_ATTR(state, S_IRUGO | S_IWUSR | S_IWGRP,
1204 earjack_state_show, earjack_state_store);
1207 static int midas_wm1811_init_paiftx(struct snd_soc_pcm_runtime *rtd)
1209 struct snd_soc_codec *codec = rtd->codec;
1210 struct wm1811_machine_priv *wm1811
1211 = snd_soc_card_get_drvdata(codec->card);
1212 struct snd_soc_dai *aif1_dai = rtd->codec_dai;
1213 struct wm8994 *control = codec->control_data;
1214 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
1217 #ifdef SND_USE_BIAS_LEVEL
1218 midas_aif1_dai = aif1_dai;
1221 #ifdef CONFIG_MACH_GC1
1222 wm1811_codec = codec;
1225 midas_snd_set_mclk(true, false);
1227 rtd->codec_dai->driver->playback.channels_max =
1228 rtd->cpu_dai->driver->playback.channels_max;
1230 ret = snd_soc_add_controls(codec, midas_controls,
1231 ARRAY_SIZE(midas_controls));
1233 ret = snd_soc_dapm_new_controls(&codec->dapm, midas_dapm_widgets,
1234 ARRAY_SIZE(midas_dapm_widgets));
1236 dev_err(codec->dev, "Failed to add DAPM widgets: %d\n", ret);
1238 ret = snd_soc_dapm_add_routes(&codec->dapm, midas_dapm_routes,
1239 ARRAY_SIZE(midas_dapm_routes));
1241 dev_err(codec->dev, "Failed to add DAPM routes: %d\n", ret);
1243 ret = snd_soc_dai_set_sysclk(aif1_dai, WM8994_SYSCLK_MCLK2,
1244 MIDAS_DEFAULT_MCLK2, SND_SOC_CLOCK_IN);
1246 dev_err(codec->dev, "Failed to boot clocking\n");
1248 /* Force AIF1CLK on as it will be master for jack detection */
1249 if (wm8994->revision > 1) {
1250 ret = snd_soc_dapm_force_enable_pin(&codec->dapm, "AIF1CLK");
1252 dev_err(codec->dev, "Failed to enable AIF1CLK: %d\n",
1256 ret = snd_soc_dapm_disable_pin(&codec->dapm, "S5P RP");
1258 dev_err(codec->dev, "Failed to disable S5P RP: %d\n", ret);
1260 snd_soc_dapm_ignore_suspend(&codec->dapm, "RCV");
1261 snd_soc_dapm_ignore_suspend(&codec->dapm, "SPK");
1262 snd_soc_dapm_ignore_suspend(&codec->dapm, "HP");
1263 snd_soc_dapm_ignore_suspend(&codec->dapm, "Headset Mic");
1264 snd_soc_dapm_ignore_suspend(&codec->dapm, "Sub Mic");
1265 snd_soc_dapm_ignore_suspend(&codec->dapm, "Main Mic");
1266 snd_soc_dapm_ignore_suspend(&codec->dapm, "AIF1DACDAT");
1267 snd_soc_dapm_ignore_suspend(&codec->dapm, "AIF2DACDAT");
1268 snd_soc_dapm_ignore_suspend(&codec->dapm, "AIF3DACDAT");
1269 snd_soc_dapm_ignore_suspend(&codec->dapm, "AIF1ADCDAT");
1270 snd_soc_dapm_ignore_suspend(&codec->dapm, "AIF2ADCDAT");
1271 snd_soc_dapm_ignore_suspend(&codec->dapm, "AIF3ADCDAT");
1272 snd_soc_dapm_ignore_suspend(&codec->dapm, "FM In");
1273 snd_soc_dapm_ignore_suspend(&codec->dapm, "LINE");
1274 snd_soc_dapm_ignore_suspend(&codec->dapm, "HDMI");
1275 snd_soc_dapm_ignore_suspend(&codec->dapm, "Third Mic");
1277 wm1811->codec = codec;
1279 midas_micd_set_rate(codec);
1281 #ifdef CONFIG_SEC_DEV_JACK
1282 /* By default use idle_bias_off, will override for WM8994 */
1283 codec->dapm.idle_bias_off = 0;
1284 #else /* CONFIG_SEC_DEV_JACK */
1285 wm1811->jack.status = 0;
1287 ret = snd_soc_jack_new(codec, "Midas Jack",
1288 SND_JACK_HEADSET | SND_JACK_BTN_0 |
1289 SND_JACK_BTN_1 | SND_JACK_BTN_2,
1293 dev_err(codec->dev, "Failed to create jack: %d\n", ret);
1295 ret = snd_jack_set_key(wm1811->jack.jack, SND_JACK_BTN_0, KEY_MEDIA);
1298 dev_err(codec->dev, "Failed to set KEY_MEDIA: %d\n", ret);
1300 ret = snd_jack_set_key(wm1811->jack.jack, SND_JACK_BTN_1,
1303 dev_err(codec->dev, "Failed to set KEY_VOLUMEUP: %d\n", ret);
1305 ret = snd_jack_set_key(wm1811->jack.jack, SND_JACK_BTN_2,
1309 dev_err(codec->dev, "Failed to set KEY_VOLUMEDOWN: %d\n", ret);
1311 if (wm8994->revision > 1) {
1312 dev_info(codec->dev, "wm1811: Rev %c support mic detection\n",
1313 'A' + wm8994->revision);
1314 ret = wm8958_mic_detect(codec, &wm1811->jack, midas_micdet,
1318 dev_err(codec->dev, "Failed start detection: %d\n",
1321 dev_info(codec->dev, "wm1811: Rev %c doesn't support mic detection\n",
1322 'A' + wm8994->revision);
1323 codec->dapm.idle_bias_off = 0;
1325 /* To wakeup for earjack event in suspend mode */
1326 enable_irq_wake(control->irq);
1328 wake_lock_init(&wm1811->jackdet_wake_lock,
1329 WAKE_LOCK_SUSPEND, "midas_jackdet");
1331 /* To support PBA function test */
1332 jack_class = class_create(THIS_MODULE, "audio");
1334 if (IS_ERR(jack_class))
1335 pr_err("Failed to create class\n");
1337 jack_dev = device_create(jack_class, NULL, 0, codec, "earjack");
1339 if (device_create_file(jack_dev, &dev_attr_select_jack) < 0)
1340 pr_err("Failed to create device file (%s)!\n",
1341 dev_attr_select_jack.attr.name);
1343 if (device_create_file(jack_dev, &dev_attr_key_state) < 0)
1344 pr_err("Failed to create device file (%s)!\n",
1345 dev_attr_key_state.attr.name);
1347 if (device_create_file(jack_dev, &dev_attr_state) < 0)
1348 pr_err("Failed to create device file (%s)!\n",
1349 dev_attr_state.attr.name);
1351 if (device_create_file(jack_dev, &dev_attr_reselect_jack) < 0)
1352 pr_err("Failed to create device file (%s)!\n",
1353 dev_attr_reselect_jack.attr.name);
1355 #endif /* CONFIG_SEC_DEV_JACK */
1356 return snd_soc_dapm_sync(&codec->dapm);
1359 static struct snd_soc_dai_link midas_dai[] = {
1360 { /* Sec_Fifo DAI i/f */
1361 .name = "Sec_FIFO TX",
1362 .stream_name = "Sec_Dai",
1363 .cpu_dai_name = "samsung-i2s.4",
1364 .codec_dai_name = "wm8994-aif1",
1365 #ifndef CONFIG_SND_SOC_SAMSUNG_USE_DMA_WRAPPER
1366 .platform_name = "samsung-audio-idma",
1368 .platform_name = "samsung-audio",
1370 .codec_name = "wm8994-codec",
1371 .init = midas_wm1811_init_paiftx,
1372 .ops = &midas_wm1811_aif1_ops,
1375 .name = "Midas_WM1811 Voice",
1376 .stream_name = "Voice Tx/Rx",
1377 .cpu_dai_name = "midas.cp",
1378 .codec_dai_name = "wm8994-aif2",
1379 .platform_name = "snd-soc-dummy",
1380 .codec_name = "wm8994-codec",
1381 .ops = &midas_wm1811_aif2_ops,
1382 .ignore_suspend = 1,
1385 .name = "Midas_WM1811 BT",
1386 .stream_name = "BT Tx/Rx",
1387 .cpu_dai_name = "midas.bt",
1388 .codec_dai_name = "wm8994-aif3",
1389 .platform_name = "snd-soc-dummy",
1390 .codec_name = "wm8994-codec",
1391 .ops = &midas_wm1811_aif3_ops,
1392 .ignore_suspend = 1,
1394 { /* Primary DAI i/f */
1395 .name = "WM8994 AIF1",
1396 .stream_name = "Pri_Dai",
1397 .cpu_dai_name = "samsung-i2s.0",
1398 .codec_dai_name = "wm8994-aif1",
1399 .platform_name = "samsung-audio",
1400 .codec_name = "wm8994-codec",
1401 .ops = &midas_wm1811_aif1_ops,
1405 static int midas_card_suspend_pre(struct snd_soc_card *card)
1407 struct snd_soc_codec *codec = card->rtd->codec;
1408 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
1410 #ifdef CONFIG_SEC_DEV_JACK
1411 snd_soc_dapm_disable_pin(&codec->dapm, "AIF1CLK");
1417 static int midas_card_suspend_post(struct snd_soc_card *card)
1419 struct snd_soc_codec *codec = card->rtd->codec;
1420 struct snd_soc_dai *aif1_dai = card->rtd[0].codec_dai;
1421 struct snd_soc_dai *aif2_dai = card->rtd[1].codec_dai;
1424 if (!codec->active) {
1425 #ifndef SND_USE_BIAS_LEVEL
1426 ret = snd_soc_dai_set_sysclk(aif2_dai,
1427 WM8994_SYSCLK_MCLK2,
1428 MIDAS_DEFAULT_MCLK2,
1432 dev_err(codec->dev, "Unable to switch to MCLK2: %d\n",
1435 ret = snd_soc_dai_set_pll(aif2_dai, WM8994_FLL2, 0, 0, 0);
1438 dev_err(codec->dev, "Unable to stop FLL2\n");
1440 ret = snd_soc_dai_set_sysclk(aif1_dai,
1441 WM8994_SYSCLK_MCLK2,
1442 MIDAS_DEFAULT_MCLK2,
1445 dev_err(codec->dev, "Unable to switch to MCLK2\n");
1447 ret = snd_soc_dai_set_pll(aif1_dai, WM8994_FLL1, 0, 0, 0);
1450 dev_err(codec->dev, "Unable to stop FLL1\n");
1453 midas_snd_set_mclk(false, true);
1456 #ifdef CONFIG_ARCH_EXYNOS5
1457 exynos5_sys_powerdown_xxti_control(midas_snd_get_mclk() ? 1 : 0);
1458 #else /* for CONFIG_ARCH_EXYNOS5 */
1459 exynos4_sys_powerdown_xusbxti_control(midas_snd_get_mclk() ? 1 : 0);
1465 static int midas_card_resume_pre(struct snd_soc_card *card)
1467 struct snd_soc_codec *codec = card->rtd->codec;
1468 struct snd_soc_dai *aif1_dai = card->rtd[0].codec_dai;
1471 midas_snd_set_mclk(true, false);
1473 #ifndef SND_USE_BIAS_LEVEL
1474 /* Switch the FLL */
1475 ret = snd_soc_dai_set_pll(aif1_dai, WM8994_FLL1,
1476 WM8994_FLL_SRC_MCLK1,
1477 MIDAS_DEFAULT_MCLK1,
1478 MIDAS_DEFAULT_SYNC_CLK);
1481 dev_err(aif1_dai->dev, "Unable to start FLL1: %d\n", ret);
1483 /* Then switch AIF1CLK to it */
1484 ret = snd_soc_dai_set_sysclk(aif1_dai,
1486 MIDAS_DEFAULT_SYNC_CLK,
1490 dev_err(aif1_dai->dev, "Unable to switch to FLL1: %d\n", ret);
1496 static int midas_card_resume_post(struct snd_soc_card *card)
1498 struct snd_soc_codec *codec = card->rtd->codec;
1499 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
1502 /* workaround for jack detection
1503 * sometimes WM8994_GPIO_1 type changed wrong function type
1504 * so if type mismatched, update to IRQ type
1506 reg = snd_soc_read(codec, WM8994_GPIO_1);
1508 if ((reg & WM8994_GPN_FN_MASK) != WM8994_GP_FN_IRQ) {
1509 dev_err(codec->dev, "%s: GPIO1 type 0x%x\n", __func__, reg);
1510 snd_soc_write(codec, WM8994_GPIO_1, WM8994_GP_FN_IRQ);
1513 #ifdef CONFIG_SEC_DEV_JACK
1514 snd_soc_dapm_force_enable_pin(&codec->dapm, "AIF1CLK");
1520 #ifdef SND_USE_BIAS_LEVEL
1521 static int midas_set_bias_level(struct snd_soc_card *card,
1522 struct snd_soc_dapm_context *dapm,
1523 enum snd_soc_bias_level level)
1525 struct snd_soc_dai *aif1_dai = card->rtd[0].codec_dai;
1527 if (dapm->dev != aif1_dai->dev)
1531 case SND_SOC_BIAS_PREPARE:
1532 midas_start_fll1(card->rtd[0].codec_dai);
1542 static int midas_set_bias_level_post(struct snd_soc_card *card,
1543 struct snd_soc_dapm_context *dapm,
1544 enum snd_soc_bias_level level)
1546 struct snd_soc_codec *codec = card->rtd->codec;
1547 struct snd_soc_dai *aif1_dai = card->rtd[0].codec_dai;
1548 struct snd_soc_dai *aif2_dai = card->rtd[1].codec_dai;
1551 if (dapm->dev != aif1_dai->dev)
1555 case SND_SOC_BIAS_STANDBY:
1557 /* When going idle stop FLL1 and revert to using MCLK2
1558 * directly for minimum power consumptin for accessory
1561 if (card->dapm.bias_level == SND_SOC_BIAS_PREPARE) {
1562 dev_info(aif1_dai->dev, "Moving to STANDBY\n");
1564 ret = snd_soc_dai_set_sysclk(aif2_dai,
1565 WM8994_SYSCLK_MCLK2,
1566 MIDAS_DEFAULT_MCLK2,
1569 dev_err(codec->dev, "Failed to switch to MCLK2\n");
1571 ret = snd_soc_dai_set_pll(aif2_dai, WM8994_FLL2,
1576 "Failed to change FLL2\n");
1578 ret = snd_soc_dai_set_sysclk(aif1_dai,
1579 WM8994_SYSCLK_MCLK2,
1580 MIDAS_DEFAULT_MCLK2,
1584 "Failed to switch to MCLK2\n");
1586 ret = snd_soc_dai_set_pll(aif1_dai, WM8994_FLL1,
1590 "Failed to stop FLL1\n");
1593 midas_fll1_active = false;
1594 midas_snd_set_mclk(false, false);
1602 card->dapm.bias_level = level;
1608 static struct snd_soc_card midas = {
1609 .name = "Midas_WM1811",
1610 .dai_link = midas_dai,
1612 /* If you want to use sec_fifo device,
1613 * changes the num_link = 2 or ARRAY_SIZE(midas_dai). */
1614 .num_links = ARRAY_SIZE(midas_dai),
1616 #ifdef SND_USE_BIAS_LEVEL
1617 .set_bias_level = midas_set_bias_level,
1618 .set_bias_level_post = midas_set_bias_level_post,
1621 .suspend_post = midas_card_suspend_post,
1622 .resume_pre = midas_card_resume_pre,
1623 .suspend_pre = midas_card_suspend_pre,
1624 .resume_post = midas_card_resume_post
1627 static struct platform_device *midas_snd_device;
1629 static int __init midas_audio_init(void)
1631 struct wm1811_machine_priv *wm1811;
1634 wm1811 = kzalloc(sizeof *wm1811, GFP_KERNEL);
1636 pr_err("Failed to allocate memory\n");
1640 snd_soc_card_set_drvdata(&midas, wm1811);
1642 midas_snd_device = platform_device_alloc("soc-audio", -1);
1643 if (!midas_snd_device) {
1645 goto err_device_alloc;
1648 ret = snd_soc_register_dais(&midas_snd_device->dev, midas_ext_dai,
1649 ARRAY_SIZE(midas_ext_dai));
1651 pr_err("Failed to register external DAIs: %d\n", ret);
1653 platform_set_drvdata(midas_snd_device, &midas);
1655 ret = platform_device_add(midas_snd_device);
1657 platform_device_put(midas_snd_device);
1668 module_init(midas_audio_init);
1670 static void __exit midas_audio_exit(void)
1672 struct snd_soc_card *card = &midas;
1673 struct wm1811_machine_priv *wm1811 = snd_soc_card_get_drvdata(card);
1674 platform_device_unregister(midas_snd_device);
1677 module_exit(midas_audio_exit);
1679 MODULE_AUTHOR("JS. Park <aitdark.park@samsung.com>");
1680 MODULE_DESCRIPTION("ALSA SoC Midas WM1811");
1681 MODULE_LICENSE("GPL");