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 if (wm8994->mic_detecting && status & 0x4) {
543 dev_info(wm1811->codec->dev, "Detected headphone\n");
544 wm8994->mic_detecting = false;
546 midas_micd_set_rate(wm1811->codec);
548 snd_soc_jack_report(wm8994->micdet[0].jack, SND_JACK_HEADPHONE,
551 /* If we have jackdet that will detect removal */
552 if (wm8994->jackdet) {
553 mutex_lock(&wm8994->accdet_lock);
555 snd_soc_update_bits(wm1811->codec, WM8958_MIC_DETECT_1,
558 if (wm8994->active_refcount) {
559 snd_soc_update_bits(wm1811->codec,
561 WM1811_JACKDET_MODE_MASK,
562 WM1811_JACKDET_MODE_AUDIO);
565 mutex_unlock(&wm8994->accdet_lock);
567 if (wm8994->pdata->jd_ext_cap) {
568 mutex_lock(&wm1811->codec->mutex);
569 snd_soc_dapm_disable_pin(&wm1811->codec->dapm,
571 snd_soc_dapm_sync(&wm1811->codec->dapm);
572 mutex_unlock(&wm1811->codec->mutex);
577 /* Report short circuit as a button */
578 if (wm8994->jack_mic) {
580 if (status & WM1811_JACKDET_BTN0)
581 report |= SND_JACK_BTN_0;
583 if (status & WM1811_JACKDET_BTN1)
584 report |= SND_JACK_BTN_1;
586 if (status & WM1811_JACKDET_BTN2)
587 report |= SND_JACK_BTN_2;
589 dev_dbg(wm1811->codec->dev, "Detected Button: %08x (%08X)\n",
592 snd_soc_jack_report(wm8994->micdet[0].jack, report,
597 #ifdef CONFIG_SND_SAMSUNG_I2S_MASTER
598 static int set_epll_rate(unsigned long rate)
600 struct clk *fout_epll;
602 fout_epll = clk_get(NULL, "fout_epll");
603 if (IS_ERR(fout_epll)) {
604 printk(KERN_ERR "%s: failed to get fout_epll\n", __func__);
608 if (rate == clk_get_rate(fout_epll))
611 clk_set_rate(fout_epll, rate);
617 #endif /* CONFIG_SND_SAMSUNG_I2S_MASTER */
619 #ifndef CONFIG_SND_SAMSUNG_I2S_MASTER
620 static int midas_wm1811_aif1_hw_params(struct snd_pcm_substream *substream,
621 struct snd_pcm_hw_params *params)
623 struct snd_soc_pcm_runtime *rtd = substream->private_data;
624 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
625 struct snd_soc_dai *codec_dai = rtd->codec_dai;
626 unsigned int pll_out;
629 dev_info(codec_dai->dev, "%s ++\n", __func__);
630 /* AIF1CLK should be >=3MHz for optimal performance */
631 if (params_rate(params) == 8000 || params_rate(params) == 11025)
632 pll_out = params_rate(params) * 512;
634 pll_out = params_rate(params) * 256;
636 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
637 | SND_SOC_DAIFMT_NB_NF
638 | SND_SOC_DAIFMT_CBM_CFM);
642 /* Set the cpu DAI configuration */
643 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S
644 | SND_SOC_DAIFMT_NB_NF
645 | SND_SOC_DAIFMT_CBM_CFM);
649 #ifndef SND_USE_BIAS_LEVEL
651 ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL1,
652 WM8994_FLL_SRC_MCLK1, MIDAS_DEFAULT_MCLK1,
655 dev_err(codec_dai->dev, "Unable to start FLL1: %d\n", ret);
657 ret = snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_FLL1,
658 pll_out, SND_SOC_CLOCK_IN);
660 dev_err(codec_dai->dev, "Unable to switch to FLL1: %d\n", ret);
664 ret = snd_soc_dai_set_sysclk(cpu_dai, SAMSUNG_I2S_OPCLK,
669 midas_start_fll1(codec_dai);
675 dev_info(codec_dai->dev, "%s --\n", __func__);
679 #else /* CONFIG_SND_SAMSUNG_I2S_MASTER */
680 static int midas_wm1811_aif1_hw_params(struct snd_pcm_substream *substream,
681 struct snd_pcm_hw_params *params)
683 struct snd_soc_pcm_runtime *rtd = substream->private_data;
684 struct snd_soc_dai *codec_dai = rtd->codec_dai;
685 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
686 int bfs, psr, rfs, ret;
689 switch (params_format(params)) {
690 case SNDRV_PCM_FORMAT_U24:
691 case SNDRV_PCM_FORMAT_S24:
694 case SNDRV_PCM_FORMAT_U16_LE:
695 case SNDRV_PCM_FORMAT_S16_LE:
702 switch (params_rate(params)) {
731 rclk = params_rate(params) * rfs;
759 printk(KERN_INFO "Not yet supported!\n");
763 set_epll_rate(rclk * psr);
765 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
766 | SND_SOC_DAIFMT_NB_NF
767 | SND_SOC_DAIFMT_CBS_CFS);
771 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S
772 | SND_SOC_DAIFMT_NB_NF
773 | SND_SOC_DAIFMT_CBS_CFS);
777 ret = snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_MCLK1,
778 rclk, SND_SOC_CLOCK_IN);
782 ret = snd_soc_dai_set_sysclk(cpu_dai, SAMSUNG_I2S_CDCLK,
783 0, SND_SOC_CLOCK_OUT);
787 ret = snd_soc_dai_set_clkdiv(cpu_dai, SAMSUNG_I2S_DIV_BCLK, bfs);
793 #endif /* CONFIG_SND_SAMSUNG_I2S_MASTER */
796 * Midas WM1811 DAI operations.
798 static struct snd_soc_ops midas_wm1811_aif1_ops = {
799 .hw_params = midas_wm1811_aif1_hw_params,
802 static int midas_wm1811_aif2_hw_params(struct snd_pcm_substream *substream,
803 struct snd_pcm_hw_params *params)
805 struct snd_soc_pcm_runtime *rtd = substream->private_data;
806 struct snd_soc_dai *codec_dai = rtd->codec_dai;
811 dev_info(codec_dai->dev, "%s ++\n", __func__);
812 prate = params_rate(params);
813 switch (params_rate(params)) {
818 dev_warn(codec_dai->dev, "Unsupported LRCLK %d, falling back to 8000Hz\n",
819 (int)params_rate(params));
823 #if defined(CONFIG_LTE_MODEM_CMC221) || defined(CONFIG_MACH_M0_CTC)
824 #if defined(CONFIG_MACH_C1_KOR_LGT)
825 /* Set the codec DAI configuration */
826 if (aif2_mode == 0) {
828 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
829 | SND_SOC_DAIFMT_NB_NF
830 | SND_SOC_DAIFMT_CBS_CFS);
832 ret = snd_soc_dai_set_fmt(codec_dai,
834 | SND_SOC_DAIFMT_IB_NF
835 | SND_SOC_DAIFMT_CBS_CFS);
837 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
838 | SND_SOC_DAIFMT_NB_NF
839 | SND_SOC_DAIFMT_CBM_CFM);
842 /* Set the codec DAI configuration */
843 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_DSP_A
844 | SND_SOC_DAIFMT_IB_NF
845 | SND_SOC_DAIFMT_CBS_CFS);
847 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_DSP_A
848 | SND_SOC_DAIFMT_IB_NF
849 | SND_SOC_DAIFMT_CBM_CFM);
852 /* Set the codec DAI configuration, aif2_mode:0 is slave */
854 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
855 | SND_SOC_DAIFMT_NB_NF
856 | SND_SOC_DAIFMT_CBS_CFS);
858 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
859 | SND_SOC_DAIFMT_NB_NF
860 | SND_SOC_DAIFMT_CBM_CFM);
866 #if defined(CONFIG_LTE_MODEM_CMC221)
867 if (kpcs_mode == 1) {
881 #elif defined(CONFIG_MACH_M0_CTC)
896 #ifdef SND_USE_BIAS_LEVEL
897 if (!midas_fll1_active)
898 midas_start_fll1(midas_aif1_dai);
901 if (aif2_mode == 0) {
902 ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL2,
906 ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL2,
907 WM8994_FLL_SRC_MCLK1,
908 MIDAS_DEFAULT_MCLK1, prate * 256);
912 dev_err(codec_dai->dev, "Unable to configure FLL2: %d\n", ret);
914 ret = snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_FLL2,
915 prate * 256, SND_SOC_CLOCK_IN);
917 dev_err(codec_dai->dev, "Unable to switch to FLL2: %d\n", ret);
919 dev_info(codec_dai->dev, "%s --\n", __func__);
923 static struct snd_soc_ops midas_wm1811_aif2_ops = {
924 .hw_params = midas_wm1811_aif2_hw_params,
927 static int midas_wm1811_aif3_hw_params(struct snd_pcm_substream *substream,
928 struct snd_pcm_hw_params *params)
930 pr_err("%s: enter\n", __func__);
934 static struct snd_soc_ops midas_wm1811_aif3_ops = {
935 .hw_params = midas_wm1811_aif3_hw_params,
938 static const struct snd_kcontrol_new midas_controls[] = {
939 SOC_DAPM_PIN_SWITCH("HP"),
940 SOC_DAPM_PIN_SWITCH("SPK"),
941 SOC_DAPM_PIN_SWITCH("RCV"),
942 SOC_DAPM_PIN_SWITCH("FM In"),
943 SOC_DAPM_PIN_SWITCH("LINE"),
944 SOC_DAPM_PIN_SWITCH("HDMI"),
945 SOC_DAPM_PIN_SWITCH("Main Mic"),
946 SOC_DAPM_PIN_SWITCH("Sub Mic"),
947 SOC_DAPM_PIN_SWITCH("Third Mic"),
948 SOC_DAPM_PIN_SWITCH("Headset Mic"),
950 SOC_ENUM_EXT("AIF2 Mode", aif2_mode_enum[0],
951 get_aif2_mode, set_aif2_mode),
953 SOC_ENUM_EXT("KPCS Mode", kpcs_mode_enum[0],
954 get_kpcs_mode, set_kpcs_mode),
956 SOC_ENUM_EXT("Input Clamp", input_clamp_enum[0],
957 get_input_clamp, set_input_clamp),
959 SOC_ENUM_EXT("LineoutSwitch Mode", lineout_mode_enum[0],
960 get_lineout_mode, set_lineout_mode),
964 const struct snd_soc_dapm_widget midas_dapm_widgets[] = {
965 SND_SOC_DAPM_HP("HP", NULL),
966 SND_SOC_DAPM_SPK("SPK", midas_ext_spkmode),
967 SND_SOC_DAPM_SPK("RCV", NULL),
968 SND_SOC_DAPM_LINE("LINE", midas_lineout_switch),
969 SND_SOC_DAPM_LINE("HDMI", NULL),
971 SND_SOC_DAPM_MIC("Headset Mic", NULL),
972 SND_SOC_DAPM_MIC("Main Mic", midas_ext_micbias),
973 SND_SOC_DAPM_MIC("Sub Mic", midas_ext_submicbias),
974 SND_SOC_DAPM_MIC("Third Mic", midas_ext_thirdmicbias),
975 SND_SOC_DAPM_LINE("FM In", NULL),
977 SND_SOC_DAPM_INPUT("S5P RP"),
980 const struct snd_soc_dapm_route midas_dapm_routes[] = {
981 { "HP", NULL, "HPOUT1L" },
982 { "HP", NULL, "HPOUT1R" },
984 { "SPK", NULL, "SPKOUTLN" },
985 { "SPK", NULL, "SPKOUTLP" },
986 { "SPK", NULL, "SPKOUTRN" },
987 { "SPK", NULL, "SPKOUTRP" },
989 { "RCV", NULL, "HPOUT2N" },
990 { "RCV", NULL, "HPOUT2P" },
992 { "LINE", NULL, "LINEOUT2N" },
993 { "LINE", NULL, "LINEOUT2P" },
995 { "HDMI", NULL, "LINEOUT1N" },
996 { "HDMI", NULL, "LINEOUT1P" },
998 { "IN1LP", NULL, "MICBIAS1" },
999 { "IN1LN", NULL, "MICBIAS1" },
1000 { "MICBIAS1", NULL, "Main Mic" },
1002 { "IN1RP", NULL, "Sub Mic" },
1003 { "IN1RN", NULL, "Sub Mic" },
1005 { "IN2LP:VXRN", NULL, "MICBIAS2" },
1006 { "MICBIAS2", NULL, "Headset Mic" },
1008 { "AIF1DAC1L", NULL, "S5P RP" },
1009 { "AIF1DAC1R", NULL, "S5P RP" },
1011 { "IN2RN", NULL, "FM In" },
1012 { "IN2RP:VXRP", NULL, "FM In" },
1014 { "IN2RN", NULL, "Third Mic" },
1015 { "IN2RP:VXRP", NULL, "Third Mic" },
1018 static struct snd_soc_dai_driver midas_ext_dai[] = {
1026 .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000,
1027 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1034 .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000,
1035 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1045 .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000,
1046 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1053 .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000,
1054 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1059 #ifndef CONFIG_SEC_DEV_JACK
1060 static ssize_t earjack_state_show(struct device *dev,
1061 struct device_attribute *attr, char *buf)
1063 struct snd_soc_codec *codec = dev_get_drvdata(dev);
1064 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
1068 if ((wm8994->micdet[0].jack->status & SND_JACK_HEADPHONE) ||
1069 (wm8994->micdet[0].jack->status & SND_JACK_HEADSET)) {
1073 return sprintf(buf, "%d\n", report);
1076 static ssize_t earjack_state_store(struct device *dev,
1077 struct device_attribute *attr, const char *buf, size_t size)
1079 pr_info("%s : operate nothing\n", __func__);
1084 static ssize_t earjack_key_state_show(struct device *dev,
1085 struct device_attribute *attr, char *buf)
1087 struct snd_soc_codec *codec = dev_get_drvdata(dev);
1088 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
1092 if (wm8994->micdet[0].jack->status & SND_JACK_BTN_0)
1095 return sprintf(buf, "%d\n", report);
1098 static ssize_t earjack_key_state_store(struct device *dev,
1099 struct device_attribute *attr, const char *buf, size_t size)
1101 pr_info("%s : operate nothing\n", __func__);
1106 static ssize_t earjack_select_jack_show(struct device *dev,
1107 struct device_attribute *attr, char *buf)
1109 pr_info("%s : operate nothing\n", __func__);
1114 static ssize_t earjack_select_jack_store(struct device *dev,
1115 struct device_attribute *attr, const char *buf, size_t size)
1117 struct snd_soc_codec *codec = dev_get_drvdata(dev);
1118 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
1120 wm8994->mic_detecting = false;
1121 wm8994->jack_mic = true;
1123 midas_micd_set_rate(codec);
1125 if ((!size) || (buf[0] != '1')) {
1126 snd_soc_jack_report(wm8994->micdet[0].jack,
1127 0, SND_JACK_HEADSET);
1128 dev_info(codec->dev, "Forced remove microphone\n");
1131 snd_soc_jack_report(wm8994->micdet[0].jack,
1132 SND_JACK_HEADSET, SND_JACK_HEADSET);
1133 dev_info(codec->dev, "Forced detect microphone\n");
1139 static ssize_t reselect_jack_show(struct device *dev,
1140 struct device_attribute *attr, char *buf)
1142 pr_info("%s : operate nothing\n", __func__);
1146 static ssize_t reselect_jack_store(struct device *dev,
1147 struct device_attribute *attr, const char *buf, size_t size)
1149 struct snd_soc_codec *codec = dev_get_drvdata(dev);
1150 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
1153 reg = snd_soc_read(codec, WM8958_MIC_DETECT_3);
1155 dev_info(codec->dev, "Detected open circuit\n");
1157 snd_soc_update_bits(codec, WM8958_MICBIAS2,
1158 WM8958_MICB2_DISCH, WM8958_MICB2_DISCH);
1159 /* Enable debounce while removed */
1160 snd_soc_update_bits(codec, WM1811_JACKDET_CTRL,
1161 WM1811_JACKDET_DB, WM1811_JACKDET_DB);
1163 wm8994->mic_detecting = false;
1164 wm8994->jack_mic = false;
1165 snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
1166 WM8958_MICD_ENA, 0);
1168 if (wm8994->active_refcount) {
1169 snd_soc_update_bits(codec,
1171 WM1811_JACKDET_MODE_MASK,
1172 WM1811_JACKDET_MODE_AUDIO);
1174 snd_soc_update_bits(codec,
1176 WM1811_JACKDET_MODE_MASK,
1177 WM1811_JACKDET_MODE_JACK);
1180 snd_soc_jack_report(wm8994->micdet[0].jack, 0,
1181 SND_JACK_MECHANICAL | SND_JACK_HEADSET |
1187 static DEVICE_ATTR(reselect_jack, S_IRUGO | S_IWUSR | S_IWGRP,
1188 reselect_jack_show, reselect_jack_store);
1190 static DEVICE_ATTR(select_jack, S_IRUGO | S_IWUSR | S_IWGRP,
1191 earjack_select_jack_show, earjack_select_jack_store);
1193 static DEVICE_ATTR(key_state, S_IRUGO | S_IWUSR | S_IWGRP,
1194 earjack_key_state_show, earjack_key_state_store);
1196 static DEVICE_ATTR(state, S_IRUGO | S_IWUSR | S_IWGRP,
1197 earjack_state_show, earjack_state_store);
1200 static int midas_wm1811_init_paiftx(struct snd_soc_pcm_runtime *rtd)
1202 struct snd_soc_codec *codec = rtd->codec;
1203 struct wm1811_machine_priv *wm1811
1204 = snd_soc_card_get_drvdata(codec->card);
1205 struct snd_soc_dai *aif1_dai = rtd->codec_dai;
1206 struct wm8994 *control = codec->control_data;
1207 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
1210 #ifdef SND_USE_BIAS_LEVEL
1211 midas_aif1_dai = aif1_dai;
1214 #ifdef CONFIG_MACH_GC1
1215 wm1811_codec = codec;
1218 midas_snd_set_mclk(true, false);
1220 rtd->codec_dai->driver->playback.channels_max =
1221 rtd->cpu_dai->driver->playback.channels_max;
1223 ret = snd_soc_add_controls(codec, midas_controls,
1224 ARRAY_SIZE(midas_controls));
1226 ret = snd_soc_dapm_new_controls(&codec->dapm, midas_dapm_widgets,
1227 ARRAY_SIZE(midas_dapm_widgets));
1229 dev_err(codec->dev, "Failed to add DAPM widgets: %d\n", ret);
1231 ret = snd_soc_dapm_add_routes(&codec->dapm, midas_dapm_routes,
1232 ARRAY_SIZE(midas_dapm_routes));
1234 dev_err(codec->dev, "Failed to add DAPM routes: %d\n", ret);
1236 ret = snd_soc_dai_set_sysclk(aif1_dai, WM8994_SYSCLK_MCLK2,
1237 MIDAS_DEFAULT_MCLK2, SND_SOC_CLOCK_IN);
1239 dev_err(codec->dev, "Failed to boot clocking\n");
1241 /* Force AIF1CLK on as it will be master for jack detection */
1242 if (wm8994->revision > 1) {
1243 ret = snd_soc_dapm_force_enable_pin(&codec->dapm, "AIF1CLK");
1245 dev_err(codec->dev, "Failed to enable AIF1CLK: %d\n",
1249 ret = snd_soc_dapm_disable_pin(&codec->dapm, "S5P RP");
1251 dev_err(codec->dev, "Failed to disable S5P RP: %d\n", ret);
1253 snd_soc_dapm_ignore_suspend(&codec->dapm, "RCV");
1254 snd_soc_dapm_ignore_suspend(&codec->dapm, "SPK");
1255 snd_soc_dapm_ignore_suspend(&codec->dapm, "HP");
1256 snd_soc_dapm_ignore_suspend(&codec->dapm, "Headset Mic");
1257 snd_soc_dapm_ignore_suspend(&codec->dapm, "Sub Mic");
1258 snd_soc_dapm_ignore_suspend(&codec->dapm, "Main Mic");
1259 snd_soc_dapm_ignore_suspend(&codec->dapm, "AIF1DACDAT");
1260 snd_soc_dapm_ignore_suspend(&codec->dapm, "AIF2DACDAT");
1261 snd_soc_dapm_ignore_suspend(&codec->dapm, "AIF3DACDAT");
1262 snd_soc_dapm_ignore_suspend(&codec->dapm, "AIF1ADCDAT");
1263 snd_soc_dapm_ignore_suspend(&codec->dapm, "AIF2ADCDAT");
1264 snd_soc_dapm_ignore_suspend(&codec->dapm, "AIF3ADCDAT");
1265 snd_soc_dapm_ignore_suspend(&codec->dapm, "FM In");
1266 snd_soc_dapm_ignore_suspend(&codec->dapm, "LINE");
1267 snd_soc_dapm_ignore_suspend(&codec->dapm, "HDMI");
1268 snd_soc_dapm_ignore_suspend(&codec->dapm, "Third Mic");
1270 wm1811->codec = codec;
1272 midas_micd_set_rate(codec);
1274 #ifdef CONFIG_SEC_DEV_JACK
1275 /* By default use idle_bias_off, will override for WM8994 */
1276 codec->dapm.idle_bias_off = 0;
1277 #else /* CONFIG_SEC_DEV_JACK */
1278 wm1811->jack.status = 0;
1280 ret = snd_soc_jack_new(codec, "Midas Jack",
1281 SND_JACK_HEADSET | SND_JACK_BTN_0 |
1282 SND_JACK_BTN_1 | SND_JACK_BTN_2,
1286 dev_err(codec->dev, "Failed to create jack: %d\n", ret);
1288 ret = snd_jack_set_key(wm1811->jack.jack, SND_JACK_BTN_0, KEY_MEDIA);
1291 dev_err(codec->dev, "Failed to set KEY_MEDIA: %d\n", ret);
1293 ret = snd_jack_set_key(wm1811->jack.jack, SND_JACK_BTN_1,
1296 dev_err(codec->dev, "Failed to set KEY_VOLUMEUP: %d\n", ret);
1298 ret = snd_jack_set_key(wm1811->jack.jack, SND_JACK_BTN_2,
1302 dev_err(codec->dev, "Failed to set KEY_VOLUMEDOWN: %d\n", ret);
1304 if (wm8994->revision > 1) {
1305 dev_info(codec->dev, "wm1811: Rev %c support mic detection\n",
1306 'A' + wm8994->revision);
1307 ret = wm8958_mic_detect(codec, &wm1811->jack, midas_micdet,
1311 dev_err(codec->dev, "Failed start detection: %d\n",
1314 dev_info(codec->dev, "wm1811: Rev %c doesn't support mic detection\n",
1315 'A' + wm8994->revision);
1316 codec->dapm.idle_bias_off = 0;
1318 /* To wakeup for earjack event in suspend mode */
1319 enable_irq_wake(control->irq);
1321 wake_lock_init(&wm1811->jackdet_wake_lock,
1322 WAKE_LOCK_SUSPEND, "midas_jackdet");
1324 /* To support PBA function test */
1325 jack_class = class_create(THIS_MODULE, "audio");
1327 if (IS_ERR(jack_class))
1328 pr_err("Failed to create class\n");
1330 jack_dev = device_create(jack_class, NULL, 0, codec, "earjack");
1332 if (device_create_file(jack_dev, &dev_attr_select_jack) < 0)
1333 pr_err("Failed to create device file (%s)!\n",
1334 dev_attr_select_jack.attr.name);
1336 if (device_create_file(jack_dev, &dev_attr_key_state) < 0)
1337 pr_err("Failed to create device file (%s)!\n",
1338 dev_attr_key_state.attr.name);
1340 if (device_create_file(jack_dev, &dev_attr_state) < 0)
1341 pr_err("Failed to create device file (%s)!\n",
1342 dev_attr_state.attr.name);
1344 if (device_create_file(jack_dev, &dev_attr_reselect_jack) < 0)
1345 pr_err("Failed to create device file (%s)!\n",
1346 dev_attr_reselect_jack.attr.name);
1348 #endif /* CONFIG_SEC_DEV_JACK */
1349 return snd_soc_dapm_sync(&codec->dapm);
1352 static struct snd_soc_dai_link midas_dai[] = {
1353 { /* Sec_Fifo DAI i/f */
1354 .name = "Sec_FIFO TX",
1355 .stream_name = "Sec_Dai",
1356 .cpu_dai_name = "samsung-i2s.4",
1357 .codec_dai_name = "wm8994-aif1",
1358 #ifndef CONFIG_SND_SOC_SAMSUNG_USE_DMA_WRAPPER
1359 .platform_name = "samsung-audio-idma",
1361 .platform_name = "samsung-audio",
1363 .codec_name = "wm8994-codec",
1364 .init = midas_wm1811_init_paiftx,
1365 .ops = &midas_wm1811_aif1_ops,
1368 .name = "Midas_WM1811 Voice",
1369 .stream_name = "Voice Tx/Rx",
1370 .cpu_dai_name = "midas.cp",
1371 .codec_dai_name = "wm8994-aif2",
1372 .platform_name = "snd-soc-dummy",
1373 .codec_name = "wm8994-codec",
1374 .ops = &midas_wm1811_aif2_ops,
1375 .ignore_suspend = 1,
1378 .name = "Midas_WM1811 BT",
1379 .stream_name = "BT Tx/Rx",
1380 .cpu_dai_name = "midas.bt",
1381 .codec_dai_name = "wm8994-aif3",
1382 .platform_name = "snd-soc-dummy",
1383 .codec_name = "wm8994-codec",
1384 .ops = &midas_wm1811_aif3_ops,
1385 .ignore_suspend = 1,
1387 { /* Primary DAI i/f */
1388 .name = "WM8994 AIF1",
1389 .stream_name = "Pri_Dai",
1390 .cpu_dai_name = "samsung-i2s.0",
1391 .codec_dai_name = "wm8994-aif1",
1392 .platform_name = "samsung-audio",
1393 .codec_name = "wm8994-codec",
1394 .ops = &midas_wm1811_aif1_ops,
1398 static int midas_card_suspend_pre(struct snd_soc_card *card)
1400 struct snd_soc_codec *codec = card->rtd->codec;
1401 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
1403 #ifdef CONFIG_SEC_DEV_JACK
1404 snd_soc_dapm_disable_pin(&codec->dapm, "AIF1CLK");
1410 static int midas_card_suspend_post(struct snd_soc_card *card)
1412 struct snd_soc_codec *codec = card->rtd->codec;
1413 struct snd_soc_dai *aif1_dai = card->rtd[0].codec_dai;
1414 struct snd_soc_dai *aif2_dai = card->rtd[1].codec_dai;
1417 if (!codec->active) {
1418 #ifndef SND_USE_BIAS_LEVEL
1419 ret = snd_soc_dai_set_sysclk(aif2_dai,
1420 WM8994_SYSCLK_MCLK2,
1421 MIDAS_DEFAULT_MCLK2,
1425 dev_err(codec->dev, "Unable to switch to MCLK2: %d\n",
1428 ret = snd_soc_dai_set_pll(aif2_dai, WM8994_FLL2, 0, 0, 0);
1431 dev_err(codec->dev, "Unable to stop FLL2\n");
1433 ret = snd_soc_dai_set_sysclk(aif1_dai,
1434 WM8994_SYSCLK_MCLK2,
1435 MIDAS_DEFAULT_MCLK2,
1438 dev_err(codec->dev, "Unable to switch to MCLK2\n");
1440 ret = snd_soc_dai_set_pll(aif1_dai, WM8994_FLL1, 0, 0, 0);
1443 dev_err(codec->dev, "Unable to stop FLL1\n");
1446 midas_snd_set_mclk(false, true);
1449 #ifdef CONFIG_ARCH_EXYNOS5
1450 exynos5_sys_powerdown_xxti_control(midas_snd_get_mclk() ? 1 : 0);
1451 #else /* for CONFIG_ARCH_EXYNOS5 */
1452 exynos4_sys_powerdown_xusbxti_control(midas_snd_get_mclk() ? 1 : 0);
1458 static int midas_card_resume_pre(struct snd_soc_card *card)
1460 struct snd_soc_codec *codec = card->rtd->codec;
1461 struct snd_soc_dai *aif1_dai = card->rtd[0].codec_dai;
1464 midas_snd_set_mclk(true, false);
1466 #ifndef SND_USE_BIAS_LEVEL
1467 /* Switch the FLL */
1468 ret = snd_soc_dai_set_pll(aif1_dai, WM8994_FLL1,
1469 WM8994_FLL_SRC_MCLK1,
1470 MIDAS_DEFAULT_MCLK1,
1471 MIDAS_DEFAULT_SYNC_CLK);
1474 dev_err(aif1_dai->dev, "Unable to start FLL1: %d\n", ret);
1476 /* Then switch AIF1CLK to it */
1477 ret = snd_soc_dai_set_sysclk(aif1_dai,
1479 MIDAS_DEFAULT_SYNC_CLK,
1483 dev_err(aif1_dai->dev, "Unable to switch to FLL1: %d\n", ret);
1489 static int midas_card_resume_post(struct snd_soc_card *card)
1491 struct snd_soc_codec *codec = card->rtd->codec;
1492 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
1495 /* workaround for jack detection
1496 * sometimes WM8994_GPIO_1 type changed wrong function type
1497 * so if type mismatched, update to IRQ type
1499 reg = snd_soc_read(codec, WM8994_GPIO_1);
1501 if ((reg & WM8994_GPN_FN_MASK) != WM8994_GP_FN_IRQ) {
1502 dev_err(codec->dev, "%s: GPIO1 type 0x%x\n", __func__, reg);
1503 snd_soc_write(codec, WM8994_GPIO_1, WM8994_GP_FN_IRQ);
1506 #ifdef CONFIG_SEC_DEV_JACK
1507 snd_soc_dapm_force_enable_pin(&codec->dapm, "AIF1CLK");
1513 #ifdef SND_USE_BIAS_LEVEL
1514 static int midas_set_bias_level(struct snd_soc_card *card,
1515 struct snd_soc_dapm_context *dapm,
1516 enum snd_soc_bias_level level)
1518 struct snd_soc_dai *aif1_dai = card->rtd[0].codec_dai;
1520 if (dapm->dev != aif1_dai->dev)
1524 case SND_SOC_BIAS_PREPARE:
1525 midas_start_fll1(card->rtd[0].codec_dai);
1535 static int midas_set_bias_level_post(struct snd_soc_card *card,
1536 struct snd_soc_dapm_context *dapm,
1537 enum snd_soc_bias_level level)
1539 struct snd_soc_codec *codec = card->rtd->codec;
1540 struct snd_soc_dai *aif1_dai = card->rtd[0].codec_dai;
1541 struct snd_soc_dai *aif2_dai = card->rtd[1].codec_dai;
1544 if (dapm->dev != aif1_dai->dev)
1548 case SND_SOC_BIAS_STANDBY:
1550 /* When going idle stop FLL1 and revert to using MCLK2
1551 * directly for minimum power consumptin for accessory
1554 if (card->dapm.bias_level == SND_SOC_BIAS_PREPARE) {
1555 dev_info(aif1_dai->dev, "Moving to STANDBY\n");
1557 ret = snd_soc_dai_set_sysclk(aif2_dai,
1558 WM8994_SYSCLK_MCLK2,
1559 MIDAS_DEFAULT_MCLK2,
1562 dev_err(codec->dev, "Failed to switch to MCLK2\n");
1564 ret = snd_soc_dai_set_pll(aif2_dai, WM8994_FLL2,
1569 "Failed to change FLL2\n");
1571 ret = snd_soc_dai_set_sysclk(aif1_dai,
1572 WM8994_SYSCLK_MCLK2,
1573 MIDAS_DEFAULT_MCLK2,
1577 "Failed to switch to MCLK2\n");
1579 ret = snd_soc_dai_set_pll(aif1_dai, WM8994_FLL1,
1583 "Failed to stop FLL1\n");
1586 midas_fll1_active = false;
1587 midas_snd_set_mclk(false, false);
1595 card->dapm.bias_level = level;
1601 static struct snd_soc_card midas = {
1602 .name = "Midas_WM1811",
1603 .dai_link = midas_dai,
1605 /* If you want to use sec_fifo device,
1606 * changes the num_link = 2 or ARRAY_SIZE(midas_dai). */
1607 .num_links = ARRAY_SIZE(midas_dai),
1609 #ifdef SND_USE_BIAS_LEVEL
1610 .set_bias_level = midas_set_bias_level,
1611 .set_bias_level_post = midas_set_bias_level_post,
1614 .suspend_post = midas_card_suspend_post,
1615 .resume_pre = midas_card_resume_pre,
1616 .suspend_pre = midas_card_suspend_pre,
1617 .resume_post = midas_card_resume_post
1620 static struct platform_device *midas_snd_device;
1622 static int __init midas_audio_init(void)
1624 struct wm1811_machine_priv *wm1811;
1627 wm1811 = kzalloc(sizeof *wm1811, GFP_KERNEL);
1629 pr_err("Failed to allocate memory\n");
1633 snd_soc_card_set_drvdata(&midas, wm1811);
1635 midas_snd_device = platform_device_alloc("soc-audio", -1);
1636 if (!midas_snd_device) {
1638 goto err_device_alloc;
1641 ret = snd_soc_register_dais(&midas_snd_device->dev, midas_ext_dai,
1642 ARRAY_SIZE(midas_ext_dai));
1644 pr_err("Failed to register external DAIs: %d\n", ret);
1646 platform_set_drvdata(midas_snd_device, &midas);
1648 ret = platform_device_add(midas_snd_device);
1650 platform_device_put(midas_snd_device);
1661 module_init(midas_audio_init);
1663 static void __exit midas_audio_exit(void)
1665 struct snd_soc_card *card = &midas;
1666 struct wm1811_machine_priv *wm1811 = snd_soc_card_get_drvdata(card);
1667 platform_device_unregister(midas_snd_device);
1670 module_exit(midas_audio_exit);
1672 MODULE_AUTHOR("JS. Park <aitdark.park@samsung.com>");
1673 MODULE_DESCRIPTION("ALSA SoC Midas WM1811");
1674 MODULE_LICENSE("GPL");