aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/samsung
diff options
context:
space:
mode:
Diffstat (limited to 'sound/soc/samsung')
-rw-r--r--sound/soc/samsung/Kconfig49
-rw-r--r--sound/soc/samsung/Makefile12
-rw-r--r--sound/soc/samsung/audss.c4
-rw-r--r--sound/soc/samsung/gc2pd_wm1811.c2040
-rw-r--r--sound/soc/samsung/gd2_wm1811.c1814
-rw-r--r--sound/soc/samsung/grande_wm1811.c45
-rw-r--r--sound/soc/samsung/i2s.c10
-rw-r--r--sound/soc/samsung/kona_wm1811.c1481
-rw-r--r--sound/soc/samsung/m3_wm1811.c36
-rw-r--r--sound/soc/samsung/midas_wm1811.c374
-rw-r--r--sound/soc/samsung/t0_wm1811.c356
-rw-r--r--sound/soc/samsung/t0duos_wm1811.c292
-rw-r--r--sound/soc/samsung/tab3_wm1811.c1406
-rw-r--r--sound/soc/samsung/watch_ymu831.c210
-rw-r--r--sound/soc/samsung/zest_wm1811.c1735
15 files changed, 9627 insertions, 237 deletions
diff --git a/sound/soc/samsung/Kconfig b/sound/soc/samsung/Kconfig
index de7cd13..55332b8 100644
--- a/sound/soc/samsung/Kconfig
+++ b/sound/soc/samsung/Kconfig
@@ -85,7 +85,7 @@ config SND_SOC_SAMSUNG_GRANDE_WM1811
config SND_SOC_SAMSUNG_T0_WM1811
tristate "SoC I2S Audio support for WM1811 on T0"
- depends on SND_SOC_SAMSUNG && MACH_T0
+ depends on SND_SOC_SAMSUNG && (MACH_T0 || MACH_M3_USA_TMO)
select SND_SOC_WM8994
select SND_SAMSUNG_I2S
help
@@ -103,6 +103,12 @@ config SND_SOC_SAMSUNG_M3_WM1811
select SND_SOC_WM8994
select SND_SAMSUNG_I2S
+config SND_SOC_SAMSUNG_KONA_WM1811
+ tristate "SoC I2S Audio support for WM1811 on KONA"
+ depends on SND_SOC_SAMSUNG && MACH_KONA
+ select SND_SOC_WM8994
+ select SND_SAMSUNG_I2S
+
config SND_SOC_SAMSUNG_SLP_EXYNOS_WM1811
tristate "SoC I2S Audio support for WM1811 on SLP MIDAS"
depends on SND_SOC_SAMSUNG && (MACH_SLP_PQ || MACH_SLP_PQ_LTE || MACH_REDWOOD || MACH_SLP_T0_LTE)
@@ -119,12 +125,38 @@ config SND_SOC_SAMSUNG_SLP_NAPLES_WM1811
config SND_SOC_SAMSUNG_LUNGO_WM1811
tristate "SoC I2S Audio support for WM1811 on LUNGO"
- depends on SND_SOC_SAMSUNG && (MACH_P10 ||MACH_P11 || MACH_P4NOTE)
+ depends on SND_SOC_SAMSUNG && (MACH_P10 || MACH_P11 || MACH_P4NOTE)
select SND_SOC_WM8994
select SND_SAMSUNG_I2S
help
Say Y if you want to add support for SoC audio on the LUNGO.
+config SND_SOC_SAMSUNG_TAB3_WM1811
+ tristate "SoC I2S Audio support for WM1811 on TAB3"
+ depends on SND_SOC_SAMSUNG && MACH_TAB3
+ select SND_SOC_WM8994
+ select SND_SAMSUNG_I2S
+
+config SND_SOC_SAMSUNG_ZEST_WM1811
+ tristate "SoC I2S Audio support for WM1811 on ZEST"
+ depends on SND_SOC_SAMSUNG && MACH_ZEST
+ select SND_SOC_WM8994
+ select SND_SAMSUNG_I2S
+
+config SND_SOC_SAMSUNG_GD2_WM1811
+ tristate "SoC I2S Audio support for WM1811 on ZEST"
+ depends on SND_SOC_SAMSUNG && MACH_GD2
+ select SND_SOC_WM8994
+ select SND_SAMSUNG_I2S
+
+config SND_SOC_SAMSUNG_GC2PD_WM1811
+ tristate "SoC I2S Audio support for WM1811 on GC2PD"
+ depends on SND_SOC_SAMSUNG && (MACH_GC2PD || MACH_IPCAM)
+ select SND_SOC_WM8994
+ select SND_SAMSUNG_I2S
+ help
+ Say Y if you want to add support for SoC audio on the GC2PD.
+
config SND_SOC_U1_MC1N2
tristate "SoC I2S Audio support for MC1N2 on U1"
depends on SND_SOC_SAMSUNG && (MACH_U1 || MACH_PX)
@@ -144,6 +176,19 @@ config SND_SOC_SLP_TRATS_MC1N2
Samsung Exynos-4210 audio subsystem
and Yamaha MC1N2 codec.
+config SND_SOC_SAMSUNG_WATCH_YMU831
+ tristate "SoC I2S Audio support for WATCH - YMU831"
+ depends on SND_SOC_SAMSUNG && MACH_WATCH
+ select SND_SAMSUNG_I2S
+ select SND_SOC_YAMAHA_YMU831
+ help
+ Say Y if you want to add support for SoC audio on WATCH Board
+ with the YMU831
+
+config SND_USE_YMU831_LDODE_GPIO
+ bool "Use YMU831_LDODE_GPIO"
+ depends on SND_SOC_SAMSUNG && SND_SOC_YAMAHA_YMU831
+
config SND_SOC_SAMSUNG_USE_DMA_WRAPPER
bool "DMA wrapper for ALSA Platform(DMA)"
diff --git a/sound/soc/samsung/Makefile b/sound/soc/samsung/Makefile
index 5891ebe..c5016b5 100644
--- a/sound/soc/samsung/Makefile
+++ b/sound/soc/samsung/Makefile
@@ -50,10 +50,16 @@ snd-soc-midas-wm1811-objs := midas_wm1811.o
snd-soc-t0-wm1811-objs := t0_wm1811.o
snd-soc-t0duos-wm1811-objs := t0duos_wm1811.o
snd-soc-m3-wm1811-objs := m3_wm1811.o
+snd-soc-kona-wm1811-objs := kona_wm1811.o
snd-soc-slp-exynos-wm1811-objs := slp_exynos_wm1811.o
snd-soc-slp-naples-wm1811-objs := slp_naples_wm1811.o
snd-soc-lungo-wm1811-objs := lungo_wm1811.o
snd-soc-grande-wm1811-objs := grande_wm1811.o
+snd-soc-tab3-wm1811-objs := tab3_wm1811.o
+snd-soc-zest-wm1811-objs := zest_wm1811.o
+snd-soc-gd2-wm1811-objs := gd2_wm1811.o
+snd-soc-gc2pd-wm1811-objs := gc2pd_wm1811.o
+snd-soc-watch-ymu831-objs := watch_ymu831.o
obj-$(CONFIG_SND_SOC_SAMSUNG_JIVE_WM8750) += snd-soc-jive-wm8750.o
obj-$(CONFIG_SND_SOC_SAMSUNG_NEO1973_WM8753) += snd-soc-neo1973-wm8753.o
@@ -81,10 +87,16 @@ obj-$(CONFIG_SND_SOC_SAMSUNG_MIDAS_WM1811) += snd-soc-midas-wm1811.o
obj-$(CONFIG_SND_SOC_SAMSUNG_T0_WM1811) += snd-soc-t0-wm1811.o
obj-$(CONFIG_SND_SOC_SAMSUNG_T0DUOS_WM1811) += snd-soc-t0duos-wm1811.o
obj-$(CONFIG_SND_SOC_SAMSUNG_M3_WM1811) += snd-soc-m3-wm1811.o
+obj-$(CONFIG_SND_SOC_SAMSUNG_KONA_WM1811) += snd-soc-kona-wm1811.o
obj-$(CONFIG_SND_SOC_SAMSUNG_SLP_EXYNOS_WM1811) += snd-soc-slp-exynos-wm1811.o
obj-$(CONFIG_SND_SOC_SAMSUNG_SLP_NAPLES_WM1811) += snd-soc-slp-naples-wm1811.o
obj-$(CONFIG_SND_SOC_SAMSUNG_LUNGO_WM1811) += snd-soc-midas-wm1811.o
obj-$(CONFIG_SND_SOC_SAMSUNG_GRANDE_WM1811) += snd-soc-grande-wm1811.o
+obj-$(CONFIG_SND_SOC_SAMSUNG_TAB3_WM1811) += snd-soc-tab3-wm1811.o
+obj-$(CONFIG_SND_SOC_SAMSUNG_ZEST_WM1811) += snd-soc-zest-wm1811.o
+obj-$(CONFIG_SND_SOC_SAMSUNG_GD2_WM1811) += snd-soc-gd2-wm1811.o
+obj-$(CONFIG_SND_SOC_SAMSUNG_GC2PD_WM1811) += snd-soc-gc2pd-wm1811.o
+obj-$(CONFIG_SND_SOC_SAMSUNG_WATCH_YMU831) += snd-soc-watch-ymu831.o
obj-$(CONFIG_SND_SAMSUNG_RP) += srp_ulp/
obj-$(CONFIG_SND_SAMSUNG_ALP) += srp_alp/
diff --git a/sound/soc/samsung/audss.c b/sound/soc/samsung/audss.c
index a5300de..d0da54c 100644
--- a/sound/soc/samsung/audss.c
+++ b/sound/soc/samsung/audss.c
@@ -138,9 +138,9 @@ void audss_reg_restore(void)
if (!audss.reg_saved)
return;
- writel(audss.suspend_audss_clksrc, S5P_CLKSRC_AUDSS);
- writel(audss.suspend_audss_clkdiv, S5P_CLKDIV_AUDSS);
writel(audss.suspend_audss_clkgate, S5P_CLKGATE_AUDSS);
+ writel(audss.suspend_audss_clkdiv, S5P_CLKDIV_AUDSS);
+ writel(audss.suspend_audss_clksrc, S5P_CLKSRC_AUDSS);
audss.reg_saved = false;
pr_debug("%s: Successfully restored audss reg\n", __func__);
diff --git a/sound/soc/samsung/gc2pd_wm1811.c b/sound/soc/samsung/gc2pd_wm1811.c
new file mode 100644
index 0000000..ca40f9c
--- /dev/null
+++ b/sound/soc/samsung/gc2pd_wm1811.c
@@ -0,0 +1,2040 @@
+/*
+ * gc2pd_wm1811.c
+ *
+ * Copyright (c) 2011 Samsung Electronics Co. Ltd
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ */
+#include <linux/platform_device.h>
+#include <linux/clk.h>
+#include <linux/io.h>
+#include <linux/gpio.h>
+#include <linux/delay.h>
+#include <linux/slab.h>
+#include <linux/workqueue.h>
+#include <linux/input.h>
+#include <linux/wakelock.h>
+#include <linux/suspend.h>
+
+#include <sound/soc.h>
+#include <sound/soc-dapm.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include <sound/jack.h>
+
+#include <mach/regs-clock.h>
+#include <mach/pmu.h>
+#include <mach/midas-sound.h>
+
+#include <linux/mfd/wm8994/core.h>
+#include <linux/mfd/wm8994/registers.h>
+#include <linux/mfd/wm8994/pdata.h>
+#include <linux/mfd/wm8994/gpio.h>
+
+#ifdef CONFIG_EXYNOS_SOUND_PLATFORM_DATA
+#include <linux/exynos_audio.h>
+#endif
+
+#ifdef CONFIG_USE_ADC_DET
+#include <plat/adc.h>
+#endif
+
+#if defined(CONFIG_SND_USE_MUIC_SWITCH)
+#include <linux/mfd/max77693-private.h>
+#endif
+
+
+#include "i2s.h"
+#include "s3c-i2s-v2.h"
+#include "../codecs/wm8994.h"
+
+
+#define GC2PD_DEFAULT_MCLK1 24000000
+#define GC2PD_DEFAULT_MCLK2 32768
+#define GC2PD_DEFAULT_SYNC_CLK 11289600
+
+#define WM1811_JACKDET_MODE_NONE 0x0000
+#define WM1811_JACKDET_MODE_JACK 0x0100
+#define WM1811_JACKDET_MODE_MIC 0x0080
+#define WM1811_JACKDET_MODE_AUDIO 0x0180
+
+#define WM1811_JACKDET_BTN0 0x04
+#define WM1811_JACKDET_BTN1 0x10
+#define WM1811_JACKDET_BTN2 0x08
+
+#define MIC_DISABLE 0
+#define MIC_ENABLE 1
+#define MIC_FORCE_DISABLE 2
+#define MIC_FORCE_ENABLE 3
+
+#define JACK_ADC_CH 3
+#define JACK_SAMPLE_SIZE 5
+
+#define MAX_ZONE_LIMIT 10
+/* keep this value if you support double-pressed concept */
+#define WAKE_LOCK_TIME (HZ * 5) /* 5 sec */
+#define EAR_CHECK_LOOP_CNT 10
+
+struct wm1811_machine_priv {
+ struct snd_soc_jack jack;
+ struct snd_soc_codec *codec;
+ struct wake_lock jackdet_wake_lock;
+ void (*lineout_switch_f) (int on);
+ void (*set_main_mic_f) (int on);
+ void (*set_sub_mic_f) (int on);
+ int (*get_g_det_value_f) (void);
+ int (*get_g_det_irq_num_f) (void);
+#ifdef CONFIG_USE_ADC_DET
+ struct s3c_adc_client *padc;
+ struct jack_zone *zones;
+ int num_zones;
+ int use_jackdet_type;
+#endif
+};
+
+enum {
+ SEC_JACK_NO_DEVICE = 0x0,
+ SEC_HEADSET_4POLE = 0x01 << 0,
+ SEC_HEADSET_3POLE = 0x01 << 1,
+ SEC_TTY_DEVICE = 0x01 << 2,
+ SEC_FM_HEADSET = 0x01 << 3,
+ SEC_FM_SPEAKER = 0x01 << 4,
+ SEC_TVOUT_DEVICE = 0x01 << 5,
+ SEC_EXTRA_DOCK_SPEAKER = 0x01 << 6,
+ SEC_EXTRA_CAR_DOCK_SPEAKER = 0x01 << 7,
+ SEC_UNKNOWN_DEVICE = 0x01 << 8,
+};
+
+#ifdef CONFIG_USE_ADC_DET
+static bool recheck_jack;
+static int jack_get_adc_data(struct s3c_adc_client *padc);
+static void jack_set_type(struct wm1811_machine_priv *wm1811, int jack_type);
+#endif
+
+static struct wm8958_micd_rate gc2pd_det_rates[] = {
+ { GC2PD_DEFAULT_MCLK2, true, 0, 0 },
+ { GC2PD_DEFAULT_MCLK2, false, 0, 0 },
+ { GC2PD_DEFAULT_SYNC_CLK, true, 7, 7 },
+ { GC2PD_DEFAULT_SYNC_CLK, false, 7, 7 },
+};
+
+static struct wm8958_micd_rate gc2pd_jackdet_rates[] = {
+ { GC2PD_DEFAULT_MCLK2, true, 0, 0 },
+ { GC2PD_DEFAULT_MCLK2, false, 0, 0 },
+ { GC2PD_DEFAULT_SYNC_CLK, true, 10, 10 },
+ { GC2PD_DEFAULT_SYNC_CLK, false, 7, 8 },
+};
+
+static int aif2_mode;
+const char *aif2_mode_text[] = {
+ "Slave", "Master"
+};
+
+static int kpcs_mode = 2;
+const char *kpcs_mode_text[] = {
+ "Off", "On"
+};
+
+static int input_clamp;
+const char *input_clamp_text[] = {
+ "Off", "On"
+};
+
+static int lineout_mode;
+const char *lineout_mode_text[] = {
+ "Off", "On"
+};
+
+static int aif2_digital_mute;
+const char *switch_mode_text[] = {
+ "Off", "On"
+};
+
+const char *mic_bias_mode_text[] = {
+ "Disable", "Force Disable", "Enable", "Force Enable"
+};
+
+static int main_mic_bias_mode;
+static int sub_mic_bias_mode;
+
+static const struct soc_enum mic_bias_mode_enum[] = {
+ SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(mic_bias_mode_text), mic_bias_mode_text),
+};
+
+#ifndef CONFIG_SEC_DEV_JACK
+/* To support PBA function test */
+static struct class *jack_class;
+static struct device *jack_dev;
+#endif
+
+#ifdef SND_USE_BIAS_LEVEL
+static bool gc2pd_fll1_active;
+struct snd_soc_dai *gc2pd_aif1_dai;
+#endif
+
+static struct platform_device *gc2pd_snd_device;
+
+static void gc2pd_gpio_init(void)
+{
+ int err;
+#ifdef CONFIG_SND_SOC_USE_EXTERNAL_MIC_BIAS
+ /* Main Microphone BIAS */
+ err = gpio_request(GPIO_MIC_BIAS_EN, "MAIN MIC");
+ if (err) {
+ pr_err(KERN_ERR "MIC_BIAS_EN GPIO set error!\n");
+ return;
+ }
+ gpio_direction_output(GPIO_MIC_BIAS_EN, 1);
+ gpio_set_value(GPIO_MIC_BIAS_EN, 0);
+ gpio_free(GPIO_MIC_BIAS_EN);
+#endif
+
+#ifdef CONFIG_SND_USE_SUB_MIC
+ /* Sub Microphone BIAS */
+ err = gpio_request(GPIO_SUB_MIC_BIAS_EN, "SUB MIC");
+ if (err) {
+ pr_err(KERN_ERR "SUB_MIC_BIAS_EN GPIO set error!\n");
+ return;
+ }
+ gpio_direction_output(GPIO_SUB_MIC_BIAS_EN, 1);
+ gpio_set_value(GPIO_SUB_MIC_BIAS_EN, 0);
+ gpio_free(GPIO_SUB_MIC_BIAS_EN);
+#endif
+
+#ifdef CONFIG_SND_USE_THIRD_MIC
+ /* Third Microphone BIAS */
+ err = gpio_request(GPIO_THIRD_MIC_BIAS_EN, "THIRD MIC");
+ if (err) {
+ pr_err(KERN_ERR "THIRD_MIC_BIAS_EN GPIO set error!\n");
+ return;
+ }
+ gpio_direction_output(GPIO_THIRD_MIC_BIAS_EN, 1);
+ gpio_set_value(GPIO_THIRD_MIC_BIAS_EN, 0);
+ gpio_free(GPIO_THIRD_MIC_BIAS_EN);
+#endif
+
+#ifdef CONFIG_FM_RADIO
+ /* FM/Third Mic GPIO */
+ err = gpio_request(GPIO_FM_MIC_SW, "GPL0");
+ if (err) {
+ pr_err(KERN_ERR "FM/THIRD_MIC Switch GPIO set error!\n");
+ return;
+ }
+ gpio_direction_output(GPIO_FM_MIC_SW, 1);
+ gpio_set_value(GPIO_FM_MIC_SW, 0);
+ gpio_free(GPIO_FM_MIC_SW);
+#endif
+
+#ifdef CONFIG_SND_USE_LINEOUT_SWITCH
+ err = gpio_request(GPIO_LINEOUT_EN, "LINEOUT_EN");
+ if (err) {
+ pr_err(KERN_ERR "LINEOUT_EN GPIO set error!\n");
+ return;
+ }
+ gpio_direction_output(GPIO_LINEOUT_EN, 1);
+ gpio_set_value(GPIO_LINEOUT_EN, 0);
+ gpio_free(GPIO_LINEOUT_EN);
+#endif
+}
+
+static const struct soc_enum lineout_mode_enum[] = {
+ SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(lineout_mode_text), lineout_mode_text),
+};
+
+static int get_lineout_mode(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ ucontrol->value.integer.value[0] = lineout_mode;
+ return 0;
+}
+
+static int set_lineout_mode(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+
+ lineout_mode = ucontrol->value.integer.value[0];
+ dev_dbg(codec->dev, "set lineout mode : %s\n",
+ lineout_mode_text[lineout_mode]);
+ return 0;
+
+}
+static const struct soc_enum aif2_mode_enum[] = {
+ SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(aif2_mode_text), aif2_mode_text),
+};
+
+static const struct soc_enum kpcs_mode_enum[] = {
+ SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(kpcs_mode_text), kpcs_mode_text),
+};
+
+static const struct soc_enum input_clamp_enum[] = {
+ SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(input_clamp_text), input_clamp_text),
+};
+
+static const struct soc_enum switch_mode_enum[] = {
+ SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(switch_mode_text), switch_mode_text),
+};
+
+static int get_aif2_mode(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ ucontrol->value.integer.value[0] = aif2_mode;
+ return 0;
+}
+
+static int set_aif2_mode(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ if (aif2_mode == ucontrol->value.integer.value[0])
+ return 0;
+
+ aif2_mode = ucontrol->value.integer.value[0];
+
+ pr_info("set aif2 mode : %s\n", aif2_mode_text[aif2_mode]);
+
+ return 0;
+}
+
+static int get_kpcs_mode(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ ucontrol->value.integer.value[0] = kpcs_mode;
+ return 0;
+}
+
+static int set_kpcs_mode(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+
+ kpcs_mode = ucontrol->value.integer.value[0];
+
+ pr_info("set kpcs mode : %d\n", kpcs_mode);
+
+ return 0;
+}
+
+static int get_input_clamp(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ ucontrol->value.integer.value[0] = input_clamp;
+ return 0;
+}
+
+static int set_input_clamp(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+
+ input_clamp = ucontrol->value.integer.value[0];
+
+ if (input_clamp) {
+ snd_soc_update_bits(codec, WM8994_INPUT_MIXER_1,
+ WM8994_INPUTS_CLAMP, WM8994_INPUTS_CLAMP);
+ msleep(100);
+ } else {
+ snd_soc_update_bits(codec, WM8994_INPUT_MIXER_1,
+ WM8994_INPUTS_CLAMP, 0);
+ }
+ pr_info("set fm input_clamp : %s\n", input_clamp_text[input_clamp]);
+
+ return 0;
+}
+
+static int get_aif2_mute_status(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ ucontrol->value.integer.value[0] = aif2_digital_mute;
+ return 0;
+}
+
+static int set_aif2_mute_status(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+ int reg;
+
+ aif2_digital_mute = ucontrol->value.integer.value[0];
+
+ if (snd_soc_read(codec, WM8994_POWER_MANAGEMENT_6)
+ & WM8994_AIF2_DACDAT_SRC)
+ aif2_digital_mute = 0;
+
+ if (aif2_digital_mute)
+ reg = WM8994_AIF1DAC1_MUTE;
+ else
+ reg = 0;
+
+ snd_soc_update_bits(codec, WM8994_AIF2_DAC_FILTERS_1,
+ WM8994_AIF1DAC1_MUTE, reg);
+
+ pr_info("set aif2_digital_mute : %s\n",
+ switch_mode_text[aif2_digital_mute]);
+
+ return 0;
+}
+
+
+static int gc2pd_ext_micbias(struct snd_soc_dapm_widget *w,
+ struct snd_kcontrol *kcontrol, int event)
+{
+ struct snd_soc_codec *codec = w->codec;
+
+ dev_dbg(codec->dev, "%s event is %02X", w->name, event);
+
+#ifdef CONFIG_SND_SOC_USE_EXTERNAL_MIC_BIAS
+ switch (event) {
+ case SND_SOC_DAPM_PRE_PMU:
+ gpio_set_value(GPIO_MIC_BIAS_EN, 1);
+ msleep(150);
+ break;
+ case SND_SOC_DAPM_POST_PMD:
+ gpio_set_value(GPIO_MIC_BIAS_EN, 0);
+ break;
+ }
+#endif
+ return 0;
+}
+
+static int gc2pd_ext_submicbias(struct snd_soc_dapm_widget *w,
+ struct snd_kcontrol *kcontrol, int event)
+{
+ struct snd_soc_codec *codec = w->codec;
+
+ dev_dbg(codec->dev, "%s event is %02X", w->name, event);
+
+#ifdef CONFIG_SND_USE_SUB_MIC
+ switch (event) {
+ case SND_SOC_DAPM_PRE_PMU:
+ gpio_set_value(GPIO_SUB_MIC_BIAS_EN, 1);
+ msleep(150);
+ break;
+ case SND_SOC_DAPM_POST_PMD:
+ gpio_set_value(GPIO_SUB_MIC_BIAS_EN, 0);
+ break;
+ }
+#endif
+ return 0;
+}
+
+static int gc2pd_ext_thirdmicbias(struct snd_soc_dapm_widget *w,
+ struct snd_kcontrol *kcontrol, int event)
+{
+ struct snd_soc_codec *codec = w->codec;
+
+ dev_dbg(codec->dev, "%s event is %02X", w->name, event);
+
+#ifdef CONFIG_SND_USE_THIRD_MIC
+ switch (event) {
+ case SND_SOC_DAPM_PRE_PMU:
+ gpio_set_value(GPIO_THIRD_MIC_BIAS_EN, 1);
+ break;
+ case SND_SOC_DAPM_POST_PMD:
+ gpio_set_value(GPIO_THIRD_MIC_BIAS_EN, 0);
+ break;
+ }
+#endif
+ return 0;
+}
+
+static int get_main_mic_bias_mode(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ ucontrol->value.integer.value[0] = main_mic_bias_mode;
+ return 0;
+}
+
+static int set_main_mic_bias_mode(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+ int status;
+
+ status = ucontrol->value.integer.value[0];
+
+ switch (status) {
+ case MIC_FORCE_ENABLE:
+ main_mic_bias_mode = status;
+ gpio_set_value(GPIO_MIC_BIAS_EN, 1);
+ break;
+ case MIC_ENABLE:
+ gpio_set_value(GPIO_MIC_BIAS_EN, 1);
+ if (main_mic_bias_mode != MIC_FORCE_ENABLE)
+ msleep(100);
+ break;
+ case MIC_FORCE_DISABLE:
+ main_mic_bias_mode = status;
+ gpio_set_value(GPIO_MIC_BIAS_EN, 0);
+ break;
+ case MIC_DISABLE:
+ if (main_mic_bias_mode != MIC_FORCE_ENABLE) {
+ gpio_set_value(GPIO_MIC_BIAS_EN, 0);
+ } else
+ dev_info(codec->dev,
+ "SKIP main mic disable=%d\n", status);
+ break;
+ default:
+ break;
+ }
+
+ dev_info(codec->dev, "main_micbias old=%d: new=%d\n",
+ main_mic_bias_mode, status);
+
+ return 0;
+
+}
+
+static int get_sub_mic_bias_mode(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ ucontrol->value.integer.value[0] = sub_mic_bias_mode;
+ return 0;
+}
+
+static int set_sub_mic_bias_mode(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+ int status,ret;
+
+ status = ucontrol->value.integer.value[0];
+
+ switch (status) {
+ case MIC_FORCE_ENABLE:
+ sub_mic_bias_mode = status;
+ case MIC_ENABLE:
+ ret = snd_soc_dapm_force_enable_pin(&codec->dapm, "MICBIAS1");
+ if (ret < 0)
+ dev_err(codec->dev, "Failed to enable MICBIAS1: %d\n", ret);
+ break;
+ case MIC_FORCE_DISABLE:
+ sub_mic_bias_mode = status;
+ ret = snd_soc_dapm_disable_pin(&codec->dapm, "MICBIAS1");
+ if (ret < 0)
+ dev_err(codec->dev, "Failed to disable MICBIAS1: %d\n", ret);
+ break;
+ case MIC_DISABLE:
+ if (sub_mic_bias_mode != MIC_FORCE_ENABLE) {
+ ret = snd_soc_dapm_disable_pin(&codec->dapm, "MICBIAS1");
+ if (ret < 0)
+ dev_err(codec->dev, "Failed to disable MICBIAS1: %d\n",
+ ret);
+ } else
+ dev_info(codec->dev,
+ "SKIP sub mic disable=%d\n", status);
+ break;
+ default:
+ break;
+ }
+
+ snd_soc_dapm_sync(&codec->dapm);
+
+ if (status == MIC_ENABLE)
+ if (sub_mic_bias_mode != MIC_FORCE_ENABLE)
+ msleep(100);
+
+ dev_info(codec->dev, "sub_micbias old=%d: new=%d\n",
+ sub_mic_bias_mode, status);
+
+ return 0;
+
+}
+
+/*
+ * gc2pd_ext_spkmode :
+ * For phone device have 1 external speaker
+ * should mix LR data in a speaker mixer (mono setting)
+ */
+static int gc2pd_ext_spkmode(struct snd_soc_dapm_widget *w,
+ struct snd_kcontrol *kcontrol, int event)
+{
+ int ret = 0;
+#ifndef CONFIG_SND_USE_STEREO_SPEAKER
+ struct snd_soc_codec *codec = w->codec;
+
+ ret = snd_soc_update_bits(codec, WM8994_SPKOUT_MIXERS,
+ WM8994_SPKMIXR_TO_SPKOUTL_MASK,
+ WM8994_SPKMIXR_TO_SPKOUTL);
+#endif
+ return ret;
+}
+
+static int gc2pd_lineout_switch(struct snd_soc_dapm_widget *w,
+ struct snd_kcontrol *kcontrol, int event)
+{
+ struct snd_soc_codec *codec = w->codec;
+
+ dev_dbg(codec->dev, "%s event is %02X", w->name, event);
+
+#if defined(CONFIG_SND_USE_MUIC_SWITCH)
+ switch (event) {
+ case SND_SOC_DAPM_POST_PMU:
+ msleep(150);
+ max77693_muic_set_audio_switch(1);
+ break;
+ case SND_SOC_DAPM_PRE_PMD:
+ max77693_muic_set_audio_switch(0);
+ break;
+ }
+#endif
+
+#ifdef CONFIG_SND_USE_LINEOUT_SWITCH
+ switch (event) {
+ case SND_SOC_DAPM_POST_PMU:
+ gpio_set_value(GPIO_LINEOUT_EN, 1);
+ break;
+ case SND_SOC_DAPM_PRE_PMD:
+ gpio_set_value(GPIO_LINEOUT_EN, 0);
+ break;
+ }
+#endif
+ return 0;
+}
+
+static void gc2pd_micd_set_rate(struct snd_soc_codec *codec)
+{
+ struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
+ int best, i, sysclk, val;
+ bool idle;
+ const struct wm8958_micd_rate *rates = NULL;
+ int num_rates = 0;
+
+ idle = !wm8994->jack_mic;
+
+ sysclk = snd_soc_read(codec, WM8994_CLOCKING_1);
+ if (sysclk & WM8994_SYSCLK_SRC)
+ sysclk = wm8994->aifclk[1];
+ else
+ sysclk = wm8994->aifclk[0];
+
+ if (wm8994->jackdet) {
+ rates = gc2pd_jackdet_rates;
+ num_rates = ARRAY_SIZE(gc2pd_jackdet_rates);
+ wm8994->pdata->micd_rates = gc2pd_jackdet_rates;
+ wm8994->pdata->num_micd_rates = num_rates;
+ } else {
+ rates = gc2pd_det_rates;
+ num_rates = ARRAY_SIZE(gc2pd_det_rates);
+ wm8994->pdata->micd_rates = gc2pd_det_rates;
+ wm8994->pdata->num_micd_rates = num_rates;
+ }
+
+ best = 0;
+ for (i = 0; i < num_rates; i++) {
+ if (rates[i].idle != idle)
+ continue;
+ if (abs(rates[i].sysclk - sysclk) <
+ abs(rates[best].sysclk - sysclk))
+ best = i;
+ else if (rates[best].idle != idle)
+ best = i;
+ }
+
+ val = rates[best].start << WM8958_MICD_BIAS_STARTTIME_SHIFT
+ | rates[best].rate << WM8958_MICD_RATE_SHIFT;
+
+ snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
+ WM8958_MICD_BIAS_STARTTIME_MASK |
+ WM8958_MICD_RATE_MASK, val);
+}
+
+#ifdef SND_USE_BIAS_LEVEL
+static void gc2pd_start_fll1(struct snd_soc_dai *aif1_dai)
+{
+ int ret;
+ if (gc2pd_fll1_active)
+ return;
+
+ dev_info(aif1_dai->dev, "Moving to audio clocking settings\n");
+
+ /* Switch AIF1 to MCLK2 while we bring stuff up */
+ ret = snd_soc_dai_set_sysclk(aif1_dai, WM8994_SYSCLK_MCLK2,
+ GC2PD_DEFAULT_MCLK2, SND_SOC_CLOCK_IN);
+ if (ret < 0)
+ dev_err(aif1_dai->dev, "Unable to switch to MCLK2: %d\n", ret);
+
+ /* Start the 24MHz clock to provide a high frequency reference to
+ * provide a high frequency reference for the FLL, giving improved
+ * performance.
+ */
+ midas_snd_set_mclk(true, true);
+
+ /* Switch the FLL */
+ ret = snd_soc_dai_set_pll(aif1_dai, WM8994_FLL1,
+ WM8994_FLL_SRC_MCLK1, GC2PD_DEFAULT_MCLK1,
+ GC2PD_DEFAULT_SYNC_CLK);
+ if (ret < 0)
+ dev_err(aif1_dai->dev, "Unable to start FLL1: %d\n", ret);
+
+ /* Then switch AIF1CLK to it */
+ ret = snd_soc_dai_set_sysclk(aif1_dai, WM8994_SYSCLK_FLL1,
+ GC2PD_DEFAULT_SYNC_CLK, SND_SOC_CLOCK_IN);
+ if (ret < 0)
+ dev_err(aif1_dai->dev, "Unable to switch to FLL1: %d\n", ret);
+
+ gc2pd_fll1_active = true;
+}
+#endif
+
+#ifdef CONFIG_USE_ADC_DET
+static int jack_get_adc_data(struct s3c_adc_client *padc)
+{
+ int adc_data;
+ int adc_max = 0;
+ int adc_min = 0xFFFF;
+ int adc_total = 0;
+ int adc_retry_cnt = 0;
+ int i;
+
+ for (i = 0; i < JACK_SAMPLE_SIZE; i++) {
+
+ adc_data = s3c_adc_read(padc, JACK_ADC_CH);
+
+ if (adc_data < 0) {
+
+ adc_retry_cnt++;
+
+ if (adc_retry_cnt > 10)
+ return adc_data;
+ }
+
+ if (i != 0) {
+ if (adc_data > adc_max)
+ adc_max = adc_data;
+ else if (adc_data < adc_min)
+ adc_min = adc_data;
+ } else {
+ adc_max = adc_data;
+ adc_min = adc_data;
+ }
+ adc_total += adc_data;
+ }
+
+ return (adc_total - adc_max - adc_min) / (JACK_SAMPLE_SIZE - 2);
+}
+
+static void determine_jack_type(struct wm1811_machine_priv *wm1811)
+{
+ struct jack_zone *zones = wm1811->zones;
+ struct snd_soc_codec *codec = wm1811->codec;
+ int size = wm1811->num_zones;
+ int count[MAX_ZONE_LIMIT] = {0};
+ int adc;
+ int i;
+
+ /* set mic bias to enable adc */
+ while (snd_soc_read(codec, WM1811_JACKDET_CTRL) & WM1811_JACKDET_LVL) {
+ adc = jack_get_adc_data(wm1811->padc);
+
+ pr_info("%s: adc = %d\n", __func__, adc);
+
+ if (adc < 0)
+ break;
+
+ /* determine the type of headset based on the
+ * adc value. An adc value can fall in various
+ * ranges or zones. Within some ranges, the type
+ * can be returned immediately. Within others, the
+ * value is considered unstable and we need to sample
+ * a few more types (up to the limit determined by
+ * the range) before we return the type for that range.
+ */
+ for (i = 0; i < size; i++) {
+ if (adc <= zones[i].adc_high) {
+ if (++count[i] > zones[i].check_count) {
+ if (recheck_jack == true && i == 4) {
+ pr_info("%s : something wrong connection!\n",
+ __func__);
+
+ recheck_jack = false;
+ return;
+ }
+ jack_set_type(wm1811,
+ zones[i].jack_type);
+ return;
+ }
+ msleep(zones[i].delay_ms);
+ break;
+ }
+ }
+ }
+
+ recheck_jack = false;
+ /* jack removed before detection complete */
+ pr_debug("%s : jack removed before detection complete\n", __func__);
+}
+
+static void jack_set_type(struct wm1811_machine_priv *wm1811, int jack_type)
+{
+ struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(wm1811->codec);
+
+ if (jack_type == SEC_HEADSET_4POLE) {
+ dev_info(wm1811->codec->dev, "Detected microphone\n");
+
+ wm8994->mic_detecting = false;
+ wm8994->jack_mic = true;
+
+ gc2pd_micd_set_rate(wm1811->codec);
+
+ snd_soc_jack_report(wm8994->micdet[0].jack, SND_JACK_HEADSET,
+ SND_JACK_HEADSET);
+
+ snd_soc_update_bits(wm1811->codec, WM8958_MIC_DETECT_1,
+ WM8958_MICD_ENA, 1);
+ } else {
+ dev_info(wm1811->codec->dev, "Detected headphone\n");
+ wm8994->mic_detecting = false;
+
+ gc2pd_micd_set_rate(wm1811->codec);
+
+ snd_soc_jack_report(wm8994->micdet[0].jack, SND_JACK_HEADPHONE,
+ SND_JACK_HEADSET);
+
+ /* If we have jackdet that will detect removal */
+ if (wm8994->jackdet) {
+ snd_soc_update_bits(wm1811->codec, WM8958_MIC_DETECT_1,
+ WM8958_MICD_ENA, 0);
+
+ if (wm8994->active_refcount) {
+ snd_soc_update_bits(wm1811->codec,
+ WM8994_ANTIPOP_2,
+ WM1811_JACKDET_MODE_MASK,
+ WM1811_JACKDET_MODE_AUDIO);
+ }
+
+ if (wm8994->pdata->jd_ext_cap) {
+ mutex_lock(&wm1811->codec->mutex);
+ snd_soc_dapm_disable_pin(&wm1811->codec->dapm,
+ "MICBIAS2");
+ snd_soc_dapm_sync(&wm1811->codec->dapm);
+ mutex_unlock(&wm1811->codec->mutex);
+ }
+ }
+ }
+}
+
+static void gc2pd_micdet(void *data)
+{
+ struct wm1811_machine_priv *wm1811 = data;
+ struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(wm1811->codec);
+
+ struct snd_soc_codec *codec = wm1811->codec;
+
+ pr_info("%s: detected jack\n", __func__);
+ wm8994->mic_detecting = true;
+
+ wake_lock_timeout(&wm1811->jackdet_wake_lock, 5 * HZ);
+
+ snd_soc_update_bits(codec, WM8958_MICBIAS2,
+ WM8958_MICB2_MODE, 0);
+ snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_1,
+ WM8994_MICB2_ENA_MASK, WM8994_MICB2_ENA);
+
+ determine_jack_type(wm1811);
+}
+#endif
+
+static void gc2pd_mic_id(void *data, u16 status)
+{
+ struct wm1811_machine_priv *wm1811 = data;
+ struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(wm1811->codec);
+
+ pr_info("%s: detected jack\n", __func__);
+ wake_lock_timeout(&wm1811->jackdet_wake_lock, 5 * HZ);
+
+ /* Either nothing present or just starting detection */
+ if (!(status & WM8958_MICD_STS)) {
+ if (!wm8994->jackdet) {
+ /* If nothing present then clear our statuses */
+ dev_dbg(wm1811->codec->dev, "Detected open circuit\n");
+ wm8994->jack_mic = false;
+ wm8994->mic_detecting = true;
+
+ gc2pd_micd_set_rate(wm1811->codec);
+
+ snd_soc_jack_report(wm8994->micdet[0].jack, 0,
+ wm8994->btn_mask |
+ SND_JACK_HEADSET);
+ }
+ /*ToDo*/
+ /*return;*/
+ }
+
+ /* If the measurement is showing a high impedence we've got a
+ * microphone.
+ */
+ if (wm8994->mic_detecting && (status & 0x400)) {
+ dev_info(wm1811->codec->dev, "Detected microphone\n");
+
+ wm8994->mic_detecting = false;
+ wm8994->jack_mic = true;
+
+ gc2pd_micd_set_rate(wm1811->codec);
+
+ snd_soc_jack_report(wm8994->micdet[0].jack, SND_JACK_HEADSET,
+ SND_JACK_HEADSET);
+ }
+
+ if (wm8994->mic_detecting && status & 0x4) {
+ dev_info(wm1811->codec->dev, "Detected headphone\n");
+ wm8994->mic_detecting = false;
+
+ gc2pd_micd_set_rate(wm1811->codec);
+
+ snd_soc_jack_report(wm8994->micdet[0].jack, SND_JACK_HEADPHONE,
+ SND_JACK_HEADSET);
+
+ /* If we have jackdet that will detect removal */
+ if (wm8994->jackdet) {
+ mutex_lock(&wm8994->accdet_lock);
+
+ snd_soc_update_bits(wm1811->codec, WM8958_MIC_DETECT_1,
+ WM8958_MICD_ENA, 0);
+
+ if (wm8994->active_refcount) {
+ snd_soc_update_bits(wm1811->codec,
+ WM8994_ANTIPOP_2,
+ WM1811_JACKDET_MODE_MASK,
+ WM1811_JACKDET_MODE_AUDIO);
+ }
+
+ mutex_unlock(&wm8994->accdet_lock);
+
+ if (wm8994->pdata->jd_ext_cap) {
+ mutex_lock(&wm1811->codec->mutex);
+ snd_soc_dapm_disable_pin(&wm1811->codec->dapm,
+ "MICBIAS2");
+ snd_soc_dapm_sync(&wm1811->codec->dapm);
+ mutex_unlock(&wm1811->codec->mutex);
+ }
+ }
+ }
+}
+
+#ifdef CONFIG_SND_SAMSUNG_I2S_MASTER
+static int set_epll_rate(unsigned long rate)
+{
+ struct clk *fout_epll;
+
+ fout_epll = clk_get(NULL, "fout_epll");
+ if (IS_ERR(fout_epll)) {
+ printk(KERN_ERR "%s: failed to get fout_epll\n", __func__);
+ return -ENOENT;
+ }
+
+ if (rate == clk_get_rate(fout_epll))
+ goto out;
+
+ clk_set_rate(fout_epll, rate);
+out:
+ clk_put(fout_epll);
+
+ return 0;
+}
+#endif /* CONFIG_SND_SAMSUNG_I2S_MASTER */
+
+#ifndef CONFIG_SND_SAMSUNG_I2S_MASTER
+static int gc2pd_wm1811_aif1_hw_params(struct snd_pcm_substream *substream,
+ struct snd_pcm_hw_params *params)
+{
+ struct snd_soc_pcm_runtime *rtd = substream->private_data;
+ struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
+ struct snd_soc_dai *codec_dai = rtd->codec_dai;
+ unsigned int pll_out;
+ int ret;
+
+ dev_info(codec_dai->dev, "%s ++\n", __func__);
+ /* AIF1CLK should be >=3MHz for optimal performance */
+ if (params_rate(params) == 8000 || params_rate(params) == 11025)
+ pll_out = params_rate(params) * 512;
+ else
+ pll_out = params_rate(params) * 256;
+
+ ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
+ | SND_SOC_DAIFMT_NB_NF
+ | SND_SOC_DAIFMT_CBM_CFM);
+ if (ret < 0)
+ return ret;
+
+ /* Set the cpu DAI configuration */
+ ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S
+ | SND_SOC_DAIFMT_NB_NF
+ | SND_SOC_DAIFMT_CBM_CFM);
+ if (ret < 0)
+ return ret;
+
+#ifndef SND_USE_BIAS_LEVEL
+ /* Switch the FLL */
+ ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL1,
+ WM8994_FLL_SRC_MCLK1, GC2PD_DEFAULT_MCLK1,
+ pll_out);
+ if (ret < 0)
+ dev_err(codec_dai->dev, "Unable to start FLL1: %d\n", ret);
+
+ ret = snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_FLL1,
+ pll_out, SND_SOC_CLOCK_IN);
+ if (ret < 0) {
+ dev_err(codec_dai->dev, "Unable to switch to FLL1: %d\n", ret);
+ return ret;
+ }
+
+ ret = snd_soc_dai_set_sysclk(cpu_dai, SAMSUNG_I2S_OPCLK,
+ 0, MOD_OPCLK_PCLK);
+ if (ret < 0)
+ return ret;
+#else
+ gc2pd_start_fll1(codec_dai);
+#endif
+
+ if (ret < 0)
+ return ret;
+
+ dev_info(codec_dai->dev, "%s --\n", __func__);
+
+ return 0;
+}
+#else /* CONFIG_SND_SAMSUNG_I2S_MASTER */
+static int gc2pd_wm1811_aif1_hw_params(struct snd_pcm_substream *substream,
+ struct snd_pcm_hw_params *params)
+{
+ struct snd_soc_pcm_runtime *rtd = substream->private_data;
+ struct snd_soc_dai *codec_dai = rtd->codec_dai;
+ struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
+ int bfs, psr, rfs, ret;
+ unsigned long rclk;
+
+ switch (params_format(params)) {
+ case SNDRV_PCM_FORMAT_U24:
+ case SNDRV_PCM_FORMAT_S24:
+ bfs = 48;
+ break;
+ case SNDRV_PCM_FORMAT_U16_LE:
+ case SNDRV_PCM_FORMAT_S16_LE:
+ bfs = 32;
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ switch (params_rate(params)) {
+ case 16000:
+ case 22050:
+ case 24000:
+ case 32000:
+ case 44100:
+ case 48000:
+ case 88200:
+ case 96000:
+ if (bfs == 48)
+ rfs = 384;
+ else
+ rfs = 256;
+ break;
+ case 64000:
+ rfs = 384;
+ break;
+ case 8000:
+ case 11025:
+ case 12000:
+ if (bfs == 48)
+ rfs = 768;
+ else
+ rfs = 512;
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ rclk = params_rate(params) * rfs;
+
+ switch (rclk) {
+ case 4096000:
+ case 5644800:
+ case 6144000:
+ case 8467200:
+ case 9216000:
+ psr = 8;
+ break;
+ case 8192000:
+ case 11289600:
+ case 12288000:
+ case 16934400:
+ case 18432000:
+ psr = 4;
+ break;
+ case 22579200:
+ case 24576000:
+ case 33868800:
+ case 36864000:
+ psr = 2;
+ break;
+ case 67737600:
+ case 73728000:
+ psr = 1;
+ break;
+ default:
+ printk(KERN_INFO "Not yet supported!\n");
+ return -EINVAL;
+ }
+
+ set_epll_rate(rclk * psr);
+
+ ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
+ | SND_SOC_DAIFMT_NB_NF
+ | SND_SOC_DAIFMT_CBS_CFS);
+ if (ret < 0)
+ return ret;
+
+ ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S
+ | SND_SOC_DAIFMT_NB_NF
+ | SND_SOC_DAIFMT_CBS_CFS);
+ if (ret < 0)
+ return ret;
+
+ ret = snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_MCLK1,
+ rclk, SND_SOC_CLOCK_IN);
+ if (ret < 0)
+ return ret;
+
+ ret = snd_soc_dai_set_sysclk(cpu_dai, SAMSUNG_I2S_CDCLK,
+ 0, SND_SOC_CLOCK_OUT);
+ if (ret < 0)
+ return ret;
+
+ ret = snd_soc_dai_set_clkdiv(cpu_dai, SAMSUNG_I2S_DIV_BCLK, bfs);
+ if (ret < 0)
+ return ret;
+
+ return 0;
+}
+#endif /* CONFIG_SND_SAMSUNG_I2S_MASTER */
+
+/*
+ * Gc2pd WM1811 DAI operations.
+ */
+static struct snd_soc_ops gc2pd_wm1811_aif1_ops = {
+ .hw_params = gc2pd_wm1811_aif1_hw_params,
+};
+
+static int gc2pd_wm1811_aif2_hw_params(struct snd_pcm_substream *substream,
+ struct snd_pcm_hw_params *params)
+{
+ struct snd_soc_pcm_runtime *rtd = substream->private_data;
+#ifndef CONFIG_MACH_BAFFIN
+ struct snd_soc_codec *codec = rtd->codec;
+#endif
+ struct snd_soc_dai *codec_dai = rtd->codec_dai;
+ int ret;
+ int prate;
+ int bclk;
+
+ dev_info(codec_dai->dev, "%s ++\n", __func__);
+ prate = params_rate(params);
+ switch (params_rate(params)) {
+ case 8000:
+ case 16000:
+ break;
+ default:
+ dev_warn(codec_dai->dev, "Unsupported LRCLK %d, falling back to 8000Hz\n",
+ (int)params_rate(params));
+ prate = 8000;
+ }
+
+#if defined(CONFIG_SEC_MODEM_GC2_ATT)
+ if (aif2_mode == 0)
+ /* Set the codec DAI configuration */
+ ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_DSP_A
+ | SND_SOC_DAIFMT_IB_NF
+ | SND_SOC_DAIFMT_CBS_CFS);
+ else
+ ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_DSP_A
+ | SND_SOC_DAIFMT_IB_NF
+ | SND_SOC_DAIFMT_CBM_CFM);
+#else
+ /* Set the codec DAI configuration, aif2_mode:0 is slave */
+ if (aif2_mode == 0)
+ ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
+ | SND_SOC_DAIFMT_NB_NF
+ | SND_SOC_DAIFMT_CBS_CFS);
+ else
+ ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
+ | SND_SOC_DAIFMT_NB_NF
+ | SND_SOC_DAIFMT_CBM_CFM);
+#endif
+
+ if (ret < 0)
+ return ret;
+
+ /* The Shannon Audio interface is setted only 2048 bclk */
+#if defined(CONFIG_SEC_MODEM_GC2_ATT)
+ switch (prate) {
+ case 8000:
+ case 16000:
+ bclk = 2048000;
+ break;
+ default:
+ return -EINVAL;
+ }
+#else
+ switch (prate) {
+ case 8000:
+ bclk = 256000;
+ break;
+ case 16000:
+ bclk = 512000;
+ break;
+ default:
+ return -EINVAL;
+ }
+#endif
+
+#ifdef SND_USE_BIAS_LEVEL
+ if (!gc2pd_fll1_active)
+ gc2pd_start_fll1(gc2pd_aif1_dai);
+#endif
+
+ if (aif2_mode == 0) {
+ ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL2,
+ WM8994_FLL_SRC_BCLK,
+ bclk, prate * 256);
+ } else {
+ ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL2,
+ WM8994_FLL_SRC_MCLK1,
+ GC2PD_DEFAULT_MCLK1, prate * 256);
+ }
+
+ if (ret < 0)
+ dev_err(codec_dai->dev, "Unable to configure FLL2: %d\n", ret);
+
+ ret = snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_FLL2,
+ prate * 256, SND_SOC_CLOCK_IN);
+ if (ret < 0)
+ dev_err(codec_dai->dev, "Unable to switch to FLL2: %d\n", ret);
+
+#ifndef CONFIG_MACH_BAFFIN
+ if (!(snd_soc_read(codec, WM8994_INTERRUPT_RAW_STATUS_2)
+ & WM8994_FLL2_LOCK_STS)) {
+ dev_info(codec_dai->dev, "%s: use mclk1 for FLL2\n", __func__);
+ ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL2,
+ WM8994_FLL_SRC_MCLK1,
+ GC2PD_DEFAULT_MCLK1, prate * 256);
+ }
+#endif
+
+ dev_info(codec_dai->dev, "%s --\n", __func__);
+ return 0;
+}
+
+static struct snd_soc_ops gc2pd_wm1811_aif2_ops = {
+ .hw_params = gc2pd_wm1811_aif2_hw_params,
+};
+
+static int gc2pd_wm1811_aif3_hw_params(struct snd_pcm_substream *substream,
+ struct snd_pcm_hw_params *params)
+{
+ pr_err("%s: enter\n", __func__);
+ return 0;
+}
+
+static struct snd_soc_ops gc2pd_wm1811_aif3_ops = {
+ .hw_params = gc2pd_wm1811_aif3_hw_params,
+};
+
+static const struct snd_kcontrol_new gc2pd_controls[] = {
+ SOC_DAPM_PIN_SWITCH("HP"),
+ SOC_DAPM_PIN_SWITCH("SPK"),
+ SOC_DAPM_PIN_SWITCH("RCV"),
+ SOC_DAPM_PIN_SWITCH("FM In"),
+ SOC_DAPM_PIN_SWITCH("LINE"),
+ SOC_DAPM_PIN_SWITCH("HDMI"),
+ SOC_DAPM_PIN_SWITCH("Main Mic"),
+ SOC_DAPM_PIN_SWITCH("Sub Mic"),
+ SOC_DAPM_PIN_SWITCH("Third Mic"),
+ SOC_DAPM_PIN_SWITCH("Headset Mic"),
+
+ SOC_ENUM_EXT("AIF2 Mode", aif2_mode_enum[0],
+ get_aif2_mode, set_aif2_mode),
+
+ SOC_ENUM_EXT("KPCS Mode", kpcs_mode_enum[0],
+ get_kpcs_mode, set_kpcs_mode),
+
+ SOC_ENUM_EXT("Input Clamp", input_clamp_enum[0],
+ get_input_clamp, set_input_clamp),
+
+ SOC_ENUM_EXT("LineoutSwitch Mode", lineout_mode_enum[0],
+ get_lineout_mode, set_lineout_mode),
+
+ SOC_ENUM_EXT("MainMicBias Mode", mic_bias_mode_enum[0],
+ get_main_mic_bias_mode, set_main_mic_bias_mode),
+
+ SOC_ENUM_EXT("SubMicBias Mode", mic_bias_mode_enum[0],
+ get_sub_mic_bias_mode, set_sub_mic_bias_mode),
+
+ SOC_ENUM_EXT("AIF2 digital mute", switch_mode_enum[0],
+ get_aif2_mute_status, set_aif2_mute_status),
+
+};
+
+const struct snd_soc_dapm_widget gc2pd_dapm_widgets[] = {
+ SND_SOC_DAPM_HP("HP", NULL),
+ SND_SOC_DAPM_SPK("SPK", gc2pd_ext_spkmode),
+ SND_SOC_DAPM_SPK("RCV", NULL),
+ SND_SOC_DAPM_LINE("LINE", gc2pd_lineout_switch),
+ SND_SOC_DAPM_LINE("HDMI", NULL),
+
+ SND_SOC_DAPM_MIC("Headset Mic", NULL),
+ SND_SOC_DAPM_MIC("Main Mic", NULL),
+ SND_SOC_DAPM_MIC("Sub Mic", NULL),
+ SND_SOC_DAPM_MIC("Third Mic", NULL),
+ SND_SOC_DAPM_LINE("FM In", NULL),
+
+ SND_SOC_DAPM_INPUT("S5P RP"),
+};
+
+const struct snd_soc_dapm_route gc2pd_dapm_routes[] = {
+ { "HP", NULL, "HPOUT1L" },
+ { "HP", NULL, "HPOUT1R" },
+
+ { "SPK", NULL, "SPKOUTLN" },
+ { "SPK", NULL, "SPKOUTLP" },
+
+ { "RCV", NULL, "HPOUT2N" },
+ { "RCV", NULL, "HPOUT2P" },
+
+ { "LINE", NULL, "LINEOUT2N" },
+ { "LINE", NULL, "LINEOUT2P" },
+
+ { "HDMI", NULL, "LINEOUT1N" },
+ { "HDMI", NULL, "LINEOUT1P" },
+#if defined(CONFIG_MACH_IPCAM)
+ { "IN2LP:VXRN", NULL, "MICBIAS1" },
+ { "IN2LN", NULL, "MICBIAS1" },
+ { "MICBIAS1", NULL, "Main Mic" },
+#else
+ { "IN2LP:VXRN", NULL, "Main Mic" },
+ { "IN2LN", NULL, "Main Mic" },
+
+ { "IN2RP:VXRP", NULL, "MICBIAS1" },
+ { "IN2RN", NULL, "MICBIAS1" },
+ { "MICBIAS1", NULL, "Sub Mic" },
+#endif
+ { "IN1LP", NULL, "MICBIAS2" },
+ { "IN1LN", NULL, "MICBIAS2" },
+ { "MICBIAS2", NULL, "Headset Mic" },
+
+ { "AIF1DAC1L", NULL, "S5P RP" },
+ { "AIF1DAC1R", NULL, "S5P RP" },
+
+ { "IN1RP", NULL, "FM In" },
+ { "IN1RN", NULL, "FM In" },
+};
+
+static struct snd_soc_dai_driver gc2pd_ext_dai[] = {
+ {
+ .name = "gc2pd.cp",
+ .playback = {
+ .channels_min = 1,
+ .channels_max = 2,
+ .rate_min = 8000,
+ .rate_max = 16000,
+ .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000,
+ .formats = SNDRV_PCM_FMTBIT_S16_LE,
+ },
+ .capture = {
+ .channels_min = 1,
+ .channels_max = 2,
+ .rate_min = 8000,
+ .rate_max = 16000,
+ .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000,
+ .formats = SNDRV_PCM_FMTBIT_S16_LE,
+ },
+ },
+ {
+ .name = "gc2pd.bt",
+ .playback = {
+ .channels_min = 1,
+ .channels_max = 2,
+ .rate_min = 8000,
+ .rate_max = 16000,
+ .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000,
+ .formats = SNDRV_PCM_FMTBIT_S16_LE,
+ },
+ .capture = {
+ .channels_min = 1,
+ .channels_max = 2,
+ .rate_min = 8000,
+ .rate_max = 16000,
+ .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000,
+ .formats = SNDRV_PCM_FMTBIT_S16_LE,
+ },
+ },
+};
+
+#ifndef CONFIG_SEC_DEV_JACK
+static ssize_t earjack_state_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct snd_soc_codec *codec = dev_get_drvdata(dev);
+ struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
+
+ int report = 0;
+
+ if ((wm8994->micdet[0].jack->status & SND_JACK_HEADPHONE) ||
+ (wm8994->micdet[0].jack->status & SND_JACK_HEADSET)) {
+ report = 1;
+ }
+
+ return sprintf(buf, "%d\n", report);
+}
+
+static ssize_t earjack_state_store(struct device *dev,
+ struct device_attribute *attr, const char *buf, size_t size)
+{
+ pr_info("%s : operate nothing\n", __func__);
+
+ return size;
+}
+
+static ssize_t earjack_key_state_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct snd_soc_codec *codec = dev_get_drvdata(dev);
+ struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
+
+ int report = 0;
+
+ if (wm8994->micdet[0].jack->status & SND_JACK_BTN_0)
+ report = 1;
+
+ return sprintf(buf, "%d\n", report);
+}
+
+static ssize_t earjack_key_state_store(struct device *dev,
+ struct device_attribute *attr, const char *buf, size_t size)
+{
+ pr_info("%s : operate nothing\n", __func__);
+
+ return size;
+}
+
+static ssize_t earjack_select_jack_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ pr_info("%s : operate nothing\n", __func__);
+
+ return 0;
+}
+
+static ssize_t earjack_select_jack_store(struct device *dev,
+ struct device_attribute *attr, const char *buf, size_t size)
+{
+ struct snd_soc_codec *codec = dev_get_drvdata(dev);
+ struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
+
+ wm8994->mic_detecting = false;
+ wm8994->jack_mic = true;
+
+ gc2pd_micd_set_rate(codec);
+
+ if ((!size) || (buf[0] != '1')) {
+ snd_soc_jack_report(wm8994->micdet[0].jack,
+ 0, SND_JACK_HEADSET);
+ dev_info(codec->dev, "Forced remove microphone\n");
+ } else {
+
+ snd_soc_jack_report(wm8994->micdet[0].jack,
+ SND_JACK_HEADSET, SND_JACK_HEADSET);
+ dev_info(codec->dev, "Forced detect microphone\n");
+ }
+
+ return size;
+}
+
+static ssize_t reselect_jack_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ pr_info("%s : operate nothing\n", __func__);
+ return 0;
+}
+
+static ssize_t reselect_jack_store(struct device *dev,
+ struct device_attribute *attr, const char *buf, size_t size)
+{
+ struct snd_soc_codec *codec = dev_get_drvdata(dev);
+ struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
+ int reg = 0;
+
+ reg = snd_soc_read(codec, WM8958_MIC_DETECT_3);
+ if (reg == 0x402) {
+ dev_info(codec->dev, "Detected open circuit\n");
+
+ snd_soc_update_bits(codec, WM8958_MICBIAS2,
+ WM8958_MICB2_DISCH, WM8958_MICB2_DISCH);
+ /* Enable debounce while removed */
+ snd_soc_update_bits(codec, WM1811_JACKDET_CTRL,
+ WM1811_JACKDET_DB, WM1811_JACKDET_DB);
+
+ wm8994->mic_detecting = false;
+ wm8994->jack_mic = false;
+ snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
+ WM8958_MICD_ENA, 0);
+
+ if (wm8994->active_refcount) {
+ snd_soc_update_bits(codec,
+ WM8994_ANTIPOP_2,
+ WM1811_JACKDET_MODE_MASK,
+ WM1811_JACKDET_MODE_AUDIO);
+ } else {
+ snd_soc_update_bits(codec,
+ WM8994_ANTIPOP_2,
+ WM1811_JACKDET_MODE_MASK,
+ WM1811_JACKDET_MODE_JACK);
+ }
+
+ snd_soc_jack_report(wm8994->micdet[0].jack, 0,
+ SND_JACK_MECHANICAL | SND_JACK_HEADSET |
+ wm8994->btn_mask);
+ }
+ return size;
+}
+
+static DEVICE_ATTR(reselect_jack, S_IRUGO | S_IWUSR | S_IWGRP,
+ reselect_jack_show, reselect_jack_store);
+
+static DEVICE_ATTR(select_jack, S_IRUGO | S_IWUSR | S_IWGRP,
+ earjack_select_jack_show, earjack_select_jack_store);
+
+static DEVICE_ATTR(key_state, S_IRUGO | S_IWUSR | S_IWGRP,
+ earjack_key_state_show, earjack_key_state_store);
+
+static DEVICE_ATTR(state, S_IRUGO | S_IWUSR | S_IWGRP,
+ earjack_state_show, earjack_state_store);
+#endif
+
+static int gc2pd_wm1811_init_paiftx(struct snd_soc_pcm_runtime *rtd)
+{
+ struct snd_soc_codec *codec = rtd->codec;
+ struct wm1811_machine_priv *wm1811
+ = snd_soc_card_get_drvdata(codec->card);
+ struct snd_soc_dai *aif1_dai = rtd->codec_dai;
+ struct wm8994 *control = codec->control_data;
+ struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
+#ifdef CONFIG_EXYNOS_SOUND_PLATFORM_DATA
+ const struct exynos_sound_platform_data *sound_pdata;
+#endif
+ int ret;
+#ifdef CONFIG_EXYNOS_SOUND_PLATFORM_DATA
+ sound_pdata = exynos_sound_get_platform_data();
+#endif
+
+#ifdef SND_USE_BIAS_LEVEL
+ gc2pd_aif1_dai = aif1_dai;
+#endif
+
+ midas_snd_set_mclk(true, false);
+
+ rtd->codec_dai->driver->playback.channels_max =
+ rtd->cpu_dai->driver->playback.channels_max;
+
+ ret = snd_soc_add_controls(codec, gc2pd_controls,
+ ARRAY_SIZE(gc2pd_controls));
+
+ ret = snd_soc_dapm_new_controls(&codec->dapm, gc2pd_dapm_widgets,
+ ARRAY_SIZE(gc2pd_dapm_widgets));
+ if (ret != 0)
+ dev_err(codec->dev, "Failed to add DAPM widgets: %d\n", ret);
+
+ ret = snd_soc_dapm_add_routes(&codec->dapm, gc2pd_dapm_routes,
+ ARRAY_SIZE(gc2pd_dapm_routes));
+ if (ret != 0)
+ dev_err(codec->dev, "Failed to add DAPM routes: %d\n", ret);
+
+ ret = snd_soc_dai_set_sysclk(aif1_dai, WM8994_SYSCLK_MCLK2,
+ GC2PD_DEFAULT_MCLK2, SND_SOC_CLOCK_IN);
+ if (ret < 0)
+ dev_err(codec->dev, "Failed to boot clocking\n");
+
+ /* Force AIF1CLK on as it will be master for jack detection */
+ if (wm8994->revision > 1) {
+ ret = snd_soc_dapm_force_enable_pin(&codec->dapm, "AIF1CLK");
+ if (ret < 0)
+ dev_err(codec->dev, "Failed to enable AIF1CLK: %d\n",
+ ret);
+ }
+
+ ret = snd_soc_dapm_disable_pin(&codec->dapm, "S5P RP");
+ if (ret < 0)
+ dev_err(codec->dev, "Failed to disable S5P RP: %d\n", ret);
+
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "RCV");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "SPK");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "HP");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "Headset Mic");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "Sub Mic");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "Main Mic");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "AIF1DACDAT");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "AIF2DACDAT");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "AIF3DACDAT");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "AIF1ADCDAT");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "AIF2ADCDAT");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "AIF3ADCDAT");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "FM In");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "LINE");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "HDMI");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "Third Mic");
+
+ wm1811->codec = codec;
+
+ /* Configure Hidden registers of WM1811 to conform of
+ * the Samsung's standard Revision 1.1 for earphones */
+ snd_soc_write(codec, 0x102, 0x3);
+ snd_soc_write(codec, 0xcb, 0x5151);
+ snd_soc_write(codec, 0xd3, 0x3f3f);
+ snd_soc_write(codec, 0xd4, 0x3f3f);
+ snd_soc_write(codec, 0xd5, 0x3f3f);
+ snd_soc_write(codec, 0xd6, 0x3228);
+ snd_soc_write(codec, 0x102, 0x0);
+
+ gc2pd_micd_set_rate(codec);
+
+#ifdef CONFIG_SEC_DEV_JACK
+ /* By default use idle_bias_off, will override for WM8994 */
+ codec->dapm.idle_bias_off = 0;
+#else /* CONFIG_SEC_DEV_JACK */
+ wm1811->jack.status = 0;
+
+ ret = snd_soc_jack_new(codec, "Gc2pd Jack",
+ SND_JACK_HEADSET | SND_JACK_BTN_0 |
+ SND_JACK_BTN_1 | SND_JACK_BTN_2,
+ &wm1811->jack);
+
+ if (ret < 0)
+ dev_err(codec->dev, "Failed to create jack: %d\n", ret);
+
+ ret = snd_jack_set_key(wm1811->jack.jack, SND_JACK_BTN_0, KEY_MEDIA);
+
+ if (ret < 0)
+ dev_err(codec->dev, "Failed to set KEY_MEDIA: %d\n", ret);
+
+ ret = snd_jack_set_key(wm1811->jack.jack, SND_JACK_BTN_1,
+ KEY_VOLUMEUP);
+ if (ret < 0)
+ dev_err(codec->dev, "Failed to set KEY_VOLUMEUP: %d\n", ret);
+
+ ret = snd_jack_set_key(wm1811->jack.jack, SND_JACK_BTN_2,
+ KEY_VOLUMEDOWN);
+
+ if (ret < 0)
+ dev_err(codec->dev, "Failed to set KEY_VOLUMEDOWN: %d\n", ret);
+
+ if (wm8994->revision > 1) {
+ dev_info(codec->dev, "wm1811: Rev %c support mic detection\n",
+ 'A' + wm8994->revision);
+#ifdef CONFIG_EXYNOS_SOUND_PLATFORM_DATA
+#ifdef CONFIG_USE_ADC_DET
+ if (sound_pdata->use_jackdet_type) {
+ ret = wm8958_mic_detect(codec, &wm1811->jack,
+ gc2pd_micdet, wm1811, NULL, NULL);
+ } else {
+ ret = wm8958_mic_detect(codec, &wm1811->jack, NULL,
+ NULL, gc2pd_mic_id, wm1811);
+ }
+#else
+ ret = wm8958_mic_detect(codec, &wm1811->jack, NULL,
+ NULL, gc2pd_mic_id, wm1811);
+#endif
+#else
+ ret = wm8958_mic_detect(codec, &wm1811->jack, NULL,
+ NULL, gc2pd_mic_id, wm1811);
+#endif
+
+ if (ret < 0)
+ dev_err(codec->dev, "Failed start detection: %d\n",
+ ret);
+ } else {
+ dev_info(codec->dev, "wm1811: Rev %c doesn't support mic detection\n",
+ 'A' + wm8994->revision);
+ codec->dapm.idle_bias_off = 0;
+ }
+ /* To wakeup for earjack event in suspend mode */
+ enable_irq_wake(control->irq);
+
+ wake_lock_init(&wm1811->jackdet_wake_lock,
+ WAKE_LOCK_SUSPEND, "gc2pd_jackdet");
+
+ /* To support PBA function test */
+ jack_class = class_create(THIS_MODULE, "audio");
+
+ if (IS_ERR(jack_class))
+ pr_err("Failed to create class\n");
+
+ jack_dev = device_create(jack_class, NULL, 0, codec, "earjack");
+
+ if (device_create_file(jack_dev, &dev_attr_select_jack) < 0)
+ pr_err("Failed to create device file (%s)!\n",
+ dev_attr_select_jack.attr.name);
+
+ if (device_create_file(jack_dev, &dev_attr_key_state) < 0)
+ pr_err("Failed to create device file (%s)!\n",
+ dev_attr_key_state.attr.name);
+
+ if (device_create_file(jack_dev, &dev_attr_state) < 0)
+ pr_err("Failed to create device file (%s)!\n",
+ dev_attr_state.attr.name);
+
+ if (device_create_file(jack_dev, &dev_attr_reselect_jack) < 0)
+ pr_err("Failed to create device file (%s)!\n",
+ dev_attr_reselect_jack.attr.name);
+
+#endif /* CONFIG_SEC_DEV_JACK */
+
+#ifdef CONFIG_USE_ADC_DET
+ pr_info("%s: register adc client\n", __func__);
+ wm1811->padc = s3c_adc_register(gc2pd_snd_device, NULL, NULL, 0);
+#endif
+
+ return snd_soc_dapm_sync(&codec->dapm);
+}
+
+static struct snd_soc_dai_link gc2pd_dai[] = {
+ { /* Sec_Fifo DAI i/f */
+ .name = "Sec_FIFO TX",
+ .stream_name = "Sec_Dai",
+ .cpu_dai_name = "samsung-i2s.4",
+ .codec_dai_name = "wm8994-aif1",
+#ifndef CONFIG_SND_SOC_SAMSUNG_USE_DMA_WRAPPER
+ .platform_name = "samsung-audio-idma",
+#else
+ .platform_name = "samsung-audio",
+#endif
+ .codec_name = "wm8994-codec",
+ .init = gc2pd_wm1811_init_paiftx,
+ .ops = &gc2pd_wm1811_aif1_ops,
+ },
+ {
+ .name = "Gc2pd_WM1811 Voice",
+ .stream_name = "Voice Tx/Rx",
+ .cpu_dai_name = "gc2pd.cp",
+ .codec_dai_name = "wm8994-aif2",
+ .platform_name = "snd-soc-dummy",
+ .codec_name = "wm8994-codec",
+ .ops = &gc2pd_wm1811_aif2_ops,
+ .ignore_suspend = 1,
+ },
+ {
+ .name = "Gc2pd_WM1811 BT",
+ .stream_name = "BT Tx/Rx",
+ .cpu_dai_name = "gc2pd.bt",
+ .codec_dai_name = "wm8994-aif3",
+ .platform_name = "snd-soc-dummy",
+ .codec_name = "wm8994-codec",
+ .ops = &gc2pd_wm1811_aif3_ops,
+ .ignore_suspend = 1,
+ },
+ { /* Primary DAI i/f */
+ .name = "WM8994 AIF1",
+ .stream_name = "Pri_Dai",
+ .cpu_dai_name = "samsung-i2s.0",
+ .codec_dai_name = "wm8994-aif1",
+ .platform_name = "samsung-audio",
+ .codec_name = "wm8994-codec",
+ .ops = &gc2pd_wm1811_aif1_ops,
+ },
+};
+
+static int gc2pd_card_suspend_pre(struct snd_soc_card *card)
+{
+ struct snd_soc_codec *codec = card->rtd->codec;
+ struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
+
+#ifdef CONFIG_SEC_DEV_JACK
+ snd_soc_dapm_disable_pin(&codec->dapm, "AIF1CLK");
+#endif
+
+ return 0;
+}
+
+static int gc2pd_card_suspend_post(struct snd_soc_card *card)
+{
+ struct snd_soc_codec *codec = card->rtd->codec;
+ struct snd_soc_dai *aif1_dai = card->rtd[0].codec_dai;
+ struct snd_soc_dai *aif2_dai = card->rtd[1].codec_dai;
+ int ret;
+
+ if (!codec->active) {
+#ifndef SND_USE_BIAS_LEVEL
+ ret = snd_soc_dai_set_sysclk(aif2_dai,
+ WM8994_SYSCLK_MCLK2,
+ GC2PD_DEFAULT_MCLK2,
+ SND_SOC_CLOCK_IN);
+
+ if (ret < 0)
+ dev_err(codec->dev, "Unable to switch to MCLK2: %d\n",
+ ret);
+
+ ret = snd_soc_dai_set_pll(aif2_dai, WM8994_FLL2, 0, 0, 0);
+
+ if (ret < 0)
+ dev_err(codec->dev, "Unable to stop FLL2\n");
+
+ ret = snd_soc_dai_set_sysclk(aif1_dai,
+ WM8994_SYSCLK_MCLK2,
+ GC2PD_DEFAULT_MCLK2,
+ SND_SOC_CLOCK_IN);
+ if (ret < 0)
+ dev_err(codec->dev, "Unable to switch to MCLK2\n");
+
+ ret = snd_soc_dai_set_pll(aif1_dai, WM8994_FLL1, 0, 0, 0);
+
+ if (ret < 0)
+ dev_err(codec->dev, "Unable to stop FLL1\n");
+#endif
+
+ midas_snd_set_mclk(false, true);
+ }
+
+#ifdef CONFIG_ARCH_EXYNOS5
+ exynos5_sys_powerdown_xxti_control(midas_snd_get_mclk() ? 1 : 0);
+#else /* for CONFIG_ARCH_EXYNOS5 */
+ exynos4_sys_powerdown_xusbxti_control(midas_snd_get_mclk() ? 1 : 0);
+#endif
+
+ return 0;
+}
+
+static int gc2pd_card_resume_pre(struct snd_soc_card *card)
+{
+ struct snd_soc_dai *aif1_dai = card->rtd[0].codec_dai;
+ int ret;
+
+ midas_snd_set_mclk(true, false);
+
+#ifndef SND_USE_BIAS_LEVEL
+ /* Switch the FLL */
+ ret = snd_soc_dai_set_pll(aif1_dai, WM8994_FLL1,
+ WM8994_FLL_SRC_MCLK1,
+ GC2PD_DEFAULT_MCLK1,
+ GC2PD_DEFAULT_SYNC_CLK);
+
+ if (ret < 0)
+ dev_err(aif1_dai->dev, "Unable to start FLL1: %d\n", ret);
+
+ /* Then switch AIF1CLK to it */
+ ret = snd_soc_dai_set_sysclk(aif1_dai,
+ WM8994_SYSCLK_FLL1,
+ GC2PD_DEFAULT_SYNC_CLK,
+ SND_SOC_CLOCK_IN);
+
+ if (ret < 0)
+ dev_err(aif1_dai->dev, "Unable to switch to FLL1: %d\n", ret);
+#endif
+
+ return 0;
+}
+
+static int gc2pd_card_resume_post(struct snd_soc_card *card)
+{
+ struct snd_soc_codec *codec = card->rtd->codec;
+ int reg = 0;
+
+ /* workaround for jack detection
+ * sometimes WM8994_GPIO_1 type changed wrong function type
+ * so if type mismatched, update to IRQ type
+ */
+ reg = snd_soc_read(codec, WM8994_GPIO_1);
+
+ if ((reg & WM8994_GPN_FN_MASK) != WM8994_GP_FN_IRQ) {
+ dev_err(codec->dev, "%s: GPIO1 type 0x%x\n", __func__, reg);
+ snd_soc_write(codec, WM8994_GPIO_1, WM8994_GP_FN_IRQ);
+ }
+
+#ifdef CONFIG_SEC_DEV_JACK
+ snd_soc_dapm_force_enable_pin(&codec->dapm, "AIF1CLK");
+#endif
+
+ return 0;
+}
+
+#ifdef SND_USE_BIAS_LEVEL
+static int gc2pd_set_bias_level(struct snd_soc_card *card,
+ struct snd_soc_dapm_context *dapm,
+ enum snd_soc_bias_level level)
+{
+ struct snd_soc_dai *aif1_dai = card->rtd[0].codec_dai;
+
+ if (dapm->dev != aif1_dai->dev)
+ return 0;
+
+ switch (level) {
+ case SND_SOC_BIAS_PREPARE:
+ gc2pd_start_fll1(card->rtd[0].codec_dai);
+ break;
+
+ default:
+ break;
+ }
+
+ return 0;
+}
+
+static int gc2pd_set_bias_level_post(struct snd_soc_card *card,
+ struct snd_soc_dapm_context *dapm,
+ enum snd_soc_bias_level level)
+{
+ struct snd_soc_codec *codec = card->rtd->codec;
+ struct snd_soc_dai *aif1_dai = card->rtd[0].codec_dai;
+ struct snd_soc_dai *aif2_dai = card->rtd[1].codec_dai;
+ int ret;
+
+ if (dapm->dev != aif1_dai->dev)
+ return 0;
+
+ switch (level) {
+ case SND_SOC_BIAS_STANDBY:
+
+ /* When going idle stop FLL1 and revert to using MCLK2
+ * directly for minimum power consumptin for accessory
+ * detection.
+ */
+ if (card->dapm.bias_level == SND_SOC_BIAS_PREPARE) {
+ dev_info(aif1_dai->dev, "Moving to STANDBY\n");
+
+ ret = snd_soc_dai_set_sysclk(aif2_dai,
+ WM8994_SYSCLK_MCLK2,
+ GC2PD_DEFAULT_MCLK2,
+ SND_SOC_CLOCK_IN);
+ if (ret < 0)
+ dev_err(codec->dev, "Failed to switch to MCLK2\n");
+
+ ret = snd_soc_dai_set_pll(aif2_dai, WM8994_FLL2,
+ 0, 0, 0);
+
+ if (ret < 0)
+ dev_err(codec->dev,
+ "Failed to change FLL2\n");
+
+ ret = snd_soc_dai_set_sysclk(aif1_dai,
+ WM8994_SYSCLK_MCLK2,
+ GC2PD_DEFAULT_MCLK2,
+ SND_SOC_CLOCK_IN);
+ if (ret < 0)
+ dev_err(codec->dev,
+ "Failed to switch to MCLK2\n");
+
+ ret = snd_soc_dai_set_pll(aif1_dai, WM8994_FLL1,
+ 0, 0, 0);
+ if (ret < 0)
+ dev_err(codec->dev,
+ "Failed to stop FLL1\n");
+
+
+ gc2pd_fll1_active = false;
+ midas_snd_set_mclk(false, false);
+ }
+
+ break;
+ default:
+ break;
+ }
+
+ card->dapm.bias_level = level;
+
+ return 0;
+}
+#endif
+
+static struct snd_soc_card gc2pd = {
+ .name = "Gc2pd_WM1811",
+ .dai_link = gc2pd_dai,
+
+ /* If you want to use sec_fifo device,
+ * changes the num_link = 2 or ARRAY_SIZE(gc2pd_dai). */
+ .num_links = ARRAY_SIZE(gc2pd_dai),
+
+#ifdef SND_USE_BIAS_LEVEL
+ .set_bias_level = gc2pd_set_bias_level,
+ .set_bias_level_post = gc2pd_set_bias_level_post,
+#endif
+
+ .suspend_post = gc2pd_card_suspend_post,
+ .resume_pre = gc2pd_card_resume_pre,
+ .suspend_pre = gc2pd_card_suspend_pre,
+ .resume_post = gc2pd_card_resume_post
+};
+
+static int __init gc2pd_audio_init(void)
+{
+ struct wm1811_machine_priv *wm1811;
+#ifdef CONFIG_EXYNOS_SOUND_PLATFORM_DATA
+ const struct exynos_sound_platform_data *sound_pdata;
+#endif
+ int ret;
+
+ wm1811 = kzalloc(sizeof *wm1811, GFP_KERNEL);
+ if (!wm1811) {
+ pr_err("Failed to allocate memory\n");
+ ret = -ENOMEM;
+ goto err_kzalloc;
+ }
+ snd_soc_card_set_drvdata(&gc2pd, wm1811);
+
+ gc2pd_snd_device = platform_device_alloc("soc-audio", -1);
+ if (!gc2pd_snd_device) {
+ ret = -ENOMEM;
+ goto err_device_alloc;
+ }
+
+ ret = snd_soc_register_dais(&gc2pd_snd_device->dev, gc2pd_ext_dai,
+ ARRAY_SIZE(gc2pd_ext_dai));
+ if (ret != 0)
+ pr_err("Failed to register external DAIs: %d\n", ret);
+
+ platform_set_drvdata(gc2pd_snd_device, &gc2pd);
+
+ ret = platform_device_add(gc2pd_snd_device);
+ if (ret)
+ platform_device_put(gc2pd_snd_device);
+
+#ifdef CONFIG_EXYNOS_SOUND_PLATFORM_DATA
+ sound_pdata = exynos_sound_get_platform_data();
+ if (!sound_pdata)
+ pr_info("%s: don't use sound pdata\n", __func__);
+#ifdef CONFIG_USE_ADC_DET
+ if (sound_pdata->zones) {
+ wm1811->zones = sound_pdata->zones;
+ wm1811->num_zones = sound_pdata->num_zones;
+ }
+ pr_info("%s:use_jackdet_type = %d\n", __func__,
+ sound_pdata->use_jackdet_type);
+ wm1811->use_jackdet_type = sound_pdata->use_jackdet_type;
+#endif
+#endif
+
+ gc2pd_gpio_init();
+
+ return ret;
+
+err_device_alloc:
+ kfree(wm1811);
+err_kzalloc:
+ return ret;
+}
+module_init(gc2pd_audio_init);
+
+static void __exit gc2pd_audio_exit(void)
+{
+ struct snd_soc_card *card = &gc2pd;
+ struct wm1811_machine_priv *wm1811 = snd_soc_card_get_drvdata(card);
+#ifdef CONFIG_USE_ADC_DET
+ s3c_adc_release(wm1811->padc);
+#endif
+ platform_device_unregister(gc2pd_snd_device);
+ kfree(wm1811);
+}
+module_exit(gc2pd_audio_exit);
+
+MODULE_AUTHOR("DI Kim <deokil.kim@samsung.com>");
+MODULE_DESCRIPTION("ALSA SoC Gc2pd WM1811");
+MODULE_LICENSE("GPL");
diff --git a/sound/soc/samsung/gd2_wm1811.c b/sound/soc/samsung/gd2_wm1811.c
new file mode 100644
index 0000000..4566997
--- /dev/null
+++ b/sound/soc/samsung/gd2_wm1811.c
@@ -0,0 +1,1814 @@
+/*
+ * gd2_wm1811.c
+ *
+ * Copyright (c) 2011 Samsung Electronics Co. Ltd
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ */
+#include <linux/platform_device.h>
+#include <linux/clk.h>
+#include <linux/io.h>
+#include <linux/gpio.h>
+#include <linux/delay.h>
+#include <linux/slab.h>
+#include <linux/workqueue.h>
+#include <linux/input.h>
+#include <linux/wakelock.h>
+#include <linux/suspend.h>
+#include <linux/irq.h>
+#include <linux/interrupt.h>
+
+#include <sound/soc.h>
+#include <sound/soc-dapm.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include <sound/jack.h>
+
+#include <mach/regs-clock.h>
+#include <mach/pmu.h>
+#include <mach/midas-sound.h>
+
+#include <linux/mfd/wm8994/core.h>
+#include <linux/mfd/wm8994/registers.h>
+#include <linux/mfd/wm8994/pdata.h>
+#include <linux/mfd/wm8994/gpio.h>
+
+#include <linux/exynos_audio.h>
+
+#ifdef CONFIG_USE_ADC_DET
+#include <plat/adc.h>
+#endif
+
+#if defined(CONFIG_SND_USE_MUIC_SWITCH)
+#include <linux/mfd/max77693-private.h>
+#endif
+
+
+#include "i2s.h"
+#include "s3c-i2s-v2.h"
+#include "../codecs/wm8994.h"
+
+
+#define MIDAS_DEFAULT_MCLK1 24000000
+#define MIDAS_DEFAULT_MCLK2 32768
+#define MIDAS_DEFAULT_SYNC_CLK 11289600
+
+#define WM1811_JACKDET_MODE_NONE 0x0000
+#define WM1811_JACKDET_MODE_JACK 0x0100
+#define WM1811_JACKDET_MODE_MIC 0x0080
+#define WM1811_JACKDET_MODE_AUDIO 0x0180
+
+#define WM1811_JACKDET_BTN0 0x04
+#define WM1811_JACKDET_BTN1 0x10
+#define WM1811_JACKDET_BTN2 0x08
+
+#define WM1811_MIC_IRQ_NUM (IRQ_BOARD_CODEC_START + WM8994_IRQ_MIC1_DET)
+#define WM1811_JACKDET_IRQ_NUM (IRQ_BOARD_CODEC_START + WM8994_IRQ_GPIO(6))
+
+#define MIC_DISABLE 0
+#define MIC_ENABLE 1
+#define MIC_FORCE_DISABLE 2
+#define MIC_FORCE_ENABLE 3
+
+#define JACK_ADC_CH 3
+#define JACK_SAMPLE_SIZE 5
+
+#define MAX_ZONE_LIMIT 10
+/* keep this value if you support double-pressed concept */
+#define WAKE_LOCK_TIME (HZ * 5) /* 5 sec */
+#define EAR_CHECK_LOOP_CNT 10
+
+struct wm1811_machine_priv {
+ struct snd_soc_jack jack;
+ struct snd_soc_codec *codec;
+ struct wake_lock jackdet_wake_lock;
+ void (*lineout_switch_f) (int on);
+ void (*set_main_mic_f) (int on);
+ void (*set_sub_mic_f) (int on);
+ void (*set_ext_mic_f) (int on);
+ int (*get_g_det_value_f) (void);
+ int (*get_g_det_irq_num_f) (void);
+#ifdef CONFIG_USE_ADC_DET
+ struct s3c_adc_client *padc;
+ struct jack_zone *zones;
+ int num_zones;
+ int use_jackdet_type;
+#endif
+};
+
+enum {
+ SEC_JACK_NO_DEVICE = 0x0,
+ SEC_HEADSET_4POLE = 0x01 << 0,
+ SEC_HEADSET_3POLE = 0x01 << 1,
+ SEC_TTY_DEVICE = 0x01 << 2,
+ SEC_FM_HEADSET = 0x01 << 3,
+ SEC_FM_SPEAKER = 0x01 << 4,
+ SEC_TVOUT_DEVICE = 0x01 << 5,
+ SEC_EXTRA_DOCK_SPEAKER = 0x01 << 6,
+ SEC_EXTRA_CAR_DOCK_SPEAKER = 0x01 << 7,
+ SEC_UNKNOWN_DEVICE = 0x01 << 8,
+};
+
+#ifdef CONFIG_USE_ADC_DET
+static bool recheck_jack;
+static int jack_get_adc_data(struct s3c_adc_client *padc);
+static void jack_set_type(struct wm1811_machine_priv *wm1811, int jack_type);
+#endif
+
+static struct wm8958_micd_rate gd2_det_rates[] = {
+ { MIDAS_DEFAULT_MCLK2, true, 0, 0 },
+ { MIDAS_DEFAULT_MCLK2, false, 0, 0 },
+ { MIDAS_DEFAULT_SYNC_CLK, true, 7, 7 },
+ { MIDAS_DEFAULT_SYNC_CLK, false, 7, 7 },
+};
+
+static struct wm8958_micd_rate gd2_jackdet_rates[] = {
+ { MIDAS_DEFAULT_MCLK2, true, 0, 0 },
+ { MIDAS_DEFAULT_MCLK2, false, 0, 0 },
+ { MIDAS_DEFAULT_SYNC_CLK, true, 12, 12 },
+ { MIDAS_DEFAULT_SYNC_CLK, false, 7, 8 },
+};
+
+static int aif2_mode;
+const char *aif2_mode_text[] = {
+ "Slave", "Master"
+};
+
+const char *switch_mode_text[] = {
+ "Off", "On"
+};
+
+const char *mic_bias_mode_text[] = {
+ "Disable", "Force Disable", "Enable", "Force Enable"
+};
+
+static int input_clamp;
+static int lineout_mode;
+static int aif2_digital_mute;
+static int main_mic_bias_mode;
+static int sub_mic_bias_mode;
+static int ext_mic_bias_mode;
+
+#ifndef CONFIG_SEC_DEV_JACK
+/* To support PBA function test */
+static struct class *jack_class;
+static struct device *jack_dev;
+#endif
+
+static struct platform_device *gd2_snd_device;
+
+static const struct soc_enum switch_mode_enum[] = {
+ SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(switch_mode_text), switch_mode_text),
+};
+
+static const struct soc_enum aif2_mode_enum[] = {
+ SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(aif2_mode_text), aif2_mode_text),
+};
+
+static const struct soc_enum mic_bias_mode_enum[] = {
+ SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(mic_bias_mode_text), mic_bias_mode_text),
+};
+
+static const struct soc_enum sub_bias_mode_enum[] = {
+ SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(mic_bias_mode_text), mic_bias_mode_text),
+};
+
+static const struct soc_enum ext_bias_mode_enum[] = {
+ SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(mic_bias_mode_text), mic_bias_mode_text),
+};
+
+static int get_lineout_mode(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ ucontrol->value.integer.value[0] = lineout_mode;
+ return 0;
+}
+
+static int set_lineout_mode(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+ struct wm1811_machine_priv *wm1811
+ = snd_soc_card_get_drvdata(codec->card);
+
+ lineout_mode = ucontrol->value.integer.value[0];
+
+ if (lineout_mode) {
+ wm8994_vmid_mode(codec, WM8994_VMID_FORCE);
+ if (wm1811->lineout_switch_f)
+ wm1811->lineout_switch_f(1);
+ } else {
+ if (wm1811->lineout_switch_f)
+ wm1811->lineout_switch_f(0);
+ wm8994_vmid_mode(codec, WM8994_VMID_NORMAL);
+ }
+
+ dev_info(codec->dev, "set lineout mode : %s\n",
+ switch_mode_text[lineout_mode]);
+ return 0;
+
+}
+
+static int get_aif2_mode(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ ucontrol->value.integer.value[0] = aif2_mode;
+ return 0;
+}
+
+static int set_aif2_mode(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ if (aif2_mode == ucontrol->value.integer.value[0])
+ return 0;
+
+ aif2_mode = ucontrol->value.integer.value[0];
+
+ pr_info("set aif2 mode : %s\n", aif2_mode_text[aif2_mode]);
+
+ return 0;
+}
+
+static int get_input_clamp(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ ucontrol->value.integer.value[0] = input_clamp;
+ return 0;
+}
+
+static int set_input_clamp(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+
+ input_clamp = ucontrol->value.integer.value[0];
+
+ if (input_clamp) {
+ snd_soc_update_bits(codec, WM8994_INPUT_MIXER_1,
+ WM8994_INPUTS_CLAMP, WM8994_INPUTS_CLAMP);
+ msleep(100);
+ } else {
+ snd_soc_update_bits(codec, WM8994_INPUT_MIXER_1,
+ WM8994_INPUTS_CLAMP, 0);
+ }
+ pr_info("set fm input_clamp : %s\n", switch_mode_text[input_clamp]);
+
+ return 0;
+}
+
+static int get_aif2_mute_status(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ ucontrol->value.integer.value[0] = aif2_digital_mute;
+ return 0;
+}
+
+static int set_aif2_mute_status(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+ int reg;
+
+ aif2_digital_mute = ucontrol->value.integer.value[0];
+
+ if (snd_soc_read(codec, WM8994_POWER_MANAGEMENT_6)
+ & WM8994_AIF2_DACDAT_SRC)
+ aif2_digital_mute = 0;
+
+ if (aif2_digital_mute)
+ reg = WM8994_AIF1DAC1_MUTE;
+ else
+ reg = 0;
+
+ snd_soc_update_bits(codec, WM8994_AIF2_DAC_FILTERS_1,
+ WM8994_AIF1DAC1_MUTE, reg);
+
+ pr_info("set aif2_digital_mute : %s\n",
+ switch_mode_text[aif2_digital_mute]);
+
+ return 0;
+}
+
+static int get_sub_mic_bias_mode(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ ucontrol->value.integer.value[0] = sub_mic_bias_mode;
+ return 0;
+}
+
+static int set_sub_mic_bias_mode(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+ struct wm1811_machine_priv *wm1811
+ = snd_soc_card_get_drvdata(codec->card);
+ int status = 0;
+
+ status = ucontrol->value.integer.value[0];
+
+ switch (status) {
+ case MIC_FORCE_ENABLE:
+ sub_mic_bias_mode = status;
+ snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_1,
+ WM8994_MICB1_ENA, WM8994_MICB1_ENA);
+
+ if (wm1811->set_sub_mic_f)
+ wm1811->set_sub_mic_f(1);
+ break;
+ case MIC_ENABLE:
+ snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_1,
+ WM8994_MICB1_ENA, WM8994_MICB1_ENA);
+ if (wm1811->set_sub_mic_f)
+ wm1811->set_sub_mic_f(1);
+ if (sub_mic_bias_mode != MIC_FORCE_ENABLE)
+ msleep(100);
+ break;
+ case MIC_FORCE_DISABLE:
+ sub_mic_bias_mode = status;
+ snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_1,
+ WM8994_MICB1_ENA, 0);
+
+ if (wm1811->set_sub_mic_f)
+ wm1811->set_sub_mic_f(0);
+ break;
+ case MIC_DISABLE:
+ if (sub_mic_bias_mode != MIC_FORCE_ENABLE) {
+ snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_1,
+ WM8994_MICB1_ENA, 0);
+ if (wm1811->set_sub_mic_f)
+ wm1811->set_sub_mic_f(0);
+ } else
+ dev_info(codec->dev,
+ "SKIP submic disable=%d\n", status);
+ break;
+ default:
+ break;
+ }
+
+ dev_info(codec->dev, "sub_mic_bias_mod=%d: status=%d\n",
+ sub_mic_bias_mode, status);
+
+ return 0;
+
+}
+
+static int get_main_mic_bias_mode(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ ucontrol->value.integer.value[0] = main_mic_bias_mode;
+ return 0;
+}
+
+static int set_main_mic_bias_mode(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+ struct wm1811_machine_priv *wm1811
+ = snd_soc_card_get_drvdata(codec->card);
+ int status = 0;
+
+ status = ucontrol->value.integer.value[0];
+
+ switch (status) {
+ case MIC_FORCE_ENABLE:
+ main_mic_bias_mode = status;
+
+ if (wm1811->set_main_mic_f)
+ wm1811->set_main_mic_f(1);
+ break;
+ case MIC_ENABLE:
+ if (wm1811->set_main_mic_f)
+ wm1811->set_main_mic_f(1);
+ if (main_mic_bias_mode != MIC_FORCE_ENABLE)
+ msleep(100);
+ break;
+ case MIC_FORCE_DISABLE:
+ main_mic_bias_mode = status;
+
+ if (wm1811->set_main_mic_f)
+ wm1811->set_main_mic_f(0);
+ break;
+ case MIC_DISABLE:
+ if (main_mic_bias_mode != MIC_FORCE_ENABLE) {
+ if (wm1811->set_main_mic_f)
+ wm1811->set_main_mic_f(0);
+ } else
+ dev_info(codec->dev,
+ "SKIP mainmic disable=%d\n", status);
+ break;
+ default:
+ break;
+ }
+
+ dev_info(codec->dev, "main_mic_bias_mod=%d: status=%d\n",
+ main_mic_bias_mode, status);
+
+ return 0;
+
+}
+
+static int get_ext_mic_bias_mode(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ ucontrol->value.integer.value[0] = ext_mic_bias_mode;
+ return 0;
+}
+
+static int set_ext_mic_bias_mode(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+ struct wm1811_machine_priv *wm1811
+ = snd_soc_card_get_drvdata(codec->card);
+ int status = 0;
+
+ status = ucontrol->value.integer.value[0];
+
+ switch (status) {
+ case MIC_FORCE_ENABLE:
+ ext_mic_bias_mode = status;
+
+ if (wm1811->set_ext_mic_f)
+ wm1811->set_ext_mic_f(1);
+ break;
+ case MIC_ENABLE:
+ if (wm1811->set_ext_mic_f)
+ wm1811->set_ext_mic_f(1);
+ if (ext_mic_bias_mode != MIC_FORCE_ENABLE)
+ msleep(100);
+ break;
+ case MIC_FORCE_DISABLE:
+ ext_mic_bias_mode = status;
+
+ if (wm1811->set_ext_mic_f)
+ wm1811->set_ext_mic_f(0);
+ break;
+ case MIC_DISABLE:
+ if (ext_mic_bias_mode != MIC_FORCE_ENABLE) {
+ if (wm1811->set_ext_mic_f)
+ wm1811->set_ext_mic_f(0);
+ } else
+ dev_info(codec->dev,
+ "SKIP ext mic disable=%d\n", status);
+ break;
+ default:
+ break;
+ }
+
+ dev_info(codec->dev, "ext_mic_bias_mode=%d: status=%d\n",
+ ext_mic_bias_mode, status);
+
+ return 0;
+
+}
+
+static int set_ext_micbias(struct snd_soc_dapm_widget *w,
+ struct snd_kcontrol *kcontrol, int event)
+{
+ struct snd_soc_codec *codec = w->codec;
+ struct wm1811_machine_priv *wm1811
+ = snd_soc_card_get_drvdata(codec->card);
+
+ dev_info(codec->dev, "%s event is %02X", w->name, event);
+
+ switch (event) {
+ case SND_SOC_DAPM_PRE_PMU:
+ if (wm1811->set_main_mic_f)
+ wm1811->set_main_mic_f(1);
+ break;
+ case SND_SOC_DAPM_POST_PMD:
+ if (wm1811->set_main_mic_f)
+ wm1811->set_main_mic_f(0);
+ break;
+ }
+
+ return 0;
+}
+
+static int set_ext_submicbias(struct snd_soc_dapm_widget *w,
+ struct snd_kcontrol *kcontrol, int event)
+{
+ struct snd_soc_codec *codec = w->codec;
+ struct wm1811_machine_priv *wm1811
+ = snd_soc_card_get_drvdata(codec->card);
+
+ dev_info(codec->dev, "%s event is %02X", w->name, event);
+
+ switch (event) {
+ case SND_SOC_DAPM_PRE_PMU:
+ if (wm1811->set_sub_mic_f)
+ wm1811->set_sub_mic_f(1);
+ break;
+ case SND_SOC_DAPM_POST_PMD:
+ if (wm1811->set_sub_mic_f)
+ wm1811->set_sub_mic_f(0);
+ break;
+ }
+
+ return 0;
+}
+
+static int set_muic_switch(struct snd_soc_dapm_widget *w,
+ struct snd_kcontrol *kcontrol, int event)
+{
+ struct snd_soc_codec *codec = w->codec;
+
+ dev_info(codec->dev, "%s event is %02X", w->name, event);
+
+#if defined(CONFIG_SND_USE_MUIC_SWITCH)
+ switch (event) {
+ case SND_SOC_DAPM_POST_PMU:
+ msleep(150);
+ max77693_muic_set_audio_switch(1);
+ break;
+ case SND_SOC_DAPM_PRE_PMD:
+ max77693_muic_set_audio_switch(0);
+ break;
+ }
+#endif
+
+ return 0;
+}
+
+static void gd2_micd_set_rate(struct snd_soc_codec *codec)
+{
+ struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
+ int best, i, sysclk, val;
+ bool idle;
+ const struct wm8958_micd_rate *rates = NULL;
+ int num_rates = 0;
+
+ idle = !wm8994->jack_mic;
+
+ sysclk = snd_soc_read(codec, WM8994_CLOCKING_1);
+ if (sysclk & WM8994_SYSCLK_SRC)
+ sysclk = wm8994->aifclk[1];
+ else
+ sysclk = wm8994->aifclk[0];
+
+ if (wm8994->jackdet) {
+ rates = gd2_jackdet_rates;
+ num_rates = ARRAY_SIZE(gd2_jackdet_rates);
+ wm8994->pdata->micd_rates = gd2_jackdet_rates;
+ wm8994->pdata->num_micd_rates = num_rates;
+ } else {
+ rates = gd2_det_rates;
+ num_rates = ARRAY_SIZE(gd2_det_rates);
+ wm8994->pdata->micd_rates = gd2_det_rates;
+ wm8994->pdata->num_micd_rates = num_rates;
+ }
+
+ best = 0;
+ for (i = 0; i < num_rates; i++) {
+ if (rates[i].idle != idle)
+ continue;
+ if (abs(rates[i].sysclk - sysclk) <
+ abs(rates[best].sysclk - sysclk))
+ best = i;
+ else if (rates[best].idle != idle)
+ best = i;
+ }
+
+ val = rates[best].start << WM8958_MICD_BIAS_STARTTIME_SHIFT
+ | rates[best].rate << WM8958_MICD_RATE_SHIFT;
+
+ snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
+ WM8958_MICD_BIAS_STARTTIME_MASK |
+ WM8958_MICD_RATE_MASK, val);
+}
+
+#ifdef CONFIG_USE_ADC_DET
+static int jack_get_adc_data(struct s3c_adc_client *padc)
+{
+ int adc_data;
+ int adc_max = 0;
+ int adc_min = 0xFFFF;
+ int adc_total = 0;
+ int adc_retry_cnt = 0;
+ int i;
+
+ for (i = 0; i < JACK_SAMPLE_SIZE; i++) {
+
+ adc_data = s3c_adc_read(padc, JACK_ADC_CH);
+
+ if (adc_data < 0) {
+
+ adc_retry_cnt++;
+
+ if (adc_retry_cnt > 10)
+ return adc_data;
+ }
+
+ if (i != 0) {
+ if (adc_data > adc_max)
+ adc_max = adc_data;
+ else if (adc_data < adc_min)
+ adc_min = adc_data;
+ } else {
+ adc_max = adc_data;
+ adc_min = adc_data;
+ }
+ adc_total += adc_data;
+ }
+
+ return (adc_total - adc_max - adc_min) / (JACK_SAMPLE_SIZE - 2);
+}
+
+static void determine_jack_type(struct wm1811_machine_priv *wm1811)
+{
+ struct jack_zone *zones = wm1811->zones;
+ struct snd_soc_codec *codec = wm1811->codec;
+ int size = wm1811->num_zones;
+ int count[MAX_ZONE_LIMIT] = {0};
+ int adc;
+ int i;
+
+ /* set mic bias to enable adc */
+ while (snd_soc_read(codec, WM1811_JACKDET_CTRL) & WM1811_JACKDET_LVL) {
+ adc = jack_get_adc_data(wm1811->padc);
+
+ pr_info("%s: adc = %d\n", __func__, adc);
+
+ if (adc < 0)
+ break;
+
+ /* determine the type of headset based on the
+ * adc value. An adc value can fall in various
+ * ranges or zones. Within some ranges, the type
+ * can be returned immediately. Within others, the
+ * value is considered unstable and we need to sample
+ * a few more types (up to the limit determined by
+ * the range) before we return the type for that range.
+ */
+ for (i = 0; i < size; i++) {
+ if (adc <= zones[i].adc_high) {
+ if (++count[i] > zones[i].check_count) {
+ if (recheck_jack == true && i == 4) {
+ pr_info("%s : something wrong connection!\n",
+ __func__);
+
+ recheck_jack = false;
+ return;
+ }
+ jack_set_type(wm1811,
+ zones[i].jack_type);
+ return;
+ }
+ msleep(zones[i].delay_ms);
+ break;
+ }
+ }
+ }
+
+ recheck_jack = false;
+ /* jack removed before detection complete */
+ pr_debug("%s : jack removed before detection complete\n", __func__);
+}
+
+static void jack_set_type(struct wm1811_machine_priv *wm1811, int jack_type)
+{
+ struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(wm1811->codec);
+
+ if (jack_type == SEC_HEADSET_4POLE) {
+ dev_info(wm1811->codec->dev, "Detected microphone\n");
+
+ wm8994->mic_detecting = false;
+ wm8994->jack_mic = true;
+
+ gd2_micd_set_rate(wm1811->codec);
+
+ snd_soc_jack_report(wm8994->micdet[0].jack, SND_JACK_HEADSET,
+ SND_JACK_HEADSET);
+
+ snd_soc_update_bits(wm1811->codec, WM8958_MIC_DETECT_1,
+ WM8958_MICD_ENA, 1);
+ } else {
+ dev_info(wm1811->codec->dev, "Detected headphone\n");
+ wm8994->mic_detecting = false;
+
+ gd2_micd_set_rate(wm1811->codec);
+
+ snd_soc_jack_report(wm8994->micdet[0].jack, SND_JACK_HEADPHONE,
+ SND_JACK_HEADSET);
+
+ /* If we have jackdet that will detect removal */
+ if (wm8994->jackdet) {
+ snd_soc_update_bits(wm1811->codec, WM8958_MIC_DETECT_1,
+ WM8958_MICD_ENA, 0);
+
+ if (wm8994->active_refcount) {
+ snd_soc_update_bits(wm1811->codec,
+ WM8994_ANTIPOP_2,
+ WM1811_JACKDET_MODE_MASK,
+ WM1811_JACKDET_MODE_AUDIO);
+ }
+
+ if (wm8994->pdata->jd_ext_cap) {
+ mutex_lock(&wm1811->codec->mutex);
+ snd_soc_dapm_disable_pin(&wm1811->codec->dapm,
+ "MICBIAS2");
+ snd_soc_dapm_sync(&wm1811->codec->dapm);
+ mutex_unlock(&wm1811->codec->mutex);
+ }
+ }
+ }
+}
+
+static void gd2_micdet(void *data)
+{
+ struct wm1811_machine_priv *wm1811 = data;
+ struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(wm1811->codec);
+
+ struct snd_soc_codec *codec = wm1811->codec;
+
+ pr_info("%s: detected jack\n", __func__);
+ wm8994->mic_detecting = true;
+
+ wake_lock_timeout(&wm1811->jackdet_wake_lock, 5 * HZ);
+
+ snd_soc_update_bits(codec, WM8958_MICBIAS2,
+ WM8958_MICB2_MODE, 0);
+
+ /* Apply delay time(150ms) to remove pop noise
+ * during to enable micbias */
+ msleep(150);
+
+ determine_jack_type(wm1811);
+ }
+#endif
+
+static void gd2_mic_id(void *data, u16 status)
+{
+ struct wm1811_machine_priv *wm1811 = data;
+ struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(wm1811->codec);
+
+ pr_info("%s: detected jack\n", __func__);
+ wake_lock_timeout(&wm1811->jackdet_wake_lock, 5 * HZ);
+
+ /* Either nothing present or just starting detection */
+ if (!(status & WM8958_MICD_STS)) {
+ if (!wm8994->jackdet) {
+ /* If nothing present then clear our statuses */
+ dev_dbg(wm1811->codec->dev, "Detected open circuit\n");
+ wm8994->jack_mic = false;
+ wm8994->mic_detecting = true;
+
+ gd2_micd_set_rate(wm1811->codec);
+
+ snd_soc_jack_report(wm8994->micdet[0].jack, 0,
+ wm8994->btn_mask |
+ SND_JACK_HEADSET);
+ }
+ /*ToDo*/
+ /*return;*/
+ }
+
+ /* If the measurement is showing a high impedence we've got a
+ * microphone.
+ */
+ if (wm8994->mic_detecting && (status & 0x400)) {
+ dev_info(wm1811->codec->dev, "Detected microphone\n");
+
+ wm8994->mic_detecting = false;
+ wm8994->jack_mic = true;
+
+ gd2_micd_set_rate(wm1811->codec);
+
+ snd_soc_jack_report(wm8994->micdet[0].jack, SND_JACK_HEADSET,
+ SND_JACK_HEADSET);
+ }
+
+ if (wm8994->mic_detecting && status & 0x4) {
+ dev_info(wm1811->codec->dev, "Detected headphone\n");
+ wm8994->mic_detecting = false;
+
+ gd2_micd_set_rate(wm1811->codec);
+
+ snd_soc_jack_report(wm8994->micdet[0].jack, SND_JACK_HEADPHONE,
+ SND_JACK_HEADSET);
+
+ /* If we have jackdet that will detect removal */
+ if (wm8994->jackdet) {
+ mutex_lock(&wm8994->accdet_lock);
+
+ snd_soc_update_bits(wm1811->codec, WM8958_MIC_DETECT_1,
+ WM8958_MICD_ENA, 0);
+
+ if (wm8994->active_refcount) {
+ snd_soc_update_bits(wm1811->codec,
+ WM8994_ANTIPOP_2,
+ WM1811_JACKDET_MODE_MASK,
+ WM1811_JACKDET_MODE_AUDIO);
+ }
+
+ mutex_unlock(&wm8994->accdet_lock);
+
+ if (wm8994->pdata->jd_ext_cap) {
+ mutex_lock(&wm1811->codec->mutex);
+ snd_soc_dapm_disable_pin(&wm1811->codec->dapm,
+ "MICBIAS2");
+ snd_soc_dapm_sync(&wm1811->codec->dapm);
+ mutex_unlock(&wm1811->codec->mutex);
+ }
+ }
+ }
+}
+
+static int gd2_wm1811_aif1_hw_params(struct snd_pcm_substream *substream,
+ struct snd_pcm_hw_params *params)
+{
+ struct snd_soc_pcm_runtime *rtd = substream->private_data;
+ struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
+ struct snd_soc_dai *codec_dai = rtd->codec_dai;
+ unsigned int pll_out;
+ int ret;
+
+ dev_info(codec_dai->dev, "%s ++\n", __func__);
+ /* AIF1CLK should be >=3MHz for optimal performance */
+ if (params_rate(params) == 8000 || params_rate(params) == 11025)
+ pll_out = params_rate(params) * 512;
+ else
+ pll_out = params_rate(params) * 256;
+
+ ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
+ | SND_SOC_DAIFMT_NB_NF
+ | SND_SOC_DAIFMT_CBM_CFM);
+ if (ret < 0)
+ return ret;
+
+ /* Set the cpu DAI configuration */
+ ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S
+ | SND_SOC_DAIFMT_NB_NF
+ | SND_SOC_DAIFMT_CBM_CFM);
+ if (ret < 0)
+ return ret;
+
+ /* Switch the FLL */
+ ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL1,
+ WM8994_FLL_SRC_MCLK1, MIDAS_DEFAULT_MCLK1,
+ pll_out);
+ if (ret < 0)
+ dev_err(codec_dai->dev, "Unable to start FLL1: %d\n", ret);
+
+ ret = snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_FLL1,
+ pll_out, SND_SOC_CLOCK_IN);
+ if (ret < 0) {
+ dev_err(codec_dai->dev, "Unable to switch to FLL1: %d\n", ret);
+ return ret;
+ }
+
+ ret = snd_soc_dai_set_sysclk(cpu_dai, SAMSUNG_I2S_OPCLK,
+ 0, MOD_OPCLK_PCLK);
+ if (ret < 0)
+ return ret;
+
+ dev_info(codec_dai->dev, "%s --\n", __func__);
+
+ return 0;
+}
+
+/*
+ * GD2 WM1811 DAI operations.
+ */
+static struct snd_soc_ops gd2_wm1811_aif1_ops = {
+ .hw_params = gd2_wm1811_aif1_hw_params,
+};
+
+static int gd2_wm1811_aif2_hw_params(struct snd_pcm_substream *substream,
+ struct snd_pcm_hw_params *params)
+{
+ struct snd_soc_pcm_runtime *rtd = substream->private_data;
+ struct snd_soc_codec *codec = rtd->codec;
+ struct snd_soc_dai *codec_dai = rtd->codec_dai;
+ int ret;
+ int prate;
+ int bclk;
+
+ dev_info(codec_dai->dev, "%s ++\n", __func__);
+ prate = params_rate(params);
+ switch (params_rate(params)) {
+ case 8000:
+ case 16000:
+ case 32000:
+ break;
+ default:
+ dev_warn(codec_dai->dev, "Unsupported LRCLK %d, falling back to 8000Hz\n",
+ (int)params_rate(params));
+ prate = 8000;
+ }
+
+ /* Set the codec DAI configuration, aif2_mode:0 is slave */
+ if (aif2_mode == 0)
+ ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
+ | SND_SOC_DAIFMT_NB_NF
+ | SND_SOC_DAIFMT_CBS_CFS);
+ else
+ ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
+ | SND_SOC_DAIFMT_NB_NF
+ | SND_SOC_DAIFMT_CBM_CFM);
+
+ if (ret < 0)
+ return ret;
+
+ switch (prate) {
+ case 8000:
+ bclk = 256000;
+ break;
+ case 16000:
+ bclk = 512000;
+ break;
+ case 32000:
+ bclk = 256000;
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ if (aif2_mode == 0) {
+ ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL2,
+ WM8994_FLL_SRC_BCLK,
+ bclk, prate * 256);
+ } else {
+ ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL2,
+ WM8994_FLL_SRC_MCLK1,
+ MIDAS_DEFAULT_MCLK1, prate * 256);
+ }
+
+ if (ret < 0)
+ dev_err(codec_dai->dev, "Unable to configure FLL2: %d\n", ret);
+
+ ret = snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_FLL2,
+ prate * 256, SND_SOC_CLOCK_IN);
+ if (ret < 0)
+ dev_err(codec_dai->dev, "Unable to switch to FLL2: %d\n", ret);
+
+ if (!(snd_soc_read(codec, WM8994_INTERRUPT_RAW_STATUS_2)
+ & WM8994_FLL2_LOCK_STS)) {
+ dev_info(codec_dai->dev, "%s: use mclk1 for FLL2\n", __func__);
+ ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL2,
+ WM8994_FLL_SRC_MCLK1,
+ MIDAS_DEFAULT_MCLK1, prate * 256);
+ }
+
+ dev_info(codec_dai->dev, "%s --\n", __func__);
+ return 0;
+}
+
+static struct snd_soc_ops gd2_wm1811_aif2_ops = {
+ .hw_params = gd2_wm1811_aif2_hw_params,
+};
+
+static int gd2_wm1811_aif3_hw_params(struct snd_pcm_substream *substream,
+ struct snd_pcm_hw_params *params)
+{
+ pr_err("%s: enter\n", __func__);
+ return 0;
+}
+
+static bool playback_stream_status;
+static bool capture_stream_status;
+
+static int gd2_wm1811_aif3_startup(struct snd_pcm_substream *substream)
+{
+ struct snd_soc_pcm_runtime *rtd = substream->private_data;
+ struct snd_soc_codec *codec = rtd->codec;
+ struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
+ struct wm8994_pdata *pdata = wm8994->pdata;
+ int base = WM8994_GPIO_8 - WM8994_GPIO_1;
+ int i;
+
+ pr_err("%s: enter\n", __func__);
+
+ if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
+ capture_stream_status = 1;
+ else
+ playback_stream_status = 1;
+
+ for (i = 0; i < 4; i++) {
+ if (pdata->gpio_defaults[base + i]) {
+ snd_soc_update_bits(wm8994->codec, WM8994_GPIO_8 + i,
+ 0xffff,
+ pdata->gpio_defaults[base + i]);
+ }
+ }
+ return 0;
+}
+
+static void gd2_wm1811_aif3_shutdown(struct snd_pcm_substream *substream)
+{
+ struct snd_soc_pcm_runtime *rtd = substream->private_data;
+ struct snd_soc_codec *codec = rtd->codec;
+ struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
+ int i;
+
+ pr_err("%s: enter, stream=%d\n", __func__, substream->stream);
+
+ if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
+ capture_stream_status = 0;
+ else
+ playback_stream_status = 0;
+
+ if (playback_stream_status || capture_stream_status)
+ return;
+
+ pr_info("%s: set input gpios for AIF3\n", __func__);
+
+ for (i = 0; i < 4; i++) {
+ snd_soc_update_bits(wm8994->codec, WM8994_GPIO_8 + i,
+ 0xffff,
+ 0xA101);
+ }
+ return;
+}
+
+static struct snd_soc_ops gd2_wm1811_aif3_ops = {
+ .startup = gd2_wm1811_aif3_startup,
+ .shutdown = gd2_wm1811_aif3_shutdown,
+ .hw_params = gd2_wm1811_aif3_hw_params,
+};
+
+static const struct snd_kcontrol_new gd2_controls[] = {
+ SOC_DAPM_PIN_SWITCH("HP"),
+ SOC_DAPM_PIN_SWITCH("SPK"),
+ SOC_DAPM_PIN_SWITCH("RCV"),
+ SOC_DAPM_PIN_SWITCH("FM In"),
+ SOC_DAPM_PIN_SWITCH("LINE"),
+ SOC_DAPM_PIN_SWITCH("HDMI"),
+ SOC_DAPM_PIN_SWITCH("Main Mic"),
+ SOC_DAPM_PIN_SWITCH("Sub Mic"),
+ SOC_DAPM_PIN_SWITCH("Headset Mic"),
+
+ SOC_ENUM_EXT("AIF2 Mode", aif2_mode_enum[0],
+ get_aif2_mode, set_aif2_mode),
+
+ SOC_ENUM_EXT("Input Clamp", switch_mode_enum[0],
+ get_input_clamp, set_input_clamp),
+
+ SOC_ENUM_EXT("LineoutSwitch Mode", switch_mode_enum[0],
+ get_lineout_mode, set_lineout_mode),
+
+ SOC_ENUM_EXT("MainMicBias Mode", mic_bias_mode_enum[0],
+ get_main_mic_bias_mode, set_main_mic_bias_mode),
+
+ SOC_ENUM_EXT("SubMicBias Mode", mic_bias_mode_enum[0],
+ get_sub_mic_bias_mode, set_sub_mic_bias_mode),
+
+ SOC_ENUM_EXT("ExtMicEn Mode", mic_bias_mode_enum[0],
+ get_ext_mic_bias_mode, set_ext_mic_bias_mode),
+
+ SOC_ENUM_EXT("AIF2 digital mute", switch_mode_enum[0],
+ get_aif2_mute_status, set_aif2_mute_status),
+};
+
+const struct snd_soc_dapm_widget gd2_dapm_widgets[] = {
+ SND_SOC_DAPM_HP("HP", NULL),
+ SND_SOC_DAPM_SPK("SPK", NULL),
+ SND_SOC_DAPM_SPK("RCV", NULL),
+ SND_SOC_DAPM_LINE("LINE", set_muic_switch),
+ SND_SOC_DAPM_LINE("HDMI", NULL),
+
+ SND_SOC_DAPM_MIC("Headset Mic", NULL),
+ SND_SOC_DAPM_MIC("Main Mic", NULL),
+ SND_SOC_DAPM_MIC("Sub Mic", NULL),
+ SND_SOC_DAPM_LINE("FM In", NULL),
+
+ SND_SOC_DAPM_INPUT("S5P RP"),
+};
+
+const struct snd_soc_dapm_route gd2_dapm_routes[] = {
+ { "HP", NULL, "HPOUT1L" },
+ { "HP", NULL, "HPOUT1R" },
+
+ { "SPK", NULL, "SPKOUTLN" },
+ { "SPK", NULL, "SPKOUTLP" },
+
+ { "RCV", NULL, "HPOUT2N" },
+ { "RCV", NULL, "HPOUT2P" },
+
+ { "LINE", NULL, "LINEOUT2N" },
+ { "LINE", NULL, "LINEOUT2P" },
+
+ { "HDMI", NULL, "LINEOUT1N" },
+ { "HDMI", NULL, "LINEOUT1P" },
+
+ { "IN2LP:VXRN", NULL, "Main Mic" },
+ { "IN2LN", NULL, "Main Mic" },
+
+ { "IN2RP:VXRP", NULL, "Sub Mic" },
+ { "IN2RN", NULL, "Sub Mic" },
+
+ { "IN1LP", NULL, "MICBIAS2" },
+ { "MICBIAS2", NULL, "Headset Mic" },
+ { "IN1LN", NULL, "MICBIAS2" },
+ { "MICBIAS2", NULL, "Headset Mic" },
+
+ { "AIF1DAC1L", NULL, "S5P RP" },
+ { "AIF1DAC1R", NULL, "S5P RP" },
+
+ { "IN1RP", NULL, "FM In" },
+ { "IN1RN", NULL, "FM In" },
+};
+
+static struct snd_soc_dai_driver gd2_ext_dai[] = {
+ {
+ .name = "gd2.cp",
+ .playback = {
+ .channels_min = 1,
+ .channels_max = 2,
+ .rate_min = 8000,
+ .rate_max = 16000,
+ .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000,
+ .formats = SNDRV_PCM_FMTBIT_S16_LE,
+ },
+ .capture = {
+ .channels_min = 1,
+ .channels_max = 2,
+ .rate_min = 8000,
+ .rate_max = 32000,
+ .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000
+ | SNDRV_PCM_RATE_32000,
+ .formats = SNDRV_PCM_FMTBIT_S16_LE,
+ },
+ },
+ {
+ .name = "gd2.bt",
+ .playback = {
+ .channels_min = 1,
+ .channels_max = 2,
+ .rate_min = 8000,
+ .rate_max = 16000,
+ .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000,
+ .formats = SNDRV_PCM_FMTBIT_S16_LE,
+ },
+ .capture = {
+ .channels_min = 1,
+ .channels_max = 2,
+ .rate_min = 8000,
+ .rate_max = 16000,
+ .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000,
+ .formats = SNDRV_PCM_FMTBIT_S16_LE,
+ },
+ },
+};
+
+#ifndef CONFIG_SEC_DEV_JACK
+static ssize_t earjack_state_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct snd_soc_codec *codec = dev_get_drvdata(dev);
+ struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
+
+ int report = 0;
+
+ if ((wm8994->micdet[0].jack->status & SND_JACK_HEADPHONE) ||
+ (wm8994->micdet[0].jack->status & SND_JACK_HEADSET)) {
+ report = 1;
+ }
+
+ return sprintf(buf, "%d\n", report);
+}
+
+static ssize_t earjack_state_store(struct device *dev,
+ struct device_attribute *attr, const char *buf, size_t size)
+{
+ pr_info("%s : operate nothing\n", __func__);
+
+ return size;
+}
+
+static ssize_t earjack_key_state_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct snd_soc_codec *codec = dev_get_drvdata(dev);
+ struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
+
+ int report = 0;
+
+ if (wm8994->micdet[0].jack->status & SND_JACK_BTN_0)
+ report = 1;
+
+ return sprintf(buf, "%d\n", report);
+}
+
+static ssize_t earjack_key_state_store(struct device *dev,
+ struct device_attribute *attr, const char *buf, size_t size)
+{
+ pr_info("%s : operate nothing\n", __func__);
+
+ return size;
+}
+
+static ssize_t earjack_select_jack_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ pr_info("%s : operate nothing\n", __func__);
+
+ return 0;
+}
+
+static ssize_t earjack_select_jack_store(struct device *dev,
+ struct device_attribute *attr, const char *buf, size_t size)
+{
+ struct snd_soc_codec *codec = dev_get_drvdata(dev);
+ struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
+
+ wm8994->mic_detecting = false;
+ wm8994->jack_mic = true;
+
+ gd2_micd_set_rate(codec);
+
+ if ((!size) || (buf[0] != '1')) {
+ snd_soc_jack_report(wm8994->micdet[0].jack,
+ 0, SND_JACK_HEADSET);
+ dev_info(codec->dev, "Forced remove microphone\n");
+ } else {
+
+ snd_soc_jack_report(wm8994->micdet[0].jack,
+ SND_JACK_HEADSET, SND_JACK_HEADSET);
+ dev_info(codec->dev, "Forced detect microphone\n");
+ }
+
+ return size;
+}
+
+static ssize_t reselect_jack_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ pr_info("%s : operate nothing\n", __func__);
+ return 0;
+}
+
+static ssize_t reselect_jack_store(struct device *dev,
+ struct device_attribute *attr, const char *buf, size_t size)
+{
+ pr_info("%s : operate nothing\n", __func__);
+ return size;
+}
+
+static DEVICE_ATTR(reselect_jack, S_IRUGO | S_IWUSR | S_IWGRP,
+ reselect_jack_show, reselect_jack_store);
+
+static DEVICE_ATTR(select_jack, S_IRUGO | S_IWUSR | S_IWGRP,
+ earjack_select_jack_show, earjack_select_jack_store);
+
+static DEVICE_ATTR(key_state, S_IRUGO | S_IWUSR | S_IWGRP,
+ earjack_key_state_show, earjack_key_state_store);
+
+static DEVICE_ATTR(state, S_IRUGO | S_IWUSR | S_IWGRP,
+ earjack_state_show, earjack_state_store);
+#endif
+
+static int gd2_wm1811_init_paiftx(struct snd_soc_pcm_runtime *rtd)
+{
+ struct snd_soc_codec *codec = rtd->codec;
+ struct wm1811_machine_priv *wm1811
+ = snd_soc_card_get_drvdata(codec->card);
+ struct snd_soc_dai *aif1_dai = rtd->codec_dai;
+ struct wm8994 *control = codec->control_data;
+ struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
+ const struct exynos_sound_platform_data *sound_pdata;
+ int ret;
+
+ sound_pdata = exynos_sound_get_platform_data();
+
+ midas_snd_set_mclk(true, false);
+
+ rtd->codec_dai->driver->playback.channels_max =
+ rtd->cpu_dai->driver->playback.channels_max;
+
+ ret = snd_soc_add_controls(codec, gd2_controls,
+ ARRAY_SIZE(gd2_controls));
+
+ ret = snd_soc_dapm_new_controls(&codec->dapm, gd2_dapm_widgets,
+ ARRAY_SIZE(gd2_dapm_widgets));
+ if (ret != 0)
+ dev_err(codec->dev, "Failed to add DAPM widgets: %d\n", ret);
+
+ ret = snd_soc_dapm_add_routes(&codec->dapm, gd2_dapm_routes,
+ ARRAY_SIZE(gd2_dapm_routes));
+ if (ret != 0)
+ dev_err(codec->dev, "Failed to add DAPM routes: %d\n", ret);
+
+ ret = snd_soc_dai_set_sysclk(aif1_dai, WM8994_SYSCLK_MCLK2,
+ MIDAS_DEFAULT_MCLK2, SND_SOC_CLOCK_IN);
+ if (ret < 0)
+ dev_err(codec->dev, "Failed to boot clocking\n");
+
+ /* Force AIF1CLK on as it will be master for jack detection */
+ if (wm8994->revision > 1) {
+ ret = snd_soc_dapm_force_enable_pin(&codec->dapm, "AIF1CLK");
+ if (ret < 0)
+ dev_err(codec->dev, "Failed to enable AIF1CLK: %d\n",
+ ret);
+ }
+
+ ret = snd_soc_dapm_disable_pin(&codec->dapm, "S5P RP");
+ if (ret < 0)
+ dev_err(codec->dev, "Failed to disable S5P RP: %d\n", ret);
+
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "RCV");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "SPK");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "HP");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "Headset Mic");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "Sub Mic");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "Main Mic");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "AIF1DACDAT");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "AIF2DACDAT");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "AIF3DACDAT");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "AIF1ADCDAT");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "AIF2ADCDAT");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "AIF3ADCDAT");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "FM In");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "LINE");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "HDMI");
+
+ wm1811->codec = codec;
+
+ /* Configure Hidden registers of WM1811 to conform of
+ * the Samsung's standard Revision 1.1 for earphones */
+ snd_soc_write(codec, 0x102, 0x3);
+ snd_soc_write(codec, 0xcb, 0x5151);
+ snd_soc_write(codec, 0xd3, 0x3f3f);
+ snd_soc_write(codec, 0xd4, 0x3f3f);
+ snd_soc_write(codec, 0xd5, 0x3f3f);
+ snd_soc_write(codec, 0xd6, 0x3228);
+ snd_soc_write(codec, 0x102, 0x0);
+
+ gd2_micd_set_rate(codec);
+
+#ifdef CONFIG_SEC_DEV_JACK
+ /* By default use idle_bias_off, will override for WM8994 */
+ codec->dapm.idle_bias_off = 0;
+#else /* CONFIG_SEC_DEV_JACK */
+ wm1811->jack.status = 0;
+
+ ret = snd_soc_jack_new(codec, "GD2 Jack",
+ SND_JACK_HEADSET | SND_JACK_BTN_0 |
+ SND_JACK_BTN_1 | SND_JACK_BTN_2,
+ &wm1811->jack);
+
+ if (ret < 0)
+ dev_err(codec->dev, "Failed to create jack: %d\n", ret);
+
+ ret = snd_jack_set_key(wm1811->jack.jack, SND_JACK_BTN_0, KEY_MEDIA);
+
+ if (ret < 0)
+ dev_err(codec->dev, "Failed to set KEY_MEDIA: %d\n", ret);
+
+ ret = snd_jack_set_key(wm1811->jack.jack, SND_JACK_BTN_1,
+ KEY_VOLUMEUP);
+ if (ret < 0)
+ dev_err(codec->dev, "Failed to set KEY_VOLUMEUP: %d\n", ret);
+
+ ret = snd_jack_set_key(wm1811->jack.jack, SND_JACK_BTN_2,
+ KEY_VOLUMEDOWN);
+
+ if (ret < 0)
+ dev_err(codec->dev, "Failed to set KEY_VOLUMEDOWN: %d\n", ret);
+
+ if (wm8994->revision > 1) {
+ dev_info(codec->dev, "wm1811: Rev %c support mic detection\n",
+ 'A' + wm8994->revision);
+#ifdef CONFIG_USE_ADC_DET
+ if (sound_pdata->use_jackdet_type) {
+ ret = wm8958_mic_detect(codec, &wm1811->jack,
+ gd2_micdet, wm1811, NULL, NULL);
+ } else {
+ ret = wm8958_mic_detect(codec, &wm1811->jack, NULL,
+ NULL, gd2_mic_id, wm1811);
+ }
+#else
+ ret = wm8958_mic_detect(codec, &wm1811->jack, NULL,
+ NULL, gd2_mic_id, wm1811);
+#endif
+ if (ret < 0)
+ dev_err(codec->dev, "Failed start detection: %d\n",
+ ret);
+ } else {
+ dev_info(codec->dev, "wm1811: Rev %c doesn't support mic detection\n",
+ 'A' + wm8994->revision);
+ codec->dapm.idle_bias_off = 0;
+ }
+ /* To wakeup for earjack event in suspend mode */
+ enable_irq_wake(control->irq);
+
+ wake_lock_init(&wm1811->jackdet_wake_lock,
+ WAKE_LOCK_SUSPEND, "GD2_jackdet");
+
+ /* To support PBA function test */
+ jack_class = class_create(THIS_MODULE, "audio");
+
+ if (IS_ERR(jack_class))
+ pr_err("Failed to create class\n");
+
+ jack_dev = device_create(jack_class, NULL, 0, codec, "earjack");
+
+ if (device_create_file(jack_dev, &dev_attr_select_jack) < 0)
+ pr_err("Failed to create device file (%s)!\n",
+ dev_attr_select_jack.attr.name);
+
+ if (device_create_file(jack_dev, &dev_attr_key_state) < 0)
+ pr_err("Failed to create device file (%s)!\n",
+ dev_attr_key_state.attr.name);
+
+ if (device_create_file(jack_dev, &dev_attr_state) < 0)
+ pr_err("Failed to create device file (%s)!\n",
+ dev_attr_state.attr.name);
+
+ if (device_create_file(jack_dev, &dev_attr_reselect_jack) < 0)
+ pr_err("Failed to create device file (%s)!\n",
+ dev_attr_reselect_jack.attr.name);
+
+#endif /* CONFIG_SEC_DEV_JACK */
+ sound_pdata = exynos_sound_get_platform_data();
+
+ if (sound_pdata) {
+ wm8994->hubs.dcs_codes_l = sound_pdata->dcs_offset_l;
+ wm8994->hubs.dcs_codes_r = sound_pdata->dcs_offset_r;
+ }
+
+#ifdef CONFIG_USE_ADC_DET
+ pr_info("%s: register adc client\n", __func__);
+ wm1811->padc = s3c_adc_register(gd2_snd_device, NULL, NULL, 0);
+#endif
+ return snd_soc_dapm_sync(&codec->dapm);
+}
+
+static struct snd_soc_dai_link gd2_dai[] = {
+ { /* Sec_Fifo DAI i/f */
+ .name = "Sec_FIFO TX",
+ .stream_name = "Sec_Dai",
+ .cpu_dai_name = "samsung-i2s.4",
+ .codec_dai_name = "wm8994-aif1",
+#ifndef CONFIG_SND_SOC_SAMSUNG_USE_DMA_WRAPPER
+ .platform_name = "samsung-audio-idma",
+#else
+ .platform_name = "samsung-audio",
+#endif
+ .codec_name = "wm8994-codec",
+ .init = gd2_wm1811_init_paiftx,
+ .ops = &gd2_wm1811_aif1_ops,
+ },
+ {
+ .name = "GD2_WM1811 Voice",
+ .stream_name = "Voice Tx/Rx",
+ .cpu_dai_name = "gd2.cp",
+ .codec_dai_name = "wm8994-aif2",
+ .platform_name = "snd-soc-dummy",
+ .codec_name = "wm8994-codec",
+ .ops = &gd2_wm1811_aif2_ops,
+ .ignore_suspend = 1,
+ },
+ {
+ .name = "GD2_WM1811 BT",
+ .stream_name = "BT Tx/Rx",
+ .cpu_dai_name = "gd2.bt",
+ .codec_dai_name = "wm8994-aif3",
+ .platform_name = "snd-soc-dummy",
+ .codec_name = "wm8994-codec",
+ .ops = &gd2_wm1811_aif3_ops,
+ .ignore_suspend = 1,
+ },
+ { /* Primary DAI i/f */
+ .name = "WM8994 AIF1",
+ .stream_name = "Pri_Dai",
+ .cpu_dai_name = "samsung-i2s.0",
+ .codec_dai_name = "wm8994-aif1",
+ .platform_name = "samsung-audio",
+ .codec_name = "wm8994-codec",
+ .ops = &gd2_wm1811_aif1_ops,
+ },
+};
+
+static int gd2_card_suspend_pre(struct snd_soc_card *card)
+{
+ struct snd_soc_codec *codec = card->rtd->codec;
+ struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
+
+#ifdef CONFIG_SND_USE_LINEOUT_SWITCH
+ struct wm1811_machine_priv *wm1811
+ = snd_soc_card_get_drvdata(codec->card);
+ if (lineout_mode == 1 &&
+ wm8994->vmid_mode == WM8994_VMID_FORCE) {
+ dev_info(codec->dev,
+ "%s: entering force vmid mode\n", __func__);
+ if (wm1811->lineout_switch_f)
+ wm1811->lineout_switch_f(0);
+ wm8994_vmid_mode(codec, WM8994_VMID_NORMAL);
+ }
+#endif
+#ifdef CONFIG_SEC_DEV_JACK
+ snd_soc_dapm_disable_pin(&codec->dapm, "AIF1CLK");
+#endif
+
+ return 0;
+}
+
+static int gd2_card_suspend_post(struct snd_soc_card *card)
+{
+ struct snd_soc_codec *codec = card->rtd->codec;
+ struct snd_soc_dai *aif1_dai = card->rtd[0].codec_dai;
+ struct snd_soc_dai *aif2_dai = card->rtd[1].codec_dai;
+ int ret;
+
+ if (!codec->active) {
+ ret = snd_soc_dai_set_sysclk(aif2_dai,
+ WM8994_SYSCLK_MCLK2,
+ MIDAS_DEFAULT_MCLK2,
+ SND_SOC_CLOCK_IN);
+
+ if (ret < 0)
+ dev_err(codec->dev, "Unable to switch to MCLK2: %d\n",
+ ret);
+
+ ret = snd_soc_dai_set_pll(aif2_dai, WM8994_FLL2, 0, 0, 0);
+
+ if (ret < 0)
+ dev_err(codec->dev, "Unable to stop FLL2\n");
+
+ ret = snd_soc_dai_set_sysclk(aif1_dai,
+ WM8994_SYSCLK_MCLK2,
+ MIDAS_DEFAULT_MCLK2,
+ SND_SOC_CLOCK_IN);
+ if (ret < 0)
+ dev_err(codec->dev, "Unable to switch to MCLK2\n");
+
+ ret = snd_soc_dai_set_pll(aif1_dai, WM8994_FLL1, 0, 0, 0);
+
+ if (ret < 0)
+ dev_err(codec->dev, "Unable to stop FLL1\n");
+
+ midas_snd_set_mclk(false, true);
+ }
+
+#ifdef CONFIG_ARCH_EXYNOS5
+ exynos5_sys_powerdown_xxti_control(midas_snd_get_mclk() ? 1 : 0);
+#else /* for CONFIG_ARCH_EXYNOS5 */
+ exynos4_sys_powerdown_xusbxti_control(midas_snd_get_mclk() ? 1 : 0);
+#endif
+
+ return 0;
+}
+
+static int gd2_card_resume_pre(struct snd_soc_card *card)
+{
+ struct snd_soc_codec *codec = card->rtd->codec;
+ struct snd_soc_dai *aif1_dai = card->rtd[0].codec_dai;
+ int ret;
+
+ midas_snd_set_mclk(true, false);
+
+ /* Switch the FLL */
+ ret = snd_soc_dai_set_pll(aif1_dai, WM8994_FLL1,
+ WM8994_FLL_SRC_MCLK1,
+ MIDAS_DEFAULT_MCLK1,
+ MIDAS_DEFAULT_SYNC_CLK);
+
+ if (ret < 0)
+ dev_err(aif1_dai->dev, "Unable to start FLL1: %d\n", ret);
+
+ /* Then switch AIF1CLK to it */
+ ret = snd_soc_dai_set_sysclk(aif1_dai,
+ WM8994_SYSCLK_FLL1,
+ MIDAS_DEFAULT_SYNC_CLK,
+ SND_SOC_CLOCK_IN);
+
+ if (ret < 0)
+ dev_err(aif1_dai->dev, "Unable to switch to FLL1: %d\n", ret);
+
+ return 0;
+}
+
+static int gd2_card_resume_post(struct snd_soc_card *card)
+{
+ struct snd_soc_codec *codec = card->rtd->codec;
+ struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
+ int reg = 0;
+
+#ifdef CONFIG_SND_USE_LINEOUT_SWITCH
+ struct wm1811_machine_priv *wm1811
+ = snd_soc_card_get_drvdata(codec->card);
+
+ if (lineout_mode == 1 &&
+ wm8994->vmid_mode == WM8994_VMID_NORMAL) {
+ dev_info(codec->dev,
+ "%s: entering normal vmid mode\n", __func__);
+ wm8994_vmid_mode(codec, WM8994_VMID_FORCE);
+ if (wm1811->lineout_switch_f)
+ wm1811->lineout_switch_f(1);
+ }
+#endif
+ /* workaround for jack detection
+ * sometimes WM8994_GPIO_1 type changed wrong function type
+ * so if type mismatched, update to IRQ type
+ */
+ reg = snd_soc_read(codec, WM8994_GPIO_1);
+
+ if ((reg & WM8994_GPN_FN_MASK) != WM8994_GP_FN_IRQ) {
+ dev_err(codec->dev, "%s: GPIO1 type 0x%x\n", __func__, reg);
+ snd_soc_write(codec, WM8994_GPIO_1, WM8994_GP_FN_IRQ);
+ }
+
+#ifdef CONFIG_SEC_DEV_JACK
+ snd_soc_dapm_force_enable_pin(&codec->dapm, "AIF1CLK");
+#endif
+
+ return 0;
+}
+
+static struct snd_soc_card gd2_card = {
+ .name = "GD2_WM1811",
+ .dai_link = gd2_dai,
+
+ /* If you want to use sec_fifo device,
+ * changes the num_link = 2 or ARRAY_SIZE(gd2_dai). */
+ .num_links = ARRAY_SIZE(gd2_dai),
+
+ .suspend_pre = gd2_card_suspend_pre,
+ .suspend_post = gd2_card_suspend_post,
+ .resume_pre = gd2_card_resume_pre,
+ .resume_post = gd2_card_resume_post
+};
+
+static void gd2_jackdet_set_mode(struct snd_soc_codec *codec, u16 mode)
+{
+ struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
+
+ if (!wm8994->jackdet || !wm8994->micdet[0].jack)
+ return;
+
+ if (wm8994->active_refcount)
+ mode = WM1811_JACKDET_MODE_AUDIO;
+
+ if (mode == wm8994->jackdet_mode)
+ return;
+
+ wm8994->jackdet_mode = mode;
+
+ /* Always use audio mode to detect while the system is active */
+ if (mode != WM1811_JACKDET_MODE_NONE)
+ mode = WM1811_JACKDET_MODE_AUDIO;
+
+ snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
+ WM1811_JACKDET_MODE_MASK, mode);
+}
+
+static irqreturn_t gd2_g_det_thread(int irq, void *data)
+{
+ struct wm1811_machine_priv *wm1811 = data;
+ struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(wm1811->codec);
+ struct snd_soc_codec *codec = wm8994->codec;
+
+
+ if (wm1811->get_g_det_value_f()) {
+
+ pr_info("%s: G_DET_N GPIO is High!!!!", __func__);
+
+ mutex_lock(&wm8994->accdet_lock);
+
+ snd_soc_update_bits(codec, WM8958_MICBIAS2,
+ WM8958_MICB2_DISCH, WM8958_MICB2_DISCH);
+
+ /* Enable debounce while removed */
+ snd_soc_update_bits(codec, WM1811_JACKDET_CTRL,
+ WM1811_JACKDET_DB, WM1811_JACKDET_DB);
+
+ wm8994->mic_detecting = false;
+ wm8994->jack_mic = false;
+
+ snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
+ WM8958_MICD_ENA, 0);
+
+ gd2_jackdet_set_mode(codec, WM1811_JACKDET_MODE_JACK);
+
+ mutex_unlock(&wm8994->accdet_lock);
+
+ mutex_lock(&codec->mutex);
+
+ snd_soc_dapm_disable_pin(&codec->dapm, "MICBIAS2");
+ snd_soc_dapm_sync(&codec->dapm);
+
+ mutex_unlock(&codec->mutex);
+
+ snd_soc_jack_report(wm8994->micdet[0].jack, 0,
+ SND_JACK_MECHANICAL | SND_JACK_HEADSET |
+ wm8994->btn_mask);
+ } else {
+ pr_info("%s: G_DET_N GPIO is Low!!!!", __func__);
+
+ handle_nested_irq(WM1811_JACKDET_IRQ_NUM);
+ msleep(100);
+ handle_nested_irq(WM1811_MIC_IRQ_NUM);
+ }
+
+ return IRQ_HANDLED;
+
+}
+
+static int __init gd2_audio_init(void)
+{
+ struct wm1811_machine_priv *wm1811;
+ const struct exynos_sound_platform_data *sound_pdata;
+ int ret;
+
+ wm1811 = kzalloc(sizeof *wm1811, GFP_KERNEL);
+ if (!wm1811) {
+ pr_err("Failed to allocate memory\n");
+ ret = -ENOMEM;
+ goto err_kzalloc;
+ }
+ snd_soc_card_set_drvdata(&gd2_card, wm1811);
+
+ gd2_snd_device = platform_device_alloc("soc-audio", -1);
+ if (!gd2_snd_device) {
+ ret = -ENOMEM;
+ goto err_device_alloc;
+ }
+
+ ret = snd_soc_register_dais(&gd2_snd_device->dev, gd2_ext_dai,
+ ARRAY_SIZE(gd2_ext_dai));
+ if (ret != 0)
+ pr_err("Failed to register external DAIs: %d\n", ret);
+
+ platform_set_drvdata(gd2_snd_device, &gd2_card);
+
+ ret = platform_device_add(gd2_snd_device);
+ if (ret)
+ platform_device_put(gd2_snd_device);
+
+ sound_pdata = exynos_sound_get_platform_data();
+ if (!sound_pdata) {
+ pr_info("%s: don't use sound pdata\n", __func__);
+ goto err_out_free;
+ }
+
+#ifdef CONFIG_USE_ADC_DET
+ if (sound_pdata->zones) {
+ wm1811->zones = sound_pdata->zones;
+ wm1811->num_zones = sound_pdata->num_zones;
+ }
+ pr_info("%s:use_jackdet_type = %d\n", __func__,
+ sound_pdata->use_jackdet_type);
+ wm1811->use_jackdet_type = sound_pdata->use_jackdet_type;
+#endif
+ if (sound_pdata->set_lineout_switch)
+ wm1811->lineout_switch_f = sound_pdata->set_lineout_switch;
+
+ if (sound_pdata->set_ext_main_mic)
+ wm1811->set_main_mic_f = sound_pdata->set_ext_main_mic;
+
+ if (sound_pdata->set_ext_sub_mic)
+ wm1811->set_sub_mic_f = sound_pdata->set_ext_sub_mic;
+
+ if (sound_pdata->set_ext_ext_mic)
+ wm1811->set_ext_mic_f = sound_pdata->set_ext_ext_mic;
+
+ if (sound_pdata->get_ground_det_value)
+ wm1811->get_g_det_value_f = sound_pdata->get_ground_det_value;
+
+ if (sound_pdata->get_ground_det_irq_num) {
+ wm1811->get_g_det_irq_num_f =
+ sound_pdata->get_ground_det_irq_num;
+ ret = request_threaded_irq(wm1811->get_g_det_irq_num_f(), NULL,
+ gd2_g_det_thread, IRQF_TRIGGER_RISING |
+ IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
+ "g_det irq", wm1811);
+ if (ret != 0)
+ pr_err("%s: Failed to register IRQ\n", __func__);
+
+ /* to handle insert/removal when we're sleeping in a call */
+ ret = enable_irq_wake(wm1811->get_g_det_irq_num_f());
+ if (ret)
+ pr_err("%s : Failed to enable_irq_wake\n", __func__);
+ }
+
+ return ret;
+
+err_out_free:
+ platform_device_put(gd2_snd_device);
+err_device_alloc:
+ kfree(wm1811);
+err_kzalloc:
+ return ret;
+}
+module_init(gd2_audio_init);
+
+static void __exit gd2_audio_exit(void)
+{
+ struct snd_soc_card *card = &gd2_card;
+ struct wm1811_machine_priv *wm1811 = snd_soc_card_get_drvdata(card);
+
+#ifdef CONFIG_USE_ADC_DET
+ s3c_adc_release(wm1811->padc);
+#endif
+ platform_device_unregister(gd2_snd_device);
+ kfree(wm1811);
+}
+module_exit(gd2_audio_exit);
+
+MODULE_AUTHOR("MIN LEE <min47.lee@samsung.com>");
+MODULE_DESCRIPTION("ALSA SoC GD2 WM1811");
+MODULE_LICENSE("GPL");
diff --git a/sound/soc/samsung/grande_wm1811.c b/sound/soc/samsung/grande_wm1811.c
index 304b592..2d56854 100644
--- a/sound/soc/samsung/grande_wm1811.c
+++ b/sound/soc/samsung/grande_wm1811.c
@@ -97,6 +97,10 @@ const char *modem_mode_text[] = {
"CP1", "CP2"
};
+static int aif2_digital_mute;
+const char *switch_mode_text[] = {
+ "Off", "On"
+};
#ifndef CONFIG_SEC_DEV_JACK
/* To support PBA function test */
@@ -220,6 +224,43 @@ static int set_modem_mode(struct snd_kcontrol *kcontrol,
}
+static const struct soc_enum switch_mode_enum[] = {
+ SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(switch_mode_text), switch_mode_text),
+};
+
+static int get_aif2_mute_status(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ ucontrol->value.integer.value[0] = aif2_digital_mute;
+ return 0;
+}
+
+static int set_aif2_mute_status(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+ int reg;
+
+ aif2_digital_mute = ucontrol->value.integer.value[0];
+
+ if (snd_soc_read(codec, WM8994_POWER_MANAGEMENT_6)
+ & WM8994_AIF2_DACDAT_SRC)
+ aif2_digital_mute = 0;
+
+ if (aif2_digital_mute)
+ reg = WM8994_AIF1DAC1_MUTE;
+ else
+ reg = 0;
+
+ snd_soc_update_bits(codec, WM8994_AIF2_DAC_FILTERS_1,
+ WM8994_AIF1DAC1_MUTE, reg);
+
+ pr_info("aif2_digit_mute: %s\n", switch_mode_text[aif2_digital_mute]);
+
+ return 0;
+}
+
+
static const struct soc_enum lineout_mode_enum[] = {
SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(lineout_mode_text), lineout_mode_text),
};
@@ -979,6 +1020,10 @@ static const struct snd_kcontrol_new midas_controls[] = {
SOC_ENUM_EXT("ModemSwitch Mode", modem_mode_enum[0],
get_modem_mode, set_modem_mode),
+
+ SOC_ENUM_EXT("AIF2 digital mute", switch_mode_enum[0],
+ get_aif2_mute_status, set_aif2_mute_status),
+
};
const struct snd_soc_dapm_widget midas_dapm_widgets[] = {
diff --git a/sound/soc/samsung/i2s.c b/sound/soc/samsung/i2s.c
index 52f308b..ade047f 100644
--- a/sound/soc/samsung/i2s.c
+++ b/sound/soc/samsung/i2s.c
@@ -977,10 +977,10 @@ static int i2s_trigger(struct snd_pcm_substream *substream,
goto exit_err;
}
- local_irq_save(flags);
+ spin_lock_irqsave(&lock, flags);
if (config_setup(i2s)) {
- local_irq_restore(flags);
+ spin_unlock_irqrestore(&lock, flags);
return -EINVAL;
}
@@ -989,12 +989,12 @@ static int i2s_trigger(struct snd_pcm_substream *substream,
else
i2s_txctrl(i2s, 1, substream->stream);
- local_irq_restore(flags);
+ spin_unlock_irqrestore(&lock, flags);
break;
case SNDRV_PCM_TRIGGER_STOP:
case SNDRV_PCM_TRIGGER_SUSPEND:
case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
- local_irq_save(flags);
+ spin_lock_irqsave(&lock, flags);
if (capture)
i2s_rxctrl(i2s, 0);
@@ -1007,7 +1007,7 @@ static int i2s_trigger(struct snd_pcm_substream *substream,
if (!srp_active(i2s, IS_RUNNING))
i2s_fifo(i2s, FIC_TXFLUSH, substream->stream);
}
- local_irq_restore(flags);
+ spin_unlock_irqrestore(&lock, flags);
break;
}
diff --git a/sound/soc/samsung/kona_wm1811.c b/sound/soc/samsung/kona_wm1811.c
new file mode 100644
index 0000000..9ae294b
--- /dev/null
+++ b/sound/soc/samsung/kona_wm1811.c
@@ -0,0 +1,1481 @@
+/*
+ * kona_wm1811.c
+ *
+ * Copyright (c) 2011 Samsung Electronics Co. Ltd
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ */
+#include <linux/platform_device.h>
+#include <linux/clk.h>
+#include <linux/io.h>
+#include <linux/gpio.h>
+#include <linux/delay.h>
+#include <linux/slab.h>
+#include <linux/workqueue.h>
+#include <linux/input.h>
+#include <linux/wakelock.h>
+#include <linux/suspend.h>
+
+#include <sound/soc.h>
+#include <sound/soc-dapm.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include <sound/jack.h>
+
+#include <mach/regs-clock.h>
+#include <mach/pmu.h>
+#include <mach/midas-sound.h>
+
+#include <linux/mfd/wm8994/core.h>
+#include <linux/mfd/wm8994/registers.h>
+#include <linux/mfd/wm8994/pdata.h>
+#include <linux/mfd/wm8994/gpio.h>
+
+#ifdef CONFIG_EXYNOS_SOUND_PLATFORM_DATA
+#include <linux/exynos_audio.h>
+#endif
+
+#ifdef CONFIG_USE_ADC_DET
+#include <plat/adc.h>
+#endif
+
+#if defined(CONFIG_STMPE811_ADC)
+#include <linux/stmpe811-adc.h>
+#endif
+
+#include "i2s.h"
+#include "s3c-i2s-v2.h"
+#include "../codecs/wm8994.h"
+
+#if defined(CONFIG_STMPE811_ADC)
+#define SEC_JACK_ADC_CH 4
+#else
+#define SEC_JACK_ADC_CH 3
+#endif
+
+#define MIDAS_DEFAULT_MCLK1 24000000
+#define MIDAS_DEFAULT_MCLK2 32768
+#define MIDAS_DEFAULT_SYNC_CLK 11289600
+
+#define WM1811_JACKDET_MODE_NONE 0x0000
+#define WM1811_JACKDET_MODE_JACK 0x0100
+#define WM1811_JACKDET_MODE_MIC 0x0080
+#define WM1811_JACKDET_MODE_AUDIO 0x0180
+
+#define WM1811_JACKDET_BTN0 0x04
+#define WM1811_JACKDET_BTN1 0x10
+#define WM1811_JACKDET_BTN2 0x08
+
+#define JACK_ADC_CH 2
+#define JACK_SAMPLE_SIZE 5
+
+#define MAX_ZONE_LIMIT 10
+/* keep this value if you support double-pressed concept */
+#define WAKE_LOCK_TIME (HZ * 5) /* 5 sec */
+#define EAR_CHECK_LOOP_CNT 10
+
+struct wm1811_machine_priv {
+ struct snd_soc_jack jack;
+ struct snd_soc_codec *codec;
+ struct wake_lock jackdet_wake_lock;
+ void (*lineout_switch_f) (int on);
+ void (*set_main_mic_f) (int on);
+ void (*set_sub_mic_f) (int on);
+ int (*get_g_det_value_f) (void);
+ int (*get_g_det_irq_num_f) (void);
+#ifdef CONFIG_USE_ADC_DET
+ struct s3c_adc_client *padc;
+ struct jack_zone *zones;
+ int num_zones;
+ int use_jackdet_type;
+#endif
+};
+
+enum {
+ SEC_JACK_NO_DEVICE = 0x0,
+ SEC_HEADSET_4POLE = 0x01 << 0,
+ SEC_HEADSET_3POLE = 0x01 << 1,
+ SEC_TTY_DEVICE = 0x01 << 2,
+ SEC_FM_HEADSET = 0x01 << 3,
+ SEC_FM_SPEAKER = 0x01 << 4,
+ SEC_TVOUT_DEVICE = 0x01 << 5,
+ SEC_EXTRA_DOCK_SPEAKER = 0x01 << 6,
+ SEC_EXTRA_CAR_DOCK_SPEAKER = 0x01 << 7,
+ SEC_UNKNOWN_DEVICE = 0x01 << 8,
+};
+
+#ifdef CONFIG_USE_ADC_DET
+static bool recheck_jack;
+static int jack_get_adc_data(struct s3c_adc_client *padc);
+static void jack_set_type(struct wm1811_machine_priv *wm1811, int jack_type);
+#endif
+
+static struct wm8958_micd_rate kona_det_rates[] = {
+ { MIDAS_DEFAULT_MCLK2, true, 0, 0 },
+ { MIDAS_DEFAULT_MCLK2, false, 0, 0 },
+ { MIDAS_DEFAULT_SYNC_CLK, true, 7, 7 },
+ { MIDAS_DEFAULT_SYNC_CLK, false, 7, 7 },
+};
+
+static struct wm8958_micd_rate kona_jackdet_rates[] = {
+ { MIDAS_DEFAULT_MCLK2, true, 0, 0 },
+ { MIDAS_DEFAULT_MCLK2, false, 0, 0 },
+ { MIDAS_DEFAULT_SYNC_CLK, true, 12, 12 },
+ { MIDAS_DEFAULT_SYNC_CLK, false, 7, 8 },
+};
+
+static int aif2_mode;
+const char *aif2_mode_text[] = {
+ "Slave", "Master"
+};
+
+static int input_clamp;
+const char *input_clamp_text[] = {
+ "Off", "On"
+};
+
+static int lineout_mode;
+const char *lineout_mode_text[] = {
+ "Off", "On"
+};
+
+static int aif2_digital_mute;
+const char *switch_mode_text[] = {
+ "Off", "On"
+};
+
+static int aif1_ADC_Data;
+const char *mic_mode_text[] = {
+ "Off", "On"
+};
+
+static int aif1_loopback_data;
+const char *aif1_loopback_text[] = {
+ "Off", "On"
+};
+
+#ifndef CONFIG_SEC_DEV_JACK
+/* To support PBA function test */
+static struct class *jack_class;
+static struct device *jack_dev;
+#endif
+
+static struct platform_device *kona_snd_device;
+
+
+static void kona_gpio_init(void)
+{
+ int err;
+#ifdef CONFIG_SND_SOC_USE_EXTERNAL_MIC_BIAS
+ /* Main Microphone BIAS */
+ err = gpio_request(GPIO_MIC_BIAS_EN, "MAIN MIC");
+ if (err) {
+ pr_err(KERN_ERR "MIC_BIAS_EN GPIO set error!\n");
+ return;
+ }
+ gpio_direction_output(GPIO_MIC_BIAS_EN, 1);
+ gpio_set_value(GPIO_MIC_BIAS_EN, 0);
+ gpio_free(GPIO_MIC_BIAS_EN);
+#endif
+
+#ifdef CONFIG_SND_USE_SUB_MIC
+ /* Sub Microphone BIAS */
+ err = gpio_request(GPIO_SUB_MIC_BIAS_EN, "SUB MIC");
+ if (err) {
+ pr_err(KERN_ERR "SUB_MIC_BIAS_EN GPIO set error!\n");
+ return;
+ }
+ gpio_direction_output(GPIO_SUB_MIC_BIAS_EN, 1);
+ gpio_set_value(GPIO_SUB_MIC_BIAS_EN, 0);
+ gpio_free(GPIO_SUB_MIC_BIAS_EN);
+#endif
+
+#ifdef CONFIG_SND_USE_LINEOUT_SWITCH
+ err = gpio_request(GPIO_LINEOUT_EN, "LINEOUT_EN");
+ if (err) {
+ pr_err(KERN_ERR "LINEOUT_EN GPIO set error!\n");
+ return;
+ }
+ gpio_direction_output(GPIO_LINEOUT_EN, 1);
+ gpio_set_value(GPIO_LINEOUT_EN, 0);
+ gpio_free(GPIO_LINEOUT_EN);
+#endif
+}
+
+static const struct soc_enum lineout_mode_enum[] = {
+ SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(lineout_mode_text), lineout_mode_text),
+};
+
+static int get_lineout_mode(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ ucontrol->value.integer.value[0] = lineout_mode;
+ return 0;
+}
+
+static int set_lineout_mode(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+
+ lineout_mode = ucontrol->value.integer.value[0];
+
+ if (lineout_mode)
+ gpio_set_value(GPIO_LINEOUT_EN, 1);
+ else
+ gpio_set_value(GPIO_LINEOUT_EN, 0);
+
+ dev_info(codec->dev, "set lineout mode : %s\n",
+ lineout_mode_text[lineout_mode]);
+ return 0;
+
+}
+static const struct soc_enum aif2_mode_enum[] = {
+ SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(aif2_mode_text), aif2_mode_text),
+};
+
+static int get_aif2_mode(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ ucontrol->value.integer.value[0] = aif2_mode;
+ return 0;
+}
+
+static int set_aif2_mode(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ if (aif2_mode == ucontrol->value.integer.value[0])
+ return 0;
+
+ aif2_mode = ucontrol->value.integer.value[0];
+
+ pr_info("set aif2 mode : %s\n", aif2_mode_text[aif2_mode]);
+
+ return 0;
+}
+
+static const struct soc_enum input_clamp_enum[] = {
+ SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(input_clamp_text), input_clamp_text),
+};
+
+static int get_input_clamp(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ ucontrol->value.integer.value[0] = input_clamp;
+ return 0;
+}
+
+static int set_input_clamp(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+
+ input_clamp = ucontrol->value.integer.value[0];
+
+ if (input_clamp) {
+ snd_soc_update_bits(codec, WM8994_INPUT_MIXER_1,
+ WM8994_INPUTS_CLAMP, WM8994_INPUTS_CLAMP);
+ msleep(100);
+ } else {
+ snd_soc_update_bits(codec, WM8994_INPUT_MIXER_1,
+ WM8994_INPUTS_CLAMP, 0);
+ }
+ pr_info("set fm input_clamp : %s\n", input_clamp_text[input_clamp]);
+
+ return 0;
+}
+
+static const struct soc_enum switch_mode_enum[] = {
+ SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(switch_mode_text), switch_mode_text),
+};
+
+static int get_aif2_mute_status(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ ucontrol->value.integer.value[0] = aif2_digital_mute;
+ return 0;
+}
+
+static int set_aif2_mute_status(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+ int reg;
+
+ aif2_digital_mute = ucontrol->value.integer.value[0];
+
+ if (snd_soc_read(codec, WM8994_POWER_MANAGEMENT_6)
+ & WM8994_AIF2_DACDAT_SRC)
+ aif2_digital_mute = 0;
+
+ if (aif2_digital_mute)
+ reg = WM8994_AIF1DAC1_MUTE;
+ else
+ reg = 0;
+
+ snd_soc_update_bits(codec, WM8994_AIF2_DAC_FILTERS_1,
+ WM8994_AIF1DAC1_MUTE, reg);
+
+ pr_info("set aif2_digital_mute : %s\n",
+ switch_mode_text[aif2_digital_mute]);
+
+ return 0;
+}
+
+static const struct soc_enum mic_mode_enum[] = {
+ SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(mic_mode_text), mic_mode_text),
+};
+
+static int get_aif1_ADC_status(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ ucontrol->value.integer.value[0] = aif1_ADC_Data;
+ return 0;
+}
+
+static int set_aif1_ADC_status(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+ int reg;
+
+ aif1_ADC_Data = ucontrol->value.integer.value[0];
+
+ if (aif1_ADC_Data)
+ reg = WM8994_AIF1ADCR_DAT_INV;
+ else
+ reg = 0;
+
+ snd_soc_update_bits(codec, WM8994_AIF1ADC_DATA,
+ WM8994_AIF1ADCR_DAT_INV, reg);
+
+ pr_info("set aif1_ADC_Data : %s\n",
+ mic_mode_text[aif1_ADC_Data]);
+
+ return 0;
+}
+
+static const struct soc_enum aif1_loopback_enum[] = {
+ SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(aif1_loopback_text), aif1_loopback_text),
+};
+
+static int get_aif1_loopback_status(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ ucontrol->value.integer.value[0] = aif1_loopback_data;
+ return 0;
+}
+
+static int set_aif1_loopback_status(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+ int reg1, reg2;
+
+ aif1_loopback_data = ucontrol->value.integer.value[0];
+
+ if (aif1_loopback_data){
+ reg1 = WM8994_AIF1_LOOPBACK;
+ reg2 = 0;
+ }else{
+ reg1 = 0;
+ reg2 = WM8994_AIF1DAC1_MUTE;
+ }
+
+ snd_soc_update_bits(codec, WM8994_AIF1_CONTROL_2,
+ WM8994_AIF1_LOOPBACK, reg1);
+ snd_soc_update_bits(codec, WM8994_AIF1_DAC1_FILTERS_1,
+ WM8994_AIF1DAC1_MUTE, reg2);
+
+ pr_info("set aif1_loopback_data : %s\n",
+ aif1_loopback_text[aif1_loopback_data]);
+
+ return 0;
+}
+
+static int set_ext_micbias(struct snd_soc_dapm_widget *w,
+ struct snd_kcontrol *kcontrol, int event)
+{
+ struct snd_soc_codec *codec = w->codec;
+
+ dev_info(codec->dev, "%s event is %02X", w->name, event);
+
+ switch (event) {
+ case SND_SOC_DAPM_PRE_PMU:
+ gpio_set_value(GPIO_MIC_BIAS_EN, 1);
+ msleep(100);
+ break;
+ case SND_SOC_DAPM_POST_PMD:
+ gpio_set_value(GPIO_MIC_BIAS_EN, 0);
+ break;
+ }
+
+ return 0;
+}
+
+static int set_ext_submicbias(struct snd_soc_dapm_widget *w,
+ struct snd_kcontrol *kcontrol, int event)
+{
+ struct snd_soc_codec *codec = w->codec;
+
+ dev_info(codec->dev, "%s event is %02X", w->name, event);
+
+ switch (event) {
+ case SND_SOC_DAPM_PRE_PMU:
+ gpio_set_value(GPIO_SUB_MIC_BIAS_EN, 1);
+ msleep(100);
+ break;
+ case SND_SOC_DAPM_POST_PMD:
+ gpio_set_value(GPIO_SUB_MIC_BIAS_EN, 0);
+ break;
+ }
+
+ return 0;
+}
+
+static int set_lineout_switch(struct snd_soc_dapm_widget *w,
+ struct snd_kcontrol *kcontrol, int event)
+{
+ struct snd_soc_codec *codec = w->codec;
+
+ dev_info(codec->dev, "%s event is %02X", w->name, event);
+
+ switch (event) {
+ case SND_SOC_DAPM_POST_PMU:
+ gpio_set_value(GPIO_LINEOUT_EN, 1);
+ break;
+ case SND_SOC_DAPM_PRE_PMD:
+ gpio_set_value(GPIO_LINEOUT_EN, 0);
+ break;
+ }
+
+ return 0;
+}
+
+static void kona_micd_set_rate(struct snd_soc_codec *codec)
+{
+ struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
+ int best, i, sysclk, val;
+ bool idle;
+ const struct wm8958_micd_rate *rates = NULL;
+ int num_rates = 0;
+
+ idle = !wm8994->jack_mic;
+
+ sysclk = snd_soc_read(codec, WM8994_CLOCKING_1);
+ if (sysclk & WM8994_SYSCLK_SRC)
+ sysclk = wm8994->aifclk[1];
+ else
+ sysclk = wm8994->aifclk[0];
+
+ if (wm8994->jackdet) {
+ rates = kona_jackdet_rates;
+ num_rates = ARRAY_SIZE(kona_jackdet_rates);
+ wm8994->pdata->micd_rates = kona_jackdet_rates;
+ wm8994->pdata->num_micd_rates = num_rates;
+ } else {
+ rates = kona_det_rates;
+ num_rates = ARRAY_SIZE(kona_det_rates);
+ wm8994->pdata->micd_rates = kona_det_rates;
+ wm8994->pdata->num_micd_rates = num_rates;
+ }
+
+ best = 0;
+ for (i = 0; i < num_rates; i++) {
+ if (rates[i].idle != idle)
+ continue;
+ if (abs(rates[i].sysclk - sysclk) <
+ abs(rates[best].sysclk - sysclk))
+ best = i;
+ else if (rates[best].idle != idle)
+ best = i;
+ }
+
+ val = rates[best].start << WM8958_MICD_BIAS_STARTTIME_SHIFT
+ | rates[best].rate << WM8958_MICD_RATE_SHIFT;
+
+ snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
+ WM8958_MICD_BIAS_STARTTIME_MASK |
+ WM8958_MICD_RATE_MASK, val);
+}
+
+#ifdef CONFIG_USE_ADC_DET
+static int jack_get_adc_data(struct s3c_adc_client *padc)
+{
+ int adc_data;
+ int adc_max = 0;
+ int adc_min = 0xFFFF;
+ int adc_total = 0;
+ int adc_retry_cnt = 0;
+ int i;
+
+ for (i = 0; i < JACK_SAMPLE_SIZE; i++) {
+
+#if defined(CONFIG_STMPE811_ADC)
+ adc_data = stmpe811_get_adc_data(SEC_JACK_ADC_CH);
+#else
+ adc_data = s3c_adc_read(padc, JACK_ADC_CH);
+#endif
+
+ if (adc_data < 0) {
+
+ adc_retry_cnt++;
+
+ if (adc_retry_cnt > 10)
+ return adc_data;
+ }
+
+ if (i != 0) {
+ if (adc_data > adc_max)
+ adc_max = adc_data;
+ else if (adc_data < adc_min)
+ adc_min = adc_data;
+ } else {
+ adc_max = adc_data;
+ adc_min = adc_data;
+ }
+ adc_total += adc_data;
+ }
+
+ return (adc_total - adc_max - adc_min) / (JACK_SAMPLE_SIZE - 2);
+}
+
+static void determine_jack_type(struct wm1811_machine_priv *wm1811)
+{
+ struct jack_zone *zones = wm1811->zones;
+ struct snd_soc_codec *codec = wm1811->codec;
+ int size = wm1811->num_zones;
+ int count[MAX_ZONE_LIMIT] = {0};
+ int adc;
+ int i;
+
+ /* set mic bias to enable adc */
+ while (snd_soc_read(codec, WM1811_JACKDET_CTRL) & WM1811_JACKDET_LVL) {
+ adc = jack_get_adc_data(wm1811->padc);
+
+ pr_info("%s: adc = %d\n", __func__, adc);
+
+ if (adc < 0)
+ break;
+
+ /* determine the type of headset based on the
+ * adc value. An adc value can fall in various
+ * ranges or zones. Within some ranges, the type
+ * can be returned immediately. Within others, the
+ * value is considered unstable and we need to sample
+ * a few more types (up to the limit determined by
+ * the range) before we return the type for that range.
+ */
+ for (i = 0; i < size; i++) {
+ if (adc <= zones[i].adc_high) {
+ if (++count[i] > zones[i].check_count) {
+ if (recheck_jack == true && i == 4) {
+ pr_info("%s : something wrong connection!\n",
+ __func__);
+
+ recheck_jack = false;
+ return;
+ }
+ jack_set_type(wm1811,
+ zones[i].jack_type);
+ return;
+ }
+ msleep(zones[i].delay_ms);
+ break;
+ }
+ }
+ }
+
+ recheck_jack = false;
+ /* jack removed before detection complete */
+ pr_debug("%s : jack removed before detection complete\n", __func__);
+}
+
+static void jack_set_type(struct wm1811_machine_priv *wm1811, int jack_type)
+{
+ struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(wm1811->codec);
+
+ if (jack_type == SEC_HEADSET_4POLE) {
+ dev_info(wm1811->codec->dev, "Detected microphone\n");
+
+ wm8994->mic_detecting = false;
+ wm8994->jack_mic = true;
+
+ kona_micd_set_rate(wm1811->codec);
+
+ snd_soc_jack_report(wm8994->micdet[0].jack, SND_JACK_HEADSET,
+ SND_JACK_HEADSET);
+
+ snd_soc_update_bits(wm1811->codec, WM8958_MIC_DETECT_1,
+ WM8958_MICD_ENA, 1);
+ } else {
+ dev_info(wm1811->codec->dev, "Detected headphone\n");
+ wm8994->mic_detecting = false;
+
+ kona_micd_set_rate(wm1811->codec);
+
+ snd_soc_jack_report(wm8994->micdet[0].jack, SND_JACK_HEADPHONE,
+ SND_JACK_HEADSET);
+
+ /* If we have jackdet that will detect removal */
+ if (wm8994->jackdet) {
+ snd_soc_update_bits(wm1811->codec, WM8958_MIC_DETECT_1,
+ WM8958_MICD_ENA, 0);
+
+ if (wm8994->active_refcount) {
+ snd_soc_update_bits(wm1811->codec,
+ WM8994_ANTIPOP_2,
+ WM1811_JACKDET_MODE_MASK,
+ WM1811_JACKDET_MODE_AUDIO);
+ }
+
+ if (wm8994->pdata->jd_ext_cap) {
+ mutex_lock(&wm1811->codec->mutex);
+ snd_soc_dapm_disable_pin(&wm1811->codec->dapm,
+ "MICBIAS2");
+ snd_soc_dapm_sync(&wm1811->codec->dapm);
+ mutex_unlock(&wm1811->codec->mutex);
+ }
+ }
+ }
+}
+
+static void kona_micdet(void *data)
+{
+ struct wm1811_machine_priv *wm1811 = data;
+ struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(wm1811->codec);
+
+ struct snd_soc_codec *codec = wm1811->codec;
+
+ pr_info("%s: detected jack\n", __func__);
+ wm8994->mic_detecting = true;
+
+ wake_lock_timeout(&wm1811->jackdet_wake_lock, 5 * HZ);
+
+ snd_soc_update_bits(codec, WM8958_MICBIAS2,
+ WM8958_MICB2_MODE, 0);
+
+ determine_jack_type(wm1811);
+}
+#endif
+
+static void kona_mic_id(void *data, u16 status)
+{
+ struct wm1811_machine_priv *wm1811 = data;
+ struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(wm1811->codec);
+
+ pr_info("%s: detected jack\n", __func__);
+ wake_lock_timeout(&wm1811->jackdet_wake_lock, 5 * HZ);
+
+ /* Either nothing present or just starting detection */
+ if (!(status & WM8958_MICD_STS)) {
+ if (!wm8994->jackdet) {
+ /* If nothing present then clear our statuses */
+ dev_dbg(wm1811->codec->dev, "Detected open circuit\n");
+ wm8994->jack_mic = false;
+ wm8994->mic_detecting = true;
+
+ kona_micd_set_rate(wm1811->codec);
+
+ snd_soc_jack_report(wm8994->micdet[0].jack, 0,
+ wm8994->btn_mask |
+ SND_JACK_HEADSET);
+ }
+ /*ToDo*/
+ /*return;*/
+ }
+
+ /* If the measurement is showing a high impedence we've got a
+ * microphone.
+ */
+ if (wm8994->mic_detecting && (status & 0x400)) {
+ dev_info(wm1811->codec->dev, "Detected microphone\n");
+
+ wm8994->mic_detecting = false;
+ wm8994->jack_mic = true;
+
+ kona_micd_set_rate(wm1811->codec);
+
+ snd_soc_jack_report(wm8994->micdet[0].jack, SND_JACK_HEADSET,
+ SND_JACK_HEADSET);
+ }
+
+ if (wm8994->mic_detecting && status & 0x4) {
+ dev_info(wm1811->codec->dev, "Detected headphone\n");
+ wm8994->mic_detecting = false;
+
+ kona_micd_set_rate(wm1811->codec);
+
+ snd_soc_jack_report(wm8994->micdet[0].jack, SND_JACK_HEADPHONE,
+ SND_JACK_HEADSET);
+
+ /* If we have jackdet that will detect removal */
+ if (wm8994->jackdet) {
+ mutex_lock(&wm8994->accdet_lock);
+
+ snd_soc_update_bits(wm1811->codec, WM8958_MIC_DETECT_1,
+ WM8958_MICD_ENA, 0);
+
+ if (wm8994->active_refcount) {
+ snd_soc_update_bits(wm1811->codec,
+ WM8994_ANTIPOP_2,
+ WM1811_JACKDET_MODE_MASK,
+ WM1811_JACKDET_MODE_AUDIO);
+ }
+
+ mutex_unlock(&wm8994->accdet_lock);
+
+ if (wm8994->pdata->jd_ext_cap) {
+ mutex_lock(&wm1811->codec->mutex);
+ snd_soc_dapm_disable_pin(&wm1811->codec->dapm,
+ "MICBIAS2");
+ snd_soc_dapm_sync(&wm1811->codec->dapm);
+ mutex_unlock(&wm1811->codec->mutex);
+ }
+ }
+ }
+}
+
+static int kona_wm1811_aif1_hw_params(struct snd_pcm_substream *substream,
+ struct snd_pcm_hw_params *params)
+{
+ struct snd_soc_pcm_runtime *rtd = substream->private_data;
+ struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
+ struct snd_soc_dai *codec_dai = rtd->codec_dai;
+ struct snd_soc_codec *codec = rtd->codec;
+ unsigned int pll_out;
+ int ret;
+
+ dev_info(codec_dai->dev, "%s ++\n", __func__);
+
+ snd_soc_update_bits(codec, WM8994_AIF1_MASTER_SLAVE,
+ WM8994_AIF1_TRI, 0);
+ snd_soc_update_bits(codec, WM8994_AIF2_MASTER_SLAVE,
+ WM8994_AIF2_TRI, 0);
+
+ /* AIF1CLK should be >=3MHz for optimal performance */
+ if (params_rate(params) == 8000 || params_rate(params) == 11025)
+ pll_out = params_rate(params) * 512;
+ else
+ pll_out = params_rate(params) * 256;
+
+ ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
+ | SND_SOC_DAIFMT_NB_NF
+ | SND_SOC_DAIFMT_CBM_CFM);
+ if (ret < 0)
+ return ret;
+
+ /* Set the cpu DAI configuration */
+ ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S
+ | SND_SOC_DAIFMT_NB_NF
+ | SND_SOC_DAIFMT_CBM_CFM);
+ if (ret < 0)
+ return ret;
+
+ /* Switch the FLL */
+ ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL1,
+ WM8994_FLL_SRC_MCLK1, MIDAS_DEFAULT_MCLK1,
+ pll_out);
+ if (ret < 0)
+ dev_err(codec_dai->dev, "Unable to start FLL1: %d\n", ret);
+
+ ret = snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_FLL1,
+ pll_out, SND_SOC_CLOCK_IN);
+ if (ret < 0) {
+ dev_err(codec_dai->dev, "Unable to switch to FLL1: %d\n", ret);
+ return ret;
+ }
+
+ ret = snd_soc_dai_set_sysclk(cpu_dai, SAMSUNG_I2S_OPCLK,
+ 0, MOD_OPCLK_PCLK);
+ if (ret < 0)
+ return ret;
+
+ dev_info(codec_dai->dev, "%s --\n", __func__);
+
+ return 0;
+}
+
+/*
+ * kona WM1811 DAI operations.
+ */
+static struct snd_soc_ops kona_wm1811_aif1_ops = {
+ .hw_params = kona_wm1811_aif1_hw_params,
+};
+
+static int kona_wm1811_aif2_hw_params(struct snd_pcm_substream *substream,
+ struct snd_pcm_hw_params *params)
+{
+ struct snd_soc_pcm_runtime *rtd = substream->private_data;
+ struct snd_soc_dai *codec_dai = rtd->codec_dai;
+ struct snd_soc_codec *codec = rtd->codec;
+ int ret;
+ int prate;
+ int bclk;
+
+ dev_info(codec_dai->dev, "%s ++\n", __func__);
+
+ snd_soc_update_bits(codec, WM8994_AIF1_MASTER_SLAVE,
+ WM8994_AIF1_TRI, 0);
+ snd_soc_update_bits(codec, WM8994_AIF2_MASTER_SLAVE,
+ WM8994_AIF2_TRI, 0);
+
+ prate = params_rate(params);
+ switch (params_rate(params)) {
+ case 8000:
+ case 16000:
+ break;
+ default:
+ dev_warn(codec_dai->dev, "Unsupported LRCLK %d, falling back to 8000Hz\n",
+ (int)params_rate(params));
+ prate = 8000;
+ }
+
+ /* Set the codec DAI configuration, aif2_mode:0 is slave */
+ if (aif2_mode == 0)
+ ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
+ | SND_SOC_DAIFMT_NB_NF
+ | SND_SOC_DAIFMT_CBS_CFS);
+ else
+ ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
+ | SND_SOC_DAIFMT_NB_NF
+ | SND_SOC_DAIFMT_CBM_CFM);
+
+ if (ret < 0)
+ return ret;
+
+ switch (prate) {
+ case 8000:
+ bclk = 256000;
+ break;
+ case 16000:
+ bclk = 512000;
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ if (aif2_mode == 0) {
+ ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL2,
+ WM8994_FLL_SRC_BCLK,
+ bclk, prate * 256);
+ } else {
+ ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL2,
+ WM8994_FLL_SRC_MCLK1,
+ MIDAS_DEFAULT_MCLK1, prate * 256);
+ }
+
+ if (ret < 0)
+ dev_err(codec_dai->dev, "Unable to configure FLL2: %d\n", ret);
+
+ ret = snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_FLL2,
+ prate * 256, SND_SOC_CLOCK_IN);
+ if (ret < 0)
+ dev_err(codec_dai->dev, "Unable to switch to FLL2: %d\n", ret);
+
+ dev_info(codec_dai->dev, "%s --\n", __func__);
+ return 0;
+}
+
+static struct snd_soc_ops kona_wm1811_aif2_ops = {
+ .hw_params = kona_wm1811_aif2_hw_params,
+};
+
+static int kona_wm1811_aif3_hw_params(struct snd_pcm_substream *substream,
+ struct snd_pcm_hw_params *params)
+{
+ pr_err("%s: enter\n", __func__);
+ return 0;
+}
+
+static struct snd_soc_ops kona_wm1811_aif3_ops = {
+ .hw_params = kona_wm1811_aif3_hw_params,
+};
+
+static const struct snd_kcontrol_new kona_controls[] = {
+ SOC_DAPM_PIN_SWITCH("HP"),
+ SOC_DAPM_PIN_SWITCH("SPK"),
+ SOC_DAPM_PIN_SWITCH("RCV"),
+ SOC_DAPM_PIN_SWITCH("LINE"),
+ SOC_DAPM_PIN_SWITCH("HDMI"),
+ SOC_DAPM_PIN_SWITCH("Main Mic"),
+ SOC_DAPM_PIN_SWITCH("Sub Mic"),
+ SOC_DAPM_PIN_SWITCH("Headset Mic"),
+
+ SOC_ENUM_EXT("AIF2 Mode", aif2_mode_enum[0],
+ get_aif2_mode, set_aif2_mode),
+
+ SOC_ENUM_EXT("Input Clamp", input_clamp_enum[0],
+ get_input_clamp, set_input_clamp),
+
+ SOC_ENUM_EXT("LineoutSwitch Mode", lineout_mode_enum[0],
+ get_lineout_mode, set_lineout_mode),
+
+ SOC_ENUM_EXT("AIF2 digital mute", switch_mode_enum[0],
+ get_aif2_mute_status, set_aif2_mute_status),
+
+ SOC_ENUM_EXT("Submic ADC invert", mic_mode_enum[0],
+ get_aif1_ADC_status, set_aif1_ADC_status),
+
+ SOC_ENUM_EXT("AIF1 Loopback", aif1_loopback_enum[0],
+ get_aif1_loopback_status, set_aif1_loopback_status),
+
+};
+
+const struct snd_soc_dapm_widget kona_dapm_widgets[] = {
+ SND_SOC_DAPM_HP("HP", NULL),
+ SND_SOC_DAPM_SPK("SPK", NULL),
+ SND_SOC_DAPM_SPK("RCV", NULL),
+ SND_SOC_DAPM_LINE("LINE", set_lineout_switch),
+ SND_SOC_DAPM_LINE("HDMI", NULL),
+
+ SND_SOC_DAPM_MIC("Headset Mic", NULL),
+ SND_SOC_DAPM_MIC("Main Mic", set_ext_micbias),
+ SND_SOC_DAPM_MIC("Sub Mic", set_ext_submicbias),
+};
+
+const struct snd_soc_dapm_route kona_dapm_routes[] = {
+ { "HP", NULL, "HPOUT1L" },
+ { "HP", NULL, "HPOUT1R" },
+
+ { "SPK", NULL, "SPKOUTLN" },
+ { "SPK", NULL, "SPKOUTLP" },
+ { "SPK", NULL, "SPKOUTRN" },
+ { "SPK", NULL, "SPKOUTRP" },
+
+ { "RCV", NULL, "HPOUT2N" },
+ { "RCV", NULL, "HPOUT2P" },
+
+ { "LINE", NULL, "LINEOUT2N" },
+ { "LINE", NULL, "LINEOUT2P" },
+
+ { "HDMI", NULL, "LINEOUT1N" },
+ { "HDMI", NULL, "LINEOUT1P" },
+
+ { "IN1LP", NULL, "Main Mic" },
+ { "IN1LN", NULL, "Main Mic" },
+
+ { "IN2RP:VXRP", NULL, "Sub Mic" },
+ { "IN2RN", NULL, "Sub Mic" },
+
+ { "IN1RP", NULL, "MICBIAS2" },
+ { "IN1RN", NULL, "MICBIAS2" },
+ { "MICBIAS2", NULL, "Headset Mic" },
+};
+
+static struct snd_soc_dai_driver kona_ext_dai[] = {
+ {
+ .name = "kona.cp",
+ .playback = {
+ .channels_min = 1,
+ .channels_max = 2,
+ .rate_min = 8000,
+ .rate_max = 16000,
+ .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000,
+ .formats = SNDRV_PCM_FMTBIT_S16_LE,
+ },
+ .capture = {
+ .channels_min = 1,
+ .channels_max = 2,
+ .rate_min = 8000,
+ .rate_max = 16000,
+ .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000,
+ .formats = SNDRV_PCM_FMTBIT_S16_LE,
+ },
+ },
+ {
+ .name = "kona.bt",
+ .playback = {
+ .channels_min = 1,
+ .channels_max = 2,
+ .rate_min = 8000,
+ .rate_max = 16000,
+ .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000,
+ .formats = SNDRV_PCM_FMTBIT_S16_LE,
+ },
+ .capture = {
+ .channels_min = 1,
+ .channels_max = 2,
+ .rate_min = 8000,
+ .rate_max = 16000,
+ .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000,
+ .formats = SNDRV_PCM_FMTBIT_S16_LE,
+ },
+ },
+};
+
+#ifndef CONFIG_SEC_DEV_JACK
+static ssize_t earjack_state_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct snd_soc_codec *codec = dev_get_drvdata(dev);
+ struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
+
+ int report = 0;
+
+ if ((wm8994->micdet[0].jack->status & SND_JACK_HEADPHONE) ||
+ (wm8994->micdet[0].jack->status & SND_JACK_HEADSET)) {
+ report = 1;
+ }
+
+ return sprintf(buf, "%d\n", report);
+}
+
+static ssize_t earjack_state_store(struct device *dev,
+ struct device_attribute *attr, const char *buf, size_t size)
+{
+ pr_info("%s : operate nothing\n", __func__);
+
+ return size;
+}
+
+static ssize_t earjack_key_state_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct snd_soc_codec *codec = dev_get_drvdata(dev);
+ struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
+
+ int report = 0;
+
+ if (wm8994->micdet[0].jack->status & SND_JACK_BTN_0)
+ report = 1;
+
+ return sprintf(buf, "%d\n", report);
+}
+
+static ssize_t earjack_key_state_store(struct device *dev,
+ struct device_attribute *attr, const char *buf, size_t size)
+{
+ pr_info("%s : operate nothing\n", __func__);
+
+ return size;
+}
+
+static ssize_t earjack_select_jack_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ pr_info("%s : operate nothing\n", __func__);
+
+ return 0;
+}
+
+static ssize_t earjack_select_jack_store(struct device *dev,
+ struct device_attribute *attr, const char *buf, size_t size)
+{
+ struct snd_soc_codec *codec = dev_get_drvdata(dev);
+ struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
+
+ wm8994->mic_detecting = false;
+ wm8994->jack_mic = true;
+
+ kona_micd_set_rate(codec);
+
+ if ((!size) || (buf[0] != '1')) {
+ snd_soc_jack_report(wm8994->micdet[0].jack,
+ 0, SND_JACK_HEADSET);
+ dev_info(codec->dev, "Forced remove microphone\n");
+ } else {
+
+ snd_soc_jack_report(wm8994->micdet[0].jack,
+ SND_JACK_HEADSET, SND_JACK_HEADSET);
+ dev_info(codec->dev, "Forced detect microphone\n");
+ }
+
+ return size;
+}
+
+static DEVICE_ATTR(select_jack, S_IRUGO | S_IWUSR | S_IWGRP,
+ earjack_select_jack_show, earjack_select_jack_store);
+
+static DEVICE_ATTR(key_state, S_IRUGO | S_IWUSR | S_IWGRP,
+ earjack_key_state_show, earjack_key_state_store);
+
+static DEVICE_ATTR(state, S_IRUGO | S_IWUSR | S_IWGRP,
+ earjack_state_show, earjack_state_store);
+#endif
+
+static int kona_wm1811_init_paiftx(struct snd_soc_pcm_runtime *rtd)
+{
+ struct snd_soc_codec *codec = rtd->codec;
+ struct wm1811_machine_priv *wm1811
+ = snd_soc_card_get_drvdata(codec->card);
+ struct snd_soc_dai *aif1_dai = rtd->codec_dai;
+ struct wm8994 *control = codec->control_data;
+ struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
+#ifdef CONFIG_EXYNOS_SOUND_PLATFORM_DATA
+ const struct exynos_sound_platform_data *sound_pdata;
+#endif
+ int ret;
+#ifdef CONFIG_EXYNOS_SOUND_PLATFORM_DATA
+ sound_pdata = exynos_sound_get_platform_data();
+#endif
+
+ midas_snd_set_mclk(true, false);
+
+ rtd->codec_dai->driver->playback.channels_max =
+ rtd->cpu_dai->driver->playback.channels_max;
+
+ ret = snd_soc_add_controls(codec, kona_controls,
+ ARRAY_SIZE(kona_controls));
+
+ ret = snd_soc_dapm_new_controls(&codec->dapm, kona_dapm_widgets,
+ ARRAY_SIZE(kona_dapm_widgets));
+ if (ret != 0)
+ dev_err(codec->dev, "Failed to add DAPM widgets: %d\n", ret);
+
+ ret = snd_soc_dapm_add_routes(&codec->dapm, kona_dapm_routes,
+ ARRAY_SIZE(kona_dapm_routes));
+ if (ret != 0)
+ dev_err(codec->dev, "Failed to add DAPM routes: %d\n", ret);
+
+ ret = snd_soc_dai_set_sysclk(aif1_dai, WM8994_SYSCLK_MCLK2,
+ MIDAS_DEFAULT_MCLK2, SND_SOC_CLOCK_IN);
+ if (ret < 0)
+ dev_err(codec->dev, "Failed to boot clocking\n");
+
+ /* Force AIF1CLK on as it will be master for jack detection */
+ if (wm8994->revision > 1) {
+ ret = snd_soc_dapm_force_enable_pin(&codec->dapm, "AIF1CLK");
+ if (ret < 0)
+ dev_err(codec->dev, "Failed to enable AIF1CLK: %d\n",
+ ret);
+ }
+
+ ret = snd_soc_dapm_disable_pin(&codec->dapm, "S5P RP");
+ if (ret < 0)
+ dev_err(codec->dev, "Failed to disable S5P RP: %d\n", ret);
+
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "RCV");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "SPK");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "HP");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "Headset Mic");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "Sub Mic");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "Main Mic");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "AIF1DACDAT");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "AIF2DACDAT");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "AIF3DACDAT");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "AIF1ADCDAT");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "AIF2ADCDAT");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "AIF3ADCDAT");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "LINE");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "HDMI");
+
+ wm1811->codec = codec;
+
+ kona_micd_set_rate(codec);
+
+#ifdef CONFIG_SEC_DEV_JACK
+ /* By default use idle_bias_off, will override for WM8994 */
+ codec->dapm.idle_bias_off = 0;
+#else /* CONFIG_SEC_DEV_JACK */
+ wm1811->jack.status = 0;
+
+ ret = snd_soc_jack_new(codec, "Kona Jack",
+ SND_JACK_HEADSET | SND_JACK_BTN_0 |
+ SND_JACK_BTN_1 | SND_JACK_BTN_2,
+ &wm1811->jack);
+
+ if (ret < 0)
+ dev_err(codec->dev, "Failed to create jack: %d\n", ret);
+
+ ret = snd_jack_set_key(wm1811->jack.jack, SND_JACK_BTN_0, KEY_MEDIA);
+
+ if (ret < 0)
+ dev_err(codec->dev, "Failed to set KEY_MEDIA: %d\n", ret);
+
+ ret = snd_jack_set_key(wm1811->jack.jack, SND_JACK_BTN_1,
+ KEY_VOLUMEUP);
+ if (ret < 0)
+ dev_err(codec->dev, "Failed to set KEY_VOLUMEUP: %d\n", ret);
+
+ ret = snd_jack_set_key(wm1811->jack.jack, SND_JACK_BTN_2,
+ KEY_VOLUMEDOWN);
+
+ if (ret < 0)
+ dev_err(codec->dev, "Failed to set KEY_VOLUMEDOWN: %d\n", ret);
+
+ if (wm8994->revision > 1) {
+ dev_info(codec->dev, "wm1811: Rev %c support mic detection\n",
+ 'A' + wm8994->revision);
+#ifdef CONFIG_EXYNOS_SOUND_PLATFORM_DATA
+#ifdef CONFIG_USE_ADC_DET
+ if (sound_pdata->use_jackdet_type) {
+ ret = wm8958_mic_detect(codec, &wm1811->jack,
+ kona_micdet, wm1811, NULL, NULL);
+ } else {
+ ret = wm8958_mic_detect(codec, &wm1811->jack, NULL,
+ NULL, kona_mic_id, wm1811);
+ }
+#else
+ ret = wm8958_mic_detect(codec, &wm1811->jack, NULL,
+ NULL, kona_mic_id, wm1811);
+#endif
+#else
+ ret = wm8958_mic_detect(codec, &wm1811->jack, NULL,
+ NULL, kona_mic_id, wm1811);
+#endif
+
+ if (ret < 0)
+ dev_err(codec->dev, "Failed start detection: %d\n",
+ ret);
+ } else {
+ dev_info(codec->dev, "wm1811: Rev %c doesn't support mic detection\n",
+ 'A' + wm8994->revision);
+ codec->dapm.idle_bias_off = 0;
+ }
+ /* To wakeup for earjack event in suspend mode */
+ enable_irq_wake(control->irq);
+
+ wake_lock_init(&wm1811->jackdet_wake_lock,
+ WAKE_LOCK_SUSPEND, "kona_jackdet");
+
+ /* To support PBA function test */
+ jack_class = class_create(THIS_MODULE, "audio");
+
+ if (IS_ERR(jack_class))
+ pr_err("Failed to create class\n");
+
+ jack_dev = device_create(jack_class, NULL, 0, codec, "earjack");
+
+ if (device_create_file(jack_dev, &dev_attr_select_jack) < 0)
+ pr_err("Failed to create device file (%s)!\n",
+ dev_attr_select_jack.attr.name);
+
+ if (device_create_file(jack_dev, &dev_attr_key_state) < 0)
+ pr_err("Failed to create device file (%s)!\n",
+ dev_attr_key_state.attr.name);
+
+ if (device_create_file(jack_dev, &dev_attr_state) < 0)
+ pr_err("Failed to create device file (%s)!\n",
+ dev_attr_state.attr.name);
+
+#endif /* CONFIG_SEC_DEV_JACK */
+
+#ifdef CONFIG_USE_ADC_DET
+ pr_info("%s: register adc client\n", __func__);
+ wm1811->padc = s3c_adc_register(kona_snd_device, NULL, NULL, 0);
+#endif
+
+ return snd_soc_dapm_sync(&codec->dapm);
+}
+
+static struct snd_soc_dai_link kona_dai[] = {
+ { /* Sec_Fifo DAI i/f */
+ .name = "Sec_FIFO TX",
+ .stream_name = "Sec_Dai",
+ .cpu_dai_name = "samsung-i2s.4",
+ .codec_dai_name = "wm8994-aif1",
+#ifndef CONFIG_SND_SOC_SAMSUNG_USE_DMA_WRAPPER
+ .platform_name = "samsung-audio-idma",
+#else
+ .platform_name = "samsung-audio",
+#endif
+ .codec_name = "wm8994-codec",
+ .init = kona_wm1811_init_paiftx,
+ .ops = &kona_wm1811_aif1_ops,
+ },
+ {
+ .name = "Kona_WM1811 Voice",
+ .stream_name = "Voice Tx/Rx",
+ .cpu_dai_name = "kona.cp",
+ .codec_dai_name = "wm8994-aif2",
+ .platform_name = "snd-soc-dummy",
+ .codec_name = "wm8994-codec",
+ .ops = &kona_wm1811_aif2_ops,
+ .ignore_suspend = 1,
+ },
+ {
+ .name = "Kona_WM1811 BT",
+ .stream_name = "BT Tx/Rx",
+ .cpu_dai_name = "kona.bt",
+ .codec_dai_name = "wm8994-aif3",
+ .platform_name = "snd-soc-dummy",
+ .codec_name = "wm8994-codec",
+ .ops = &kona_wm1811_aif3_ops,
+ .ignore_suspend = 1,
+ },
+ { /* Primary DAI i/f */
+ .name = "WM8994 AIF1",
+ .stream_name = "Pri_Dai",
+ .cpu_dai_name = "samsung-i2s.0",
+ .codec_dai_name = "wm8994-aif1",
+ .platform_name = "samsung-audio",
+ .codec_name = "wm8994-codec",
+ .ops = &kona_wm1811_aif1_ops,
+ },
+};
+
+static int kona_card_suspend_post(struct snd_soc_card *card)
+{
+ struct snd_soc_codec *codec = card->rtd->codec;
+ struct snd_soc_dai *aif1_dai = card->rtd[0].codec_dai;
+ struct snd_soc_dai *aif2_dai = card->rtd[1].codec_dai;
+ int ret, reg;
+
+ if (!codec->active) {
+ ret = snd_soc_dai_set_sysclk(aif2_dai,
+ WM8994_SYSCLK_MCLK2,
+ MIDAS_DEFAULT_MCLK2,
+ SND_SOC_CLOCK_IN);
+
+ if (ret < 0)
+ dev_err(codec->dev, "Unable to switch to MCLK2: %d\n",
+ ret);
+
+ ret = snd_soc_dai_set_pll(aif2_dai, WM8994_FLL2, 0, 0, 0);
+
+ if (ret < 0)
+ dev_err(codec->dev, "Unable to stop FLL2\n");
+
+ ret = snd_soc_dai_set_sysclk(aif1_dai,
+ WM8994_SYSCLK_MCLK2,
+ MIDAS_DEFAULT_MCLK2,
+ SND_SOC_CLOCK_IN);
+ if (ret < 0)
+ dev_err(codec->dev, "Unable to switch to MCLK2\n");
+
+ ret = snd_soc_dai_set_pll(aif1_dai, WM8994_FLL1, 0, 0, 0);
+
+ if (ret < 0)
+ dev_err(codec->dev, "Unable to stop FLL1\n");
+
+ midas_snd_set_mclk(false, true);
+
+ reg = WM8994_AIF1_TRI;
+ snd_soc_update_bits(codec, WM8994_AIF1_MASTER_SLAVE,
+ WM8994_AIF1_TRI, reg);
+
+ reg = WM8994_AIF2_TRI;
+ snd_soc_update_bits(codec, WM8994_AIF2_MASTER_SLAVE,
+ WM8994_AIF2_TRI, reg);
+ }
+
+ exynos4_sys_powerdown_xusbxti_control(midas_snd_get_mclk() ? 1 : 0);
+
+ return 0;
+}
+
+static int kona_card_resume_pre(struct snd_soc_card *card)
+{
+ struct snd_soc_codec *codec = card->rtd->codec;
+ struct snd_soc_dai *aif1_dai = card->rtd[0].codec_dai;
+ int ret, reg;
+
+ midas_snd_set_mclk(true, false);
+
+ /* Switch the FLL */
+ ret = snd_soc_dai_set_pll(aif1_dai, WM8994_FLL1,
+ WM8994_FLL_SRC_MCLK1,
+ MIDAS_DEFAULT_MCLK1,
+ MIDAS_DEFAULT_SYNC_CLK);
+
+ if (ret < 0)
+ dev_err(aif1_dai->dev, "Unable to start FLL1: %d\n", ret);
+
+ /* Then switch AIF1CLK to it */
+ ret = snd_soc_dai_set_sysclk(aif1_dai,
+ WM8994_SYSCLK_FLL1,
+ MIDAS_DEFAULT_SYNC_CLK,
+ SND_SOC_CLOCK_IN);
+
+ if (ret < 0)
+ dev_err(aif1_dai->dev, "Unable to switch to FLL1: %d\n", ret);
+
+ /* workaround for jack detection
+ * sometimes WM8994_GPIO_1 type changed wrong function type
+ * so if type mismatched, update to IRQ type
+ */
+ reg = snd_soc_read(codec, WM8994_GPIO_1);
+ if ((reg & WM8994_GPN_FN_MASK) != WM8994_GP_FN_IRQ) {
+ dev_err(codec->dev, "%s: GPIO1 type 0x%x\n", __func__, reg);
+ snd_soc_write(codec, WM8994_GPIO_1, WM8994_GP_FN_IRQ);
+ }
+
+ return 0;
+}
+
+static struct snd_soc_card kona = {
+ .name = "Kona_WM1811",
+ .dai_link = kona_dai,
+ .num_links = ARRAY_SIZE(kona_dai),
+ .suspend_post = kona_card_suspend_post,
+ .resume_pre = kona_card_resume_pre,
+};
+
+static int __init kona_audio_init(void)
+{
+ struct wm1811_machine_priv *wm1811;
+#ifdef CONFIG_EXYNOS_SOUND_PLATFORM_DATA
+ const struct exynos_sound_platform_data *sound_pdata;
+#endif
+ int ret;
+
+ wm1811 = kzalloc(sizeof *wm1811, GFP_KERNEL);
+ if (!wm1811) {
+ pr_err("Failed to allocate memory\n");
+ ret = -ENOMEM;
+ goto err_kzalloc;
+ }
+ snd_soc_card_set_drvdata(&kona, wm1811);
+
+ kona_snd_device = platform_device_alloc("soc-audio", -1);
+ if (!kona_snd_device) {
+ ret = -ENOMEM;
+ goto err_device_alloc;
+ }
+
+ ret = snd_soc_register_dais(&kona_snd_device->dev, kona_ext_dai,
+ ARRAY_SIZE(kona_ext_dai));
+ if (ret != 0)
+ pr_err("Failed to register external DAIs: %d\n", ret);
+
+ platform_set_drvdata(kona_snd_device, &kona);
+
+ ret = platform_device_add(kona_snd_device);
+ if (ret)
+ platform_device_put(kona_snd_device);
+
+#ifdef CONFIG_EXYNOS_SOUND_PLATFORM_DATA
+ sound_pdata = exynos_sound_get_platform_data();
+ if (!sound_pdata)
+ pr_info("%s: don't use sound pdata\n", __func__);
+#ifdef CONFIG_USE_ADC_DET
+ if (sound_pdata->zones) {
+ wm1811->zones = sound_pdata->zones;
+ wm1811->num_zones = sound_pdata->num_zones;
+ }
+ pr_info("%s:use_jackdet_type = %d\n", __func__,
+ sound_pdata->use_jackdet_type);
+ wm1811->use_jackdet_type = sound_pdata->use_jackdet_type;
+#endif
+#endif
+
+ kona_gpio_init();
+
+ return ret;
+
+err_device_alloc:
+ kfree(wm1811);
+err_kzalloc:
+ return ret;
+}
+module_init(kona_audio_init);
+
+static void __exit kona_audio_exit(void)
+{
+ struct snd_soc_card *card = &kona;
+ struct wm1811_machine_priv *wm1811 = snd_soc_card_get_drvdata(card);
+#ifdef CONFIG_USE_ADC_DET
+ s3c_adc_release(wm1811->padc);
+#endif
+ platform_device_unregister(kona_snd_device);
+ kfree(wm1811);
+}
+module_exit(kona_audio_exit);
+
+MODULE_AUTHOR("Quartz.Jang <quartz.jang@samsung.com");
+MODULE_DESCRIPTION("ALSA SoC Kona WM1811");
+MODULE_LICENSE("GPL");
diff --git a/sound/soc/samsung/m3_wm1811.c b/sound/soc/samsung/m3_wm1811.c
index 949f7d7..6e933c3 100644
--- a/sound/soc/samsung/m3_wm1811.c
+++ b/sound/soc/samsung/m3_wm1811.c
@@ -32,6 +32,7 @@
#include <linux/mfd/wm8994/core.h>
#include <linux/mfd/wm8994/registers.h>
#include <linux/mfd/wm8994/pdata.h>
+#include <linux/mfd/wm8994/gpio.h>
#if defined(CONFIG_SND_USE_MUIC_SWITCH)
#include <linux/mfd/max77693-private.h>
@@ -338,7 +339,7 @@ static void m3_micd_set_rate(struct snd_soc_codec *codec)
WM8958_MICD_RATE_MASK, val);
}
-static void m3_micdet(u16 status, void *data)
+static void m3_mic_id(void *data, u16 status)
{
struct wm1811_machine_priv *wm1811 = data;
struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(wm1811->codec);
@@ -414,25 +415,6 @@ static void m3_micdet(u16 status, void *data)
}
}
}
-
- /* Report short circuit as a button */
- if (wm8994->jack_mic) {
- report = 0;
- if (status & WM1811_JACKDET_BTN0)
- report |= SND_JACK_BTN_0;
-
- if (status & WM1811_JACKDET_BTN1)
- report |= SND_JACK_BTN_1;
-
- if (status & WM1811_JACKDET_BTN2)
- report |= SND_JACK_BTN_2;
-
- dev_dbg(wm1811->codec->dev, "Detected Button: %08x (%08X)\n",
- report, status);
-
- snd_soc_jack_report(wm8994->micdet[0].jack, report,
- wm8994->btn_mask);
- }
}
static int m3_wm1811_aif1_hw_params(struct snd_pcm_substream *substream,
@@ -915,12 +897,12 @@ static int m3_wm1811_init_paiftx(struct snd_soc_pcm_runtime *rtd)
dev_err(codec->dev, "Failed to set KEY_MEDIA: %d\n", ret);
ret = snd_jack_set_key(wm1811->jack.jack, SND_JACK_BTN_1,
- KEY_VOLUMEDOWN);
+ KEY_VOLUMEUP);
if (ret < 0)
dev_err(codec->dev, "Failed to set KEY_VOLUMEUP: %d\n", ret);
ret = snd_jack_set_key(wm1811->jack.jack, SND_JACK_BTN_2,
- KEY_VOLUMEUP);
+ KEY_VOLUMEDOWN);
if (ret < 0)
dev_err(codec->dev, "Failed to set KEY_VOLUMEDOWN: %d\n", ret);
@@ -928,8 +910,8 @@ static int m3_wm1811_init_paiftx(struct snd_soc_pcm_runtime *rtd)
if (wm8994->revision > 1) {
dev_info(codec->dev, "wm1811: Rev %c support mic detection\n",
'A' + wm8994->revision);
- ret = wm8958_mic_detect(codec, &wm1811->jack, m3_micdet,
- wm1811);
+ ret = wm8958_mic_detect(codec, &wm1811->jack, NULL,
+ NULL, m3_mic_id, wm1811);
if (ret < 0)
dev_err(codec->dev, "Failed start detection: %d\n",
@@ -1131,6 +1113,7 @@ static int m3_card_resume_post(struct snd_soc_card *card)
{
struct snd_soc_codec *codec = card->rtd->codec;
struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
+ int reg = 0;
#ifdef CONFIG_SND_USE_LINEOUT_SWITCH
if (lineout_mode == 1 &&
@@ -1141,6 +1124,11 @@ static int m3_card_resume_post(struct snd_soc_card *card)
gpio_set_value(GPIO_VPS_SOUND_EN, 1);
}
#endif
+ reg = snd_soc_read(codec, WM8994_GPIO_1);
+ if ((reg & WM8994_GPN_FN_MASK) != WM8994_GP_FN_IRQ) {
+ dev_err(codec->dev, "%s: GPIO1 type 0x%x\n", __func__, reg);
+ snd_soc_write(codec, WM8994_GPIO_1, WM8994_GP_FN_IRQ);
+ }
#ifdef CONFIG_SEC_DEV_JACK
snd_soc_dapm_force_enable_pin(&codec->dapm, "AIF1CLK");
#endif
diff --git a/sound/soc/samsung/midas_wm1811.c b/sound/soc/samsung/midas_wm1811.c
index 1f5becc..d505f87 100644
--- a/sound/soc/samsung/midas_wm1811.c
+++ b/sound/soc/samsung/midas_wm1811.c
@@ -37,6 +37,14 @@
#include <linux/mfd/wm8994/pdata.h>
#include <linux/mfd/wm8994/gpio.h>
+#ifdef CONFIG_EXYNOS_SOUND_PLATFORM_DATA
+#include <linux/exynos_audio.h>
+#endif
+
+#ifdef CONFIG_USE_ADC_DET
+#include <plat/adc.h>
+#endif
+
#if defined(CONFIG_SND_USE_MUIC_SWITCH)
#include <linux/mfd/max77693-private.h>
#endif
@@ -60,6 +68,49 @@
#define WM1811_JACKDET_BTN1 0x10
#define WM1811_JACKDET_BTN2 0x08
+#define JACK_ADC_CH 3
+#define JACK_SAMPLE_SIZE 5
+
+#define MAX_ZONE_LIMIT 10
+/* keep this value if you support double-pressed concept */
+#define WAKE_LOCK_TIME (HZ * 5) /* 5 sec */
+#define EAR_CHECK_LOOP_CNT 10
+
+struct wm1811_machine_priv {
+ struct snd_soc_jack jack;
+ struct snd_soc_codec *codec;
+ struct wake_lock jackdet_wake_lock;
+ void (*lineout_switch_f) (int on);
+ void (*set_main_mic_f) (int on);
+ void (*set_sub_mic_f) (int on);
+ int (*get_g_det_value_f) (void);
+ int (*get_g_det_irq_num_f) (void);
+#ifdef CONFIG_USE_ADC_DET
+ struct s3c_adc_client *padc;
+ struct jack_zone *zones;
+ int num_zones;
+ int use_jackdet_type;
+#endif
+};
+
+enum {
+ SEC_JACK_NO_DEVICE = 0x0,
+ SEC_HEADSET_4POLE = 0x01 << 0,
+ SEC_HEADSET_3POLE = 0x01 << 1,
+ SEC_TTY_DEVICE = 0x01 << 2,
+ SEC_FM_HEADSET = 0x01 << 3,
+ SEC_FM_SPEAKER = 0x01 << 4,
+ SEC_TVOUT_DEVICE = 0x01 << 5,
+ SEC_EXTRA_DOCK_SPEAKER = 0x01 << 6,
+ SEC_EXTRA_CAR_DOCK_SPEAKER = 0x01 << 7,
+ SEC_UNKNOWN_DEVICE = 0x01 << 8,
+};
+
+#ifdef CONFIG_USE_ADC_DET
+static bool recheck_jack;
+static int jack_get_adc_data(struct s3c_adc_client *padc);
+static void jack_set_type(struct wm1811_machine_priv *wm1811, int jack_type);
+#endif
static struct wm8958_micd_rate midas_det_rates[] = {
{ MIDAS_DEFAULT_MCLK2, true, 0, 0 },
@@ -104,6 +155,11 @@ const char *lineout_mode_text[] = {
"Off", "On"
};
+static int aif2_digital_mute;
+const char *switch_mode_text[] = {
+ "Off", "On"
+};
+
#ifndef CONFIG_SEC_DEV_JACK
/* To support PBA function test */
static struct class *jack_class;
@@ -115,14 +171,9 @@ static bool midas_fll1_active;
struct snd_soc_dai *midas_aif1_dai;
#endif
-struct wm1811_machine_priv {
- struct snd_soc_jack jack;
- struct snd_soc_codec *codec;
- struct delayed_work mic_work;
- struct wake_lock jackdet_wake_lock;
-};
+static struct platform_device *midas_snd_device;
-#ifdef CONFIG_MACH_GC1
+#if defined(CONFIG_MACH_GC1) || defined(CONFIG_MACH_GC2PD)
static struct snd_soc_codec *wm1811_codec;
void set_wm1811_micbias2(bool on)
@@ -242,6 +293,10 @@ static const struct soc_enum input_clamp_enum[] = {
SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(input_clamp_text), input_clamp_text),
};
+static const struct soc_enum switch_mode_enum[] = {
+ SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(switch_mode_text), switch_mode_text),
+};
+
static int get_aif2_mode(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
{
@@ -307,6 +362,39 @@ static int set_input_clamp(struct snd_kcontrol *kcontrol,
return 0;
}
+static int get_aif2_mute_status(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ ucontrol->value.integer.value[0] = aif2_digital_mute;
+ return 0;
+}
+
+static int set_aif2_mute_status(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+ int reg;
+
+ aif2_digital_mute = ucontrol->value.integer.value[0];
+
+ if (snd_soc_read(codec, WM8994_POWER_MANAGEMENT_6)
+ & WM8994_AIF2_DACDAT_SRC)
+ aif2_digital_mute = 0;
+
+ if (aif2_digital_mute)
+ reg = WM8994_AIF1DAC1_MUTE;
+ else
+ reg = 0;
+
+ snd_soc_update_bits(codec, WM8994_AIF2_DAC_FILTERS_1,
+ WM8994_AIF1DAC1_MUTE, reg);
+
+ pr_info("set aif2_digital_mute : %s\n",
+ switch_mode_text[aif2_digital_mute]);
+
+ return 0;
+}
+
static int midas_ext_micbias(struct snd_soc_dapm_widget *w,
struct snd_kcontrol *kcontrol, int event)
@@ -506,13 +594,170 @@ static void midas_start_fll1(struct snd_soc_dai *aif1_dai)
}
#endif
-static void midas_micdet(u16 status, void *data)
+#ifdef CONFIG_USE_ADC_DET
+static int jack_get_adc_data(struct s3c_adc_client *padc)
+{
+ int adc_data;
+ int adc_max = 0;
+ int adc_min = 0xFFFF;
+ int adc_total = 0;
+ int adc_retry_cnt = 0;
+ int i;
+
+ for (i = 0; i < JACK_SAMPLE_SIZE; i++) {
+
+ adc_data = s3c_adc_read(padc, JACK_ADC_CH);
+
+ if (adc_data < 0) {
+
+ adc_retry_cnt++;
+
+ if (adc_retry_cnt > 10)
+ return adc_data;
+ }
+
+ if (i != 0) {
+ if (adc_data > adc_max)
+ adc_max = adc_data;
+ else if (adc_data < adc_min)
+ adc_min = adc_data;
+ } else {
+ adc_max = adc_data;
+ adc_min = adc_data;
+ }
+ adc_total += adc_data;
+ }
+
+ return (adc_total - adc_max - adc_min) / (JACK_SAMPLE_SIZE - 2);
+}
+
+static void determine_jack_type(struct wm1811_machine_priv *wm1811)
+{
+ struct jack_zone *zones = wm1811->zones;
+ struct snd_soc_codec *codec = wm1811->codec;
+ int size = wm1811->num_zones;
+ int count[MAX_ZONE_LIMIT] = {0};
+ int adc;
+ int i;
+
+ /* set mic bias to enable adc */
+ while (snd_soc_read(codec, WM1811_JACKDET_CTRL) & WM1811_JACKDET_LVL) {
+ adc = jack_get_adc_data(wm1811->padc);
+
+ pr_info("%s: adc = %d\n", __func__, adc);
+
+ if (adc < 0)
+ break;
+
+ /* determine the type of headset based on the
+ * adc value. An adc value can fall in various
+ * ranges or zones. Within some ranges, the type
+ * can be returned immediately. Within others, the
+ * value is considered unstable and we need to sample
+ * a few more types (up to the limit determined by
+ * the range) before we return the type for that range.
+ */
+ for (i = 0; i < size; i++) {
+ if (adc <= zones[i].adc_high) {
+ if (++count[i] > zones[i].check_count) {
+ if (recheck_jack == true && i == 4) {
+ pr_info("%s : something wrong connection!\n",
+ __func__);
+
+ recheck_jack = false;
+ return;
+ }
+ jack_set_type(wm1811,
+ zones[i].jack_type);
+ return;
+ }
+ msleep(zones[i].delay_ms);
+ break;
+ }
+ }
+ }
+
+ recheck_jack = false;
+ /* jack removed before detection complete */
+ pr_debug("%s : jack removed before detection complete\n", __func__);
+}
+
+static void jack_set_type(struct wm1811_machine_priv *wm1811, int jack_type)
+{
+ struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(wm1811->codec);
+
+ if (jack_type == SEC_HEADSET_4POLE) {
+ dev_info(wm1811->codec->dev, "Detected microphone\n");
+
+ wm8994->mic_detecting = false;
+ wm8994->jack_mic = true;
+
+ midas_micd_set_rate(wm1811->codec);
+
+ snd_soc_jack_report(wm8994->micdet[0].jack, SND_JACK_HEADSET,
+ SND_JACK_HEADSET);
+
+ snd_soc_update_bits(wm1811->codec, WM8958_MIC_DETECT_1,
+ WM8958_MICD_ENA, 1);
+ } else {
+ dev_info(wm1811->codec->dev, "Detected headphone\n");
+ wm8994->mic_detecting = false;
+
+ midas_micd_set_rate(wm1811->codec);
+
+ snd_soc_jack_report(wm8994->micdet[0].jack, SND_JACK_HEADPHONE,
+ SND_JACK_HEADSET);
+
+ /* If we have jackdet that will detect removal */
+ if (wm8994->jackdet) {
+ snd_soc_update_bits(wm1811->codec, WM8958_MIC_DETECT_1,
+ WM8958_MICD_ENA, 0);
+
+ if (wm8994->active_refcount) {
+ snd_soc_update_bits(wm1811->codec,
+ WM8994_ANTIPOP_2,
+ WM1811_JACKDET_MODE_MASK,
+ WM1811_JACKDET_MODE_AUDIO);
+ }
+
+ if (wm8994->pdata->jd_ext_cap) {
+ mutex_lock(&wm1811->codec->mutex);
+ snd_soc_dapm_disable_pin(&wm1811->codec->dapm,
+ "MICBIAS2");
+ snd_soc_dapm_sync(&wm1811->codec->dapm);
+ mutex_unlock(&wm1811->codec->mutex);
+ }
+ }
+ }
+}
+
+static void midas_micdet(void *data)
{
struct wm1811_machine_priv *wm1811 = data;
struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(wm1811->codec);
- int report;
+ struct snd_soc_codec *codec = wm1811->codec;
+
+ pr_info("%s: detected jack\n", __func__);
+ wm8994->mic_detecting = true;
+
+ wake_lock_timeout(&wm1811->jackdet_wake_lock, 5 * HZ);
+
+ snd_soc_update_bits(codec, WM8958_MICBIAS2,
+ WM8958_MICB2_MODE, 0);
+ snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_1,
+ WM8994_MICB2_ENA_MASK, WM8994_MICB2_ENA);
+
+ determine_jack_type(wm1811);
+}
+#endif
+static void midas_mic_id(void *data, u16 status)
+{
+ struct wm1811_machine_priv *wm1811 = data;
+ struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(wm1811->codec);
+
+ pr_info("%s: detected jack\n", __func__);
wake_lock_timeout(&wm1811->jackdet_wake_lock, 5 * HZ);
/* Either nothing present or just starting detection */
@@ -582,25 +827,6 @@ static void midas_micdet(u16 status, void *data)
}
}
}
-
- /* Report short circuit as a button */
- if (wm8994->jack_mic) {
- report = 0;
- if (status & WM1811_JACKDET_BTN0)
- report |= SND_JACK_BTN_0;
-
- if (status & WM1811_JACKDET_BTN1)
- report |= SND_JACK_BTN_1;
-
- if (status & WM1811_JACKDET_BTN2)
- report |= SND_JACK_BTN_2;
-
- dev_dbg(wm1811->codec->dev, "Detected Button: %08x (%08X)\n",
- report, status);
-
- snd_soc_jack_report(wm8994->micdet[0].jack, report,
- wm8994->btn_mask);
- }
}
#ifdef CONFIG_SND_SAMSUNG_I2S_MASTER
@@ -812,6 +1038,9 @@ static int midas_wm1811_aif2_hw_params(struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params)
{
struct snd_soc_pcm_runtime *rtd = substream->private_data;
+#ifndef CONFIG_MACH_BAFFIN
+ struct snd_soc_codec *codec = rtd->codec;
+#endif
struct snd_soc_dai *codec_dai = rtd->codec_dai;
int ret;
int prate;
@@ -830,7 +1059,7 @@ static int midas_wm1811_aif2_hw_params(struct snd_pcm_substream *substream,
}
#if defined(CONFIG_LTE_MODEM_CMC221) || defined(CONFIG_MACH_M0_CTC)
-#if defined(CONFIG_MACH_C1_KOR_LGT)
+#if defined(CONFIG_MACH_C1_KOR_LGT) || defined(CONFIG_MACH_BAFFIN_KOR_LGT)
/* Set the codec DAI configuration */
if (aif2_mode == 0) {
if (kpcs_mode == 1)
@@ -843,9 +1072,15 @@ static int midas_wm1811_aif2_hw_params(struct snd_pcm_substream *substream,
| SND_SOC_DAIFMT_IB_NF
| SND_SOC_DAIFMT_CBS_CFS);
} else
+#if defined(CONFIG_MACH_C1_KOR_LGT) || defined(CONFIG_MACH_BAFFIN_KOR_LGT)
+ ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_DSP_A
+ | SND_SOC_DAIFMT_IB_NF
+ | SND_SOC_DAIFMT_CBM_CFM);
+#else
ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_NB_NF
| SND_SOC_DAIFMT_CBM_CFM);
+#endif
#else
if (aif2_mode == 0)
/* Set the codec DAI configuration */
@@ -925,6 +1160,16 @@ static int midas_wm1811_aif2_hw_params(struct snd_pcm_substream *substream,
if (ret < 0)
dev_err(codec_dai->dev, "Unable to switch to FLL2: %d\n", ret);
+#ifndef CONFIG_MACH_BAFFIN
+ if (!(snd_soc_read(codec, WM8994_INTERRUPT_RAW_STATUS_2)
+ & WM8994_FLL2_LOCK_STS)) {
+ dev_info(codec_dai->dev, "%s: use mclk1 for FLL2\n", __func__);
+ ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL2,
+ WM8994_FLL_SRC_MCLK1,
+ MIDAS_DEFAULT_MCLK1, prate * 256);
+ }
+#endif
+
dev_info(codec_dai->dev, "%s --\n", __func__);
return 0;
}
@@ -968,6 +1213,9 @@ static const struct snd_kcontrol_new midas_controls[] = {
SOC_ENUM_EXT("LineoutSwitch Mode", lineout_mode_enum[0],
get_lineout_mode, set_lineout_mode),
+ SOC_ENUM_EXT("AIF2 digital mute", switch_mode_enum[0],
+ get_aif2_mute_status, set_aif2_mute_status),
+
};
const struct snd_soc_dapm_widget midas_dapm_widgets[] = {
@@ -997,10 +1245,14 @@ const struct snd_soc_dapm_route midas_dapm_routes[] = {
{ "RCV", NULL, "HPOUT2N" },
{ "RCV", NULL, "HPOUT2P" },
-
+#if defined(CONFIG_MACH_BAFFIN_KOR_SKT) || defined(CONFIG_MACH_BAFFIN_KOR_KT) \
+ || defined(CONFIG_MACH_BAFFIN_KOR_LGT)
+ { "LINE", NULL, "HPOUT1L" },
+ { "LINE", NULL, "HPOUT1R" },
+#else
{ "LINE", NULL, "LINEOUT2N" },
{ "LINE", NULL, "LINEOUT2P" },
-
+#endif
{ "HDMI", NULL, "LINEOUT1N" },
{ "HDMI", NULL, "LINEOUT1P" },
@@ -1214,13 +1466,19 @@ static int midas_wm1811_init_paiftx(struct snd_soc_pcm_runtime *rtd)
struct snd_soc_dai *aif1_dai = rtd->codec_dai;
struct wm8994 *control = codec->control_data;
struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
+#ifdef CONFIG_EXYNOS_SOUND_PLATFORM_DATA
+ const struct exynos_sound_platform_data *sound_pdata;
+#endif
int ret;
+#ifdef CONFIG_EXYNOS_SOUND_PLATFORM_DATA
+ sound_pdata = exynos_sound_get_platform_data();
+#endif
#ifdef SND_USE_BIAS_LEVEL
midas_aif1_dai = aif1_dai;
#endif
-#ifdef CONFIG_MACH_GC1
+#if defined(CONFIG_MACH_GC1) || defined(CONFIG_MACH_GC2PD)
wm1811_codec = codec;
#endif
@@ -1300,12 +1558,12 @@ static int midas_wm1811_init_paiftx(struct snd_soc_pcm_runtime *rtd)
dev_err(codec->dev, "Failed to set KEY_MEDIA: %d\n", ret);
ret = snd_jack_set_key(wm1811->jack.jack, SND_JACK_BTN_1,
- KEY_VOLUMEDOWN);
+ KEY_VOLUMEUP);
if (ret < 0)
dev_err(codec->dev, "Failed to set KEY_VOLUMEUP: %d\n", ret);
ret = snd_jack_set_key(wm1811->jack.jack, SND_JACK_BTN_2,
- KEY_VOLUMEUP);
+ KEY_VOLUMEDOWN);
if (ret < 0)
dev_err(codec->dev, "Failed to set KEY_VOLUMEDOWN: %d\n", ret);
@@ -1313,8 +1571,23 @@ static int midas_wm1811_init_paiftx(struct snd_soc_pcm_runtime *rtd)
if (wm8994->revision > 1) {
dev_info(codec->dev, "wm1811: Rev %c support mic detection\n",
'A' + wm8994->revision);
- ret = wm8958_mic_detect(codec, &wm1811->jack, midas_micdet,
- wm1811);
+#ifdef CONFIG_EXYNOS_SOUND_PLATFORM_DATA
+#ifdef CONFIG_USE_ADC_DET
+ if (sound_pdata->use_jackdet_type) {
+ ret = wm8958_mic_detect(codec, &wm1811->jack,
+ midas_micdet, wm1811, NULL, NULL);
+ } else {
+ ret = wm8958_mic_detect(codec, &wm1811->jack, NULL,
+ NULL, midas_mic_id, wm1811);
+ }
+#else
+ ret = wm8958_mic_detect(codec, &wm1811->jack, NULL,
+ NULL, midas_mic_id, wm1811);
+#endif
+#else
+ ret = wm8958_mic_detect(codec, &wm1811->jack, NULL,
+ NULL, midas_mic_id, wm1811);
+#endif
if (ret < 0)
dev_err(codec->dev, "Failed start detection: %d\n",
@@ -1355,6 +1628,12 @@ static int midas_wm1811_init_paiftx(struct snd_soc_pcm_runtime *rtd)
dev_attr_reselect_jack.attr.name);
#endif /* CONFIG_SEC_DEV_JACK */
+
+#ifdef CONFIG_USE_ADC_DET
+ pr_info("%s: register adc client\n", __func__);
+ wm1811->padc = s3c_adc_register(midas_snd_device, NULL, NULL, 0);
+#endif
+
return snd_soc_dapm_sync(&codec->dapm);
}
@@ -1626,11 +1905,12 @@ static struct snd_soc_card midas = {
.resume_post = midas_card_resume_post
};
-static struct platform_device *midas_snd_device;
-
static int __init midas_audio_init(void)
{
struct wm1811_machine_priv *wm1811;
+#ifdef CONFIG_EXYNOS_SOUND_PLATFORM_DATA
+ const struct exynos_sound_platform_data *sound_pdata;
+#endif
int ret;
wm1811 = kzalloc(sizeof *wm1811, GFP_KERNEL);
@@ -1658,6 +1938,21 @@ static int __init midas_audio_init(void)
if (ret)
platform_device_put(midas_snd_device);
+#ifdef CONFIG_EXYNOS_SOUND_PLATFORM_DATA
+ sound_pdata = exynos_sound_get_platform_data();
+ if (!sound_pdata)
+ pr_info("%s: don't use sound pdata\n", __func__);
+#ifdef CONFIG_USE_ADC_DET
+ if (sound_pdata->zones) {
+ wm1811->zones = sound_pdata->zones;
+ wm1811->num_zones = sound_pdata->num_zones;
+ }
+ pr_info("%s:use_jackdet_type = %d\n", __func__,
+ sound_pdata->use_jackdet_type);
+ wm1811->use_jackdet_type = sound_pdata->use_jackdet_type;
+#endif
+#endif
+
midas_gpio_init();
return ret;
@@ -1673,6 +1968,9 @@ static void __exit midas_audio_exit(void)
{
struct snd_soc_card *card = &midas;
struct wm1811_machine_priv *wm1811 = snd_soc_card_get_drvdata(card);
+#ifdef CONFIG_USE_ADC_DET
+ s3c_adc_release(wm1811->padc);
+#endif
platform_device_unregister(midas_snd_device);
kfree(wm1811);
}
diff --git a/sound/soc/samsung/t0_wm1811.c b/sound/soc/samsung/t0_wm1811.c
index 30aa6c1..0085ff9 100644
--- a/sound/soc/samsung/t0_wm1811.c
+++ b/sound/soc/samsung/t0_wm1811.c
@@ -35,8 +35,13 @@
#include <linux/mfd/wm8994/registers.h>
#include <linux/mfd/wm8994/pdata.h>
#include <linux/mfd/wm8994/gpio.h>
+
#include <linux/exynos_audio.h>
+#ifdef CONFIG_USE_ADC_DET
+#include <plat/adc.h>
+#endif
+
#if defined(CONFIG_SND_USE_MUIC_SWITCH)
#include <linux/mfd/max77693-private.h>
#endif
@@ -68,6 +73,50 @@
#define MIC_FORCE_DISABLE 2
#define MIC_FORCE_ENABLE 3
+#define JACK_ADC_CH 3
+#define JACK_SAMPLE_SIZE 5
+
+#define MAX_ZONE_LIMIT 10
+/* keep this value if you support double-pressed concept */
+#define WAKE_LOCK_TIME (HZ * 5) /* 5 sec */
+#define EAR_CHECK_LOOP_CNT 10
+
+struct wm1811_machine_priv {
+ struct snd_soc_jack jack;
+ struct snd_soc_codec *codec;
+ struct wake_lock jackdet_wake_lock;
+ void (*lineout_switch_f) (int on);
+ void (*set_main_mic_f) (int on);
+ void (*set_sub_mic_f) (int on);
+ int (*get_g_det_value_f) (void);
+ int (*get_g_det_irq_num_f) (void);
+#ifdef CONFIG_USE_ADC_DET
+ struct s3c_adc_client *padc;
+ struct jack_zone *zones;
+ int num_zones;
+ int use_jackdet_type;
+#endif
+};
+
+enum {
+ SEC_JACK_NO_DEVICE = 0x0,
+ SEC_HEADSET_4POLE = 0x01 << 0,
+ SEC_HEADSET_3POLE = 0x01 << 1,
+ SEC_TTY_DEVICE = 0x01 << 2,
+ SEC_FM_HEADSET = 0x01 << 3,
+ SEC_FM_SPEAKER = 0x01 << 4,
+ SEC_TVOUT_DEVICE = 0x01 << 5,
+ SEC_EXTRA_DOCK_SPEAKER = 0x01 << 6,
+ SEC_EXTRA_CAR_DOCK_SPEAKER = 0x01 << 7,
+ SEC_UNKNOWN_DEVICE = 0x01 << 8,
+};
+
+#ifdef CONFIG_USE_ADC_DET
+static bool recheck_jack;
+static int jack_get_adc_data(struct s3c_adc_client *padc);
+static void jack_set_type(struct wm1811_machine_priv *wm1811, int jack_type);
+#endif
+
static struct wm8958_micd_rate t0_det_rates[] = {
{ MIDAS_DEFAULT_MCLK2, true, 0, 0 },
{ MIDAS_DEFAULT_MCLK2, false, 0, 0 },
@@ -107,16 +156,7 @@ static struct class *jack_class;
static struct device *jack_dev;
#endif
-struct wm1811_machine_priv {
- struct snd_soc_jack jack;
- struct snd_soc_codec *codec;
- struct wake_lock jackdet_wake_lock;
- void (*lineout_switch_f) (int on);
- void (*set_main_mic_f) (int on);
- void (*set_sub_mic_f) (int on);
- int (*get_g_det_value_f) (void);
- int (*get_g_det_irq_num_f) (void);
-};
+static struct platform_device *t0_snd_device;
static const struct soc_enum switch_mode_enum[] = {
SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(switch_mode_text), switch_mode_text),
@@ -270,7 +310,7 @@ static int set_sub_mic_bias_mode(struct snd_kcontrol *kcontrol,
WM8994_MICB1_ENA, WM8994_MICB1_ENA);
if (wm1811->set_sub_mic_f)
- wm1811->set_main_mic_f(1);
+ wm1811->set_sub_mic_f(1);
break;
case MIC_ENABLE:
snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_1,
@@ -479,30 +519,174 @@ static void t0_micd_set_rate(struct snd_soc_codec *codec)
WM8958_MICD_RATE_MASK, val);
}
-static void t0_micdet(u16 status, void *data)
+#ifdef CONFIG_USE_ADC_DET
+static int jack_get_adc_data(struct s3c_adc_client *padc)
+{
+ int adc_data;
+ int adc_max = 0;
+ int adc_min = 0xFFFF;
+ int adc_total = 0;
+ int adc_retry_cnt = 0;
+ int i;
+
+ for (i = 0; i < JACK_SAMPLE_SIZE; i++) {
+
+ adc_data = s3c_adc_read(padc, JACK_ADC_CH);
+
+ if (adc_data < 0) {
+
+ adc_retry_cnt++;
+
+ if (adc_retry_cnt > 10)
+ return adc_data;
+ }
+
+ if (i != 0) {
+ if (adc_data > adc_max)
+ adc_max = adc_data;
+ else if (adc_data < adc_min)
+ adc_min = adc_data;
+ } else {
+ adc_max = adc_data;
+ adc_min = adc_data;
+ }
+ adc_total += adc_data;
+ }
+
+ return (adc_total - adc_max - adc_min) / (JACK_SAMPLE_SIZE - 2);
+}
+
+static void determine_jack_type(struct wm1811_machine_priv *wm1811)
+{
+ struct jack_zone *zones = wm1811->zones;
+ struct snd_soc_codec *codec = wm1811->codec;
+ int size = wm1811->num_zones;
+ int count[MAX_ZONE_LIMIT] = {0};
+ int adc;
+ int i;
+
+ /* set mic bias to enable adc */
+ while (snd_soc_read(codec, WM1811_JACKDET_CTRL) & WM1811_JACKDET_LVL) {
+ adc = jack_get_adc_data(wm1811->padc);
+
+ pr_info("%s: adc = %d\n", __func__, adc);
+
+ if (adc < 0)
+ break;
+
+ /* determine the type of headset based on the
+ * adc value. An adc value can fall in various
+ * ranges or zones. Within some ranges, the type
+ * can be returned immediately. Within others, the
+ * value is considered unstable and we need to sample
+ * a few more types (up to the limit determined by
+ * the range) before we return the type for that range.
+ */
+ for (i = 0; i < size; i++) {
+ if (adc <= zones[i].adc_high) {
+ if (++count[i] > zones[i].check_count) {
+ if (recheck_jack == true && i == 4) {
+ pr_info("%s : something wrong connection!\n",
+ __func__);
+
+ recheck_jack = false;
+ return;
+ }
+ jack_set_type(wm1811,
+ zones[i].jack_type);
+ return;
+ }
+ msleep(zones[i].delay_ms);
+ break;
+ }
+ }
+ }
+
+ recheck_jack = false;
+ /* jack removed before detection complete */
+ pr_debug("%s : jack removed before detection complete\n", __func__);
+}
+
+static void jack_set_type(struct wm1811_machine_priv *wm1811, int jack_type)
{
- struct wm1811_machine_priv *wm1811 = data;
struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(wm1811->codec);
- int report;
- int reg;
- bool present;
- /*
- * If the jack is inserted abnormally,
- * The variable puts back to its previous status.
- */
- if (!wm1811->get_g_det_value_f) {
- dev_err(wm1811->codec->dev, "Do not use the ground detection\n");
+ if (jack_type == SEC_HEADSET_4POLE) {
+ dev_info(wm1811->codec->dev, "Detected microphone\n");
+
+ wm8994->mic_detecting = false;
+ wm8994->jack_mic = true;
+
+ t0_micd_set_rate(wm1811->codec);
+
+ snd_soc_jack_report(wm8994->micdet[0].jack, SND_JACK_HEADSET,
+ SND_JACK_HEADSET);
+
+ snd_soc_update_bits(wm1811->codec, WM8958_MIC_DETECT_1,
+ WM8958_MICD_ENA, 1);
} else {
- if (wm1811->get_g_det_value_f()) {
- dev_info(wm1811->codec->dev, "The jack is inserted abnormally\n");
+ dev_info(wm1811->codec->dev, "Detected headphone\n");
+ wm8994->mic_detecting = false;
+
+ t0_micd_set_rate(wm1811->codec);
- wm8994->mic_detecting = false;
+ snd_soc_jack_report(wm8994->micdet[0].jack, SND_JACK_HEADPHONE,
+ SND_JACK_HEADSET);
+
+ /* If we have jackdet that will detect removal */
+ if (wm8994->jackdet) {
+ snd_soc_update_bits(wm1811->codec, WM8958_MIC_DETECT_1,
+ WM8958_MICD_ENA, 0);
+
+ if (wm8994->active_refcount) {
+ snd_soc_update_bits(wm1811->codec,
+ WM8994_ANTIPOP_2,
+ WM1811_JACKDET_MODE_MASK,
+ WM1811_JACKDET_MODE_AUDIO);
+ }
+
+ if (wm8994->pdata->jd_ext_cap) {
+ mutex_lock(&wm1811->codec->mutex);
+ snd_soc_dapm_disable_pin(&wm1811->codec->dapm,
+ "MICBIAS2");
+ snd_soc_dapm_sync(&wm1811->codec->dapm);
+ mutex_unlock(&wm1811->codec->mutex);
+ }
}
}
+}
+
+static void t0_micdet(void *data)
+{
+ struct wm1811_machine_priv *wm1811 = data;
+ struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(wm1811->codec);
+
+ struct snd_soc_codec *codec = wm1811->codec;
+
+ pr_info("%s: detected jack\n", __func__);
+ wm8994->mic_detecting = true;
wake_lock_timeout(&wm1811->jackdet_wake_lock, 5 * HZ);
+ snd_soc_update_bits(codec, WM8958_MICBIAS2,
+ WM8958_MICB2_MODE, 0);
+
+ /* Apply delay time(150ms) to remove pop noise
+ * during to enable micbias */
+ msleep(150);
+
+ determine_jack_type(wm1811);
+ }
+#endif
+
+static void t0_mic_id(void *data, u16 status)
+{
+ struct wm1811_machine_priv *wm1811 = data;
+ struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(wm1811->codec);
+
+ pr_info("%s: detected jack\n", __func__);
+ wake_lock_timeout(&wm1811->jackdet_wake_lock, 5 * HZ);
+
/* Either nothing present or just starting detection */
if (!(status & WM8958_MICD_STS)) {
if (!wm8994->jackdet) {
@@ -570,41 +754,6 @@ static void t0_micdet(u16 status, void *data)
}
}
}
-
- /* Report short circuit as a button */
- if (wm8994->jack_mic) {
- report = 0;
- if (status & WM1811_JACKDET_BTN0)
- report |= SND_JACK_BTN_0;
-
- if (status & WM1811_JACKDET_BTN1)
- report |= SND_JACK_BTN_1;
-
- if (status & WM1811_JACKDET_BTN2)
- report |= SND_JACK_BTN_2;
-
- reg = snd_soc_read(wm1811->codec, WM1811_JACKDET_CTRL);
- if (reg < 0) {
- pr_err("%s: Failed to read jack status: %d\n",
- __func__, reg);
- return;
- }
-
- pr_err("%s: JACKDET %x\n", __func__, reg);
-
- present = reg & WM1811_JACKDET_LVL;
-
- if (!present) {
- pr_err("%s: button is ignored!!!\n", __func__);
- return;
- }
-
- dev_info(wm1811->codec->dev, "Detected Button: %08x (%08X)\n",
- report, status);
-
- snd_soc_jack_report(wm8994->micdet[0].jack, report,
- wm8994->btn_mask);
- }
}
static int t0_wm1811_aif1_hw_params(struct snd_pcm_substream *substream,
@@ -671,6 +820,7 @@ static int t0_wm1811_aif2_hw_params(struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params)
{
struct snd_soc_pcm_runtime *rtd = substream->private_data;
+ struct snd_soc_codec *codec = rtd->codec;
struct snd_soc_dai *codec_dai = rtd->codec_dai;
int ret;
int prate;
@@ -730,6 +880,14 @@ static int t0_wm1811_aif2_hw_params(struct snd_pcm_substream *substream,
if (ret < 0)
dev_err(codec_dai->dev, "Unable to switch to FLL2: %d\n", ret);
+ if (!(snd_soc_read(codec, WM8994_INTERRUPT_RAW_STATUS_2)
+ & WM8994_FLL2_LOCK_STS)) {
+ dev_info(codec_dai->dev, "%s: use mclk1 for FLL2\n", __func__);
+ ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL2,
+ WM8994_FLL_SRC_MCLK1,
+ MIDAS_DEFAULT_MCLK1, prate * 256);
+ }
+
dev_info(codec_dai->dev, "%s --\n", __func__);
return 0;
}
@@ -1017,41 +1175,7 @@ static ssize_t reselect_jack_show(struct device *dev,
static ssize_t reselect_jack_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t size)
{
- struct snd_soc_codec *codec = dev_get_drvdata(dev);
- struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
- int reg = 0;
-
- reg = snd_soc_read(codec, WM8958_MIC_DETECT_3);
- if (reg == 0x402) {
- dev_info(codec->dev, "Detected open circuit\n");
-
- snd_soc_update_bits(codec, WM8958_MICBIAS2,
- WM8958_MICB2_DISCH, WM8958_MICB2_DISCH);
- /* Enable debounce while removed */
- snd_soc_update_bits(codec, WM1811_JACKDET_CTRL,
- WM1811_JACKDET_DB, WM1811_JACKDET_DB);
-
- wm8994->mic_detecting = false;
- wm8994->jack_mic = false;
- snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
- WM8958_MICD_ENA, 0);
-
- if (wm8994->active_refcount) {
- snd_soc_update_bits(codec,
- WM8994_ANTIPOP_2,
- WM1811_JACKDET_MODE_MASK,
- WM1811_JACKDET_MODE_AUDIO);
- } else {
- snd_soc_update_bits(codec,
- WM8994_ANTIPOP_2,
- WM1811_JACKDET_MODE_MASK,
- WM1811_JACKDET_MODE_JACK);
- }
-
- snd_soc_jack_report(wm8994->micdet[0].jack, 0,
- SND_JACK_MECHANICAL | SND_JACK_HEADSET |
- wm8994->btn_mask);
- }
+ pr_info("%s : operate nothing\n", __func__);
return size;
}
@@ -1079,6 +1203,8 @@ static int t0_wm1811_init_paiftx(struct snd_soc_pcm_runtime *rtd)
const struct exynos_sound_platform_data *sound_pdata;
int ret;
+ sound_pdata = exynos_sound_get_platform_data();
+
midas_snd_set_mclk(true, false);
rtd->codec_dai->driver->playback.channels_max =
@@ -1154,12 +1280,12 @@ static int t0_wm1811_init_paiftx(struct snd_soc_pcm_runtime *rtd)
dev_err(codec->dev, "Failed to set KEY_MEDIA: %d\n", ret);
ret = snd_jack_set_key(wm1811->jack.jack, SND_JACK_BTN_1,
- KEY_VOLUMEDOWN);
+ KEY_VOLUMEUP);
if (ret < 0)
dev_err(codec->dev, "Failed to set KEY_VOLUMEUP: %d\n", ret);
ret = snd_jack_set_key(wm1811->jack.jack, SND_JACK_BTN_2,
- KEY_VOLUMEUP);
+ KEY_VOLUMEDOWN);
if (ret < 0)
dev_err(codec->dev, "Failed to set KEY_VOLUMEDOWN: %d\n", ret);
@@ -1167,9 +1293,18 @@ static int t0_wm1811_init_paiftx(struct snd_soc_pcm_runtime *rtd)
if (wm8994->revision > 1) {
dev_info(codec->dev, "wm1811: Rev %c support mic detection\n",
'A' + wm8994->revision);
- ret = wm8958_mic_detect(codec, &wm1811->jack, t0_micdet,
- wm1811);
-
+#ifdef CONFIG_USE_ADC_DET
+ if (sound_pdata->use_jackdet_type) {
+ ret = wm8958_mic_detect(codec, &wm1811->jack,
+ t0_micdet, wm1811, NULL, NULL);
+ } else {
+ ret = wm8958_mic_detect(codec, &wm1811->jack, NULL,
+ NULL, t0_mic_id, wm1811);
+ }
+#else
+ ret = wm8958_mic_detect(codec, &wm1811->jack, NULL,
+ NULL, t0_mic_id, wm1811);
+#endif
if (ret < 0)
dev_err(codec->dev, "Failed start detection: %d\n",
ret);
@@ -1216,6 +1351,10 @@ static int t0_wm1811_init_paiftx(struct snd_soc_pcm_runtime *rtd)
wm8994->hubs.dcs_codes_r = sound_pdata->dcs_offset_r;
}
+#ifdef CONFIG_USE_ADC_DET
+ pr_info("%s: register adc client\n", __func__);
+ wm1811->padc = s3c_adc_register(t0_snd_device, NULL, NULL, 0);
+#endif
return snd_soc_dapm_sync(&codec->dapm);
}
@@ -1415,13 +1554,11 @@ static struct snd_soc_card t0_card = {
.resume_post = t0_card_resume_post
};
-static struct platform_device *t0_snd_device;
-
static void t0_jackdet_set_mode(struct snd_soc_codec *codec, u16 mode)
{
struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
- if (!wm8994->jackdet || !wm8994->jack_cb)
+ if (!wm8994->jackdet || !wm8994->micdet[0].jack)
return;
if (wm8994->active_refcount)
@@ -1529,6 +1666,15 @@ static int __init t0_audio_init(void)
goto err_out_free;
}
+#ifdef CONFIG_USE_ADC_DET
+ if (sound_pdata->zones) {
+ wm1811->zones = sound_pdata->zones;
+ wm1811->num_zones = sound_pdata->num_zones;
+ }
+ pr_info("%s:use_jackdet_type = %d\n", __func__,
+ sound_pdata->use_jackdet_type);
+ wm1811->use_jackdet_type = sound_pdata->use_jackdet_type;
+#endif
if (sound_pdata->set_lineout_switch)
wm1811->lineout_switch_f = sound_pdata->set_lineout_switch;
@@ -1572,6 +1718,10 @@ static void __exit t0_audio_exit(void)
{
struct snd_soc_card *card = &t0_card;
struct wm1811_machine_priv *wm1811 = snd_soc_card_get_drvdata(card);
+
+#ifdef CONFIG_USE_ADC_DET
+ s3c_adc_release(wm1811->padc);
+#endif
platform_device_unregister(t0_snd_device);
kfree(wm1811);
}
diff --git a/sound/soc/samsung/t0duos_wm1811.c b/sound/soc/samsung/t0duos_wm1811.c
index dfa3001..4fa3b31 100644
--- a/sound/soc/samsung/t0duos_wm1811.c
+++ b/sound/soc/samsung/t0duos_wm1811.c
@@ -63,6 +63,11 @@
#define WM1811_MIC_IRQ_NUM (IRQ_BOARD_CODEC_START + WM8994_IRQ_MIC1_DET)
#define WM1811_JACKDET_IRQ_NUM (IRQ_BOARD_CODEC_START + WM8994_IRQ_GPIO(6))
+#define MIC_DISABLE 0
+#define MIC_ENABLE 1
+#define MIC_FORCE_DISABLE 2
+#define MIC_FORCE_ENABLE 3
+
static struct wm8958_micd_rate t0_det_rates[] = {
{ MIDAS_DEFAULT_MCLK2, true, 0, 0 },
{ MIDAS_DEFAULT_MCLK2, false, 0, 0 },
@@ -82,16 +87,20 @@ const char *aif2_mode_text[] = {
"Slave", "Master"
};
-static int input_clamp;
-const char *input_clamp_text[] = {
+const char *switch_mode_text[] = {
"Off", "On"
};
-static int lineout_mode;
-const char *lineout_mode_text[] = {
- "Off", "On"
+const char *mic_bias_mode_text[] = {
+ "Disable", "Force Disable", "Enable", "Force Enable"
};
+static int input_clamp;
+static int lineout_mode;
+static int aif2_digital_mute;
+static int main_mic_bias_mode;
+static int sub_mic_bias_mode;
+
#if defined(CONFIG_SND_DUOS_MODEM_SWITCH)
static int modem_mode;
const char *modem_mode_text[] = {
@@ -155,8 +164,20 @@ static int set_modem_mode(struct snd_kcontrol *kcontrol,
}
#endif
-static const struct soc_enum lineout_mode_enum[] = {
- SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(lineout_mode_text), lineout_mode_text),
+static const struct soc_enum switch_mode_enum[] = {
+ SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(switch_mode_text), switch_mode_text),
+};
+
+static const struct soc_enum aif2_mode_enum[] = {
+ SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(aif2_mode_text), aif2_mode_text),
+};
+
+static const struct soc_enum mic_bias_mode_enum[] = {
+ SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(mic_bias_mode_text), mic_bias_mode_text),
+};
+
+static const struct soc_enum sub_bias_mode_enum[] = {
+ SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(mic_bias_mode_text), mic_bias_mode_text),
};
static int get_lineout_mode(struct snd_kcontrol *kcontrol,
@@ -186,17 +207,10 @@ static int set_lineout_mode(struct snd_kcontrol *kcontrol,
}
dev_info(codec->dev, "set lineout mode : %s\n",
- lineout_mode_text[lineout_mode]);
+ switch_mode_text[lineout_mode]);
return 0;
}
-static const struct soc_enum aif2_mode_enum[] = {
- SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(aif2_mode_text), aif2_mode_text),
-};
-
-static const struct soc_enum input_clamp_enum[] = {
- SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(input_clamp_text), input_clamp_text),
-};
static int get_aif2_mode(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
@@ -240,11 +254,161 @@ static int set_input_clamp(struct snd_kcontrol *kcontrol,
snd_soc_update_bits(codec, WM8994_INPUT_MIXER_1,
WM8994_INPUTS_CLAMP, 0);
}
- pr_info("set fm input_clamp : %s\n", input_clamp_text[input_clamp]);
+ pr_info("set fm input_clamp : %s\n", switch_mode_text[input_clamp]);
+
+ return 0;
+}
+
+static int get_aif2_mute_status(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ ucontrol->value.integer.value[0] = aif2_digital_mute;
+ return 0;
+}
+
+static int set_aif2_mute_status(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+ int reg;
+
+ aif2_digital_mute = ucontrol->value.integer.value[0];
+
+ if (snd_soc_read(codec, WM8994_POWER_MANAGEMENT_6)
+ & WM8994_AIF2_DACDAT_SRC)
+ aif2_digital_mute = 0;
+
+ if (aif2_digital_mute)
+ reg = WM8994_AIF1DAC1_MUTE;
+ else
+ reg = 0;
+
+ snd_soc_update_bits(codec, WM8994_AIF2_DAC_FILTERS_1,
+ WM8994_AIF1DAC1_MUTE, reg);
+
+ pr_info("set aif2_digital_mute : %s\n",
+ switch_mode_text[aif2_digital_mute]);
+
+ return 0;
+}
+
+static int get_sub_mic_bias_mode(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ ucontrol->value.integer.value[0] = sub_mic_bias_mode;
+ return 0;
+}
+
+static int set_sub_mic_bias_mode(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+ struct wm1811_machine_priv *wm1811
+ = snd_soc_card_get_drvdata(codec->card);
+ int status = 0;
+
+ status = ucontrol->value.integer.value[0];
+
+ switch (status) {
+ case MIC_FORCE_ENABLE:
+ sub_mic_bias_mode = status;
+ snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_1,
+ WM8994_MICB1_ENA, WM8994_MICB1_ENA);
+
+ if (wm1811->set_sub_mic_f)
+ wm1811->set_sub_mic_f(1);
+ break;
+ case MIC_ENABLE:
+ snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_1,
+ WM8994_MICB1_ENA, WM8994_MICB1_ENA);
+ if (wm1811->set_sub_mic_f)
+ wm1811->set_sub_mic_f(1);
+ if (sub_mic_bias_mode != MIC_FORCE_ENABLE)
+ msleep(100);
+ break;
+ case MIC_FORCE_DISABLE:
+ sub_mic_bias_mode = status;
+ snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_1,
+ WM8994_MICB1_ENA, 0);
+
+ if (wm1811->set_sub_mic_f)
+ wm1811->set_sub_mic_f(0);
+ break;
+ case MIC_DISABLE:
+ if (sub_mic_bias_mode != MIC_FORCE_ENABLE) {
+ snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_1,
+ WM8994_MICB1_ENA, 0);
+ if (wm1811->set_sub_mic_f)
+ wm1811->set_sub_mic_f(0);
+ } else
+ dev_info(codec->dev,
+ "SKIP submic disable=%d\n", status);
+ break;
+ default:
+ break;
+ }
+
+ dev_info(codec->dev, "sub_mic_bias_mod=%d: status=%d\n",
+ sub_mic_bias_mode, status);
return 0;
+
}
+static int get_main_mic_bias_mode(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ ucontrol->value.integer.value[0] = main_mic_bias_mode;
+ return 0;
+}
+
+static int set_main_mic_bias_mode(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+ struct wm1811_machine_priv *wm1811
+ = snd_soc_card_get_drvdata(codec->card);
+ int status = 0;
+
+ status = ucontrol->value.integer.value[0];
+
+ switch (status) {
+ case MIC_FORCE_ENABLE:
+ main_mic_bias_mode = status;
+
+ if (wm1811->set_main_mic_f)
+ wm1811->set_main_mic_f(1);
+ break;
+ case MIC_ENABLE:
+ if (wm1811->set_main_mic_f)
+ wm1811->set_main_mic_f(1);
+ if (main_mic_bias_mode != MIC_FORCE_ENABLE)
+ msleep(100);
+ break;
+ case MIC_FORCE_DISABLE:
+ main_mic_bias_mode = status;
+
+ if (wm1811->set_main_mic_f)
+ wm1811->set_main_mic_f(0);
+ break;
+ case MIC_DISABLE:
+ if (main_mic_bias_mode != MIC_FORCE_ENABLE) {
+ if (wm1811->set_main_mic_f)
+ wm1811->set_main_mic_f(0);
+ } else
+ dev_info(codec->dev,
+ "SKIP mainmic disable=%d\n", status);
+ break;
+ default:
+ break;
+ }
+
+ dev_info(codec->dev, "main_mic_bias_mod=%d: status=%d\n",
+ main_mic_bias_mode, status);
+
+ return 0;
+
+}
static int set_ext_micbias(struct snd_soc_dapm_widget *w,
struct snd_kcontrol *kcontrol, int event)
@@ -361,11 +525,13 @@ static void t0_micd_set_rate(struct snd_soc_codec *codec)
WM8958_MICD_RATE_MASK, val);
}
-static void t0_micdet(u16 status, void *data)
+static void t0_micdet(void *data, u16 status)
{
struct wm1811_machine_priv *wm1811 = data;
struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(wm1811->codec);
int report;
+ int reg;
+ bool present;
/*
* If the jack is inserted abnormally,
@@ -463,6 +629,22 @@ static void t0_micdet(u16 status, void *data)
if (status & WM1811_JACKDET_BTN2)
report |= SND_JACK_BTN_2;
+ reg = snd_soc_read(wm1811->codec, WM1811_JACKDET_CTRL);
+ if (reg < 0) {
+ pr_err("%s: Failed to read jack status: %d\n",
+ __func__, reg);
+ return;
+ }
+
+ pr_err("%s: JACKDET %x\n", __func__, reg);
+
+ present = reg & WM1811_JACKDET_LVL;
+
+ if (!present) {
+ pr_err("%s: button is ignored!!!\n", __func__);
+ return;
+ }
+
dev_info(wm1811->codec->dev, "Detected Button: %08x (%08X)\n",
report, status);
@@ -609,7 +791,8 @@ static int t0_wm1811_aif2_hw_params(struct snd_pcm_substream *substream,
return -EINVAL;
}
-#if defined(CONFIG_MACH_T0_CHN_CU_DUOS)
+#if defined(CONFIG_MACH_T0_CHN_CU_DUOS) \
+ || defined(CONFIG_MACH_T0_CHN_OPEN_DUOS)
if (modem_mode == 1)
bclk = 2048000;
#endif
@@ -727,11 +910,21 @@ static const struct snd_kcontrol_new t0_controls[] = {
SOC_ENUM_EXT("AIF2 Mode", aif2_mode_enum[0],
get_aif2_mode, set_aif2_mode),
- SOC_ENUM_EXT("Input Clamp", input_clamp_enum[0],
+ SOC_ENUM_EXT("Input Clamp", switch_mode_enum[0],
get_input_clamp, set_input_clamp),
- SOC_ENUM_EXT("LineoutSwitch Mode", lineout_mode_enum[0],
+ SOC_ENUM_EXT("LineoutSwitch Mode", switch_mode_enum[0],
get_lineout_mode, set_lineout_mode),
+
+ SOC_ENUM_EXT("MainMicBias Mode", mic_bias_mode_enum[0],
+ get_main_mic_bias_mode, set_main_mic_bias_mode),
+
+ SOC_ENUM_EXT("SubMicBias Mode", mic_bias_mode_enum[0],
+ get_sub_mic_bias_mode, set_sub_mic_bias_mode),
+
+ SOC_ENUM_EXT("AIF2 digital mute", switch_mode_enum[0],
+ get_aif2_mute_status, set_aif2_mute_status),
+
#if defined(CONFIG_SND_DUOS_MODEM_SWITCH)
SOC_ENUM_EXT("ModemSwitch Mode", modem_mode_enum[0],
get_modem_mode, set_modem_mode),
@@ -746,8 +939,8 @@ const struct snd_soc_dapm_widget t0_dapm_widgets[] = {
SND_SOC_DAPM_LINE("HDMI", NULL),
SND_SOC_DAPM_MIC("Headset Mic", NULL),
- SND_SOC_DAPM_MIC("Main Mic", set_ext_micbias),
- SND_SOC_DAPM_MIC("Sub Mic", set_ext_submicbias),
+ SND_SOC_DAPM_MIC("Main Mic", NULL),
+ SND_SOC_DAPM_MIC("Sub Mic", NULL),
SND_SOC_DAPM_LINE("FM In", NULL),
SND_SOC_DAPM_INPUT("S5P RP"),
@@ -772,9 +965,8 @@ const struct snd_soc_dapm_route t0_dapm_routes[] = {
{ "IN2LP:VXRN", NULL, "Main Mic" },
{ "IN2LN", NULL, "Main Mic" },
- { "IN1RP", NULL, "MICBIAS1" },
- { "IN1RN", NULL, "MICBIAS1" },
- { "MICBIAS1", NULL, "Sub Mic" },
+ { "IN1RP", NULL, "Sub Mic" },
+ { "IN1RN", NULL, "Sub Mic" },
{ "IN1LP", NULL, "MICBIAS2" },
{ "MICBIAS2", NULL, "Headset Mic" },
@@ -919,41 +1111,7 @@ static ssize_t reselect_jack_show(struct device *dev,
static ssize_t reselect_jack_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t size)
{
- struct snd_soc_codec *codec = dev_get_drvdata(dev);
- struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
- int reg = 0;
-
- reg = snd_soc_read(codec, WM8958_MIC_DETECT_3);
- if (reg == 0x402) {
- dev_info(codec->dev, "Detected open circuit\n");
-
- snd_soc_update_bits(codec, WM8958_MICBIAS2,
- WM8958_MICB2_DISCH, WM8958_MICB2_DISCH);
- /* Enable debounce while removed */
- snd_soc_update_bits(codec, WM1811_JACKDET_CTRL,
- WM1811_JACKDET_DB, WM1811_JACKDET_DB);
-
- wm8994->mic_detecting = false;
- wm8994->jack_mic = false;
- snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
- WM8958_MICD_ENA, 0);
-
- if (wm8994->active_refcount) {
- snd_soc_update_bits(codec,
- WM8994_ANTIPOP_2,
- WM1811_JACKDET_MODE_MASK,
- WM1811_JACKDET_MODE_AUDIO);
- } else {
- snd_soc_update_bits(codec,
- WM8994_ANTIPOP_2,
- WM1811_JACKDET_MODE_MASK,
- WM1811_JACKDET_MODE_JACK);
- }
-
- snd_soc_jack_report(wm8994->micdet[0].jack, 0,
- SND_JACK_MECHANICAL | SND_JACK_HEADSET |
- wm8994->btn_mask);
- }
+ pr_info("%s : operate nothing\n", __func__);
return size;
}
@@ -978,6 +1136,7 @@ static int t0_wm1811_init_paiftx(struct snd_soc_pcm_runtime *rtd)
struct snd_soc_dai *aif1_dai = rtd->codec_dai;
struct wm8994 *control = codec->control_data;
struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
+ const struct exynos_sound_platform_data *sound_pdata;
int ret;
midas_snd_set_mclk(true, false);
@@ -1068,8 +1227,8 @@ static int t0_wm1811_init_paiftx(struct snd_soc_pcm_runtime *rtd)
if (wm8994->revision > 1) {
dev_info(codec->dev, "wm1811: Rev %c support mic detection\n",
'A' + wm8994->revision);
- ret = wm8958_mic_detect(codec, &wm1811->jack, t0_micdet,
- wm1811);
+ ret = wm8958_mic_detect(codec, &wm1811->jack, NULL,
+ NULL, t0_micdet, wm1811);
if (ret < 0)
dev_err(codec->dev, "Failed start detection: %d\n",
@@ -1110,6 +1269,13 @@ static int t0_wm1811_init_paiftx(struct snd_soc_pcm_runtime *rtd)
dev_attr_reselect_jack.attr.name);
#endif /* CONFIG_SEC_DEV_JACK */
+ sound_pdata = exynos_sound_get_platform_data();
+
+ if (sound_pdata) {
+ wm8994->hubs.dcs_codes_l = sound_pdata->dcs_offset_l;
+ wm8994->hubs.dcs_codes_r = sound_pdata->dcs_offset_r;
+ }
+
return snd_soc_dapm_sync(&codec->dapm);
}
@@ -1315,7 +1481,7 @@ static void t0_jackdet_set_mode(struct snd_soc_codec *codec, u16 mode)
{
struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
- if (!wm8994->jackdet || !wm8994->jack_cb)
+ if (!wm8994->jackdet || !wm8994->micdet[0].jack)
return;
if (wm8994->active_refcount)
diff --git a/sound/soc/samsung/tab3_wm1811.c b/sound/soc/samsung/tab3_wm1811.c
new file mode 100644
index 0000000..345d781
--- /dev/null
+++ b/sound/soc/samsung/tab3_wm1811.c
@@ -0,0 +1,1406 @@
+/*
+ * tab3_wm1811.c
+ *
+ * Copyright (c) 2011 Samsung Electronics Co. Ltd
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ */
+#include <linux/platform_device.h>
+#include <linux/clk.h>
+#include <linux/io.h>
+#include <linux/gpio.h>
+#include <linux/delay.h>
+#include <linux/slab.h>
+#include <linux/workqueue.h>
+#include <linux/input.h>
+#include <linux/wakelock.h>
+#include <linux/suspend.h>
+
+#include <sound/soc.h>
+#include <sound/soc-dapm.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include <sound/jack.h>
+
+#include <mach/regs-clock.h>
+#include <mach/pmu.h>
+#include <mach/midas-sound.h>
+
+#include <linux/mfd/wm8994/core.h>
+#include <linux/mfd/wm8994/registers.h>
+#include <linux/mfd/wm8994/pdata.h>
+#include <linux/mfd/wm8994/gpio.h>
+
+#if defined(CONFIG_SND_USE_MUIC_SWITCH)
+#include <linux/mfd/max77693-private.h>
+#endif
+
+
+#include "i2s.h"
+#include "s3c-i2s-v2.h"
+#include "../codecs/wm8994.h"
+
+
+#define MIDAS_DEFAULT_MCLK1 24000000
+#define MIDAS_DEFAULT_MCLK2 32768
+#define MIDAS_DEFAULT_SYNC_CLK 11289600
+
+#define WM1811_JACKDET_MODE_NONE 0x0000
+#define WM1811_JACKDET_MODE_JACK 0x0100
+#define WM1811_JACKDET_MODE_MIC 0x0080
+#define WM1811_JACKDET_MODE_AUDIO 0x0180
+
+#define WM1811_JACKDET_BTN0 0x04
+#define WM1811_JACKDET_BTN1 0x10
+#define WM1811_JACKDET_BTN2 0x08
+
+
+static struct wm8958_micd_rate tab3_det_rates[] = {
+ { MIDAS_DEFAULT_MCLK2, true, 0, 0 },
+ { MIDAS_DEFAULT_MCLK2, false, 0, 0 },
+ { MIDAS_DEFAULT_SYNC_CLK, true, 7, 7 },
+ { MIDAS_DEFAULT_SYNC_CLK, false, 7, 7 },
+};
+
+static struct wm8958_micd_rate tab3_jackdet_rates[] = {
+ { MIDAS_DEFAULT_MCLK2, true, 0, 0 },
+ { MIDAS_DEFAULT_MCLK2, false, 0, 0 },
+ { MIDAS_DEFAULT_SYNC_CLK, true, 12, 12 },
+ { MIDAS_DEFAULT_SYNC_CLK, false, 7, 8 },
+};
+
+static int aif2_mode;
+const char *aif2_mode_text[] = {
+ "Slave", "Master"
+};
+
+static int kpcs_mode = 2;
+const char *kpcs_mode_text[] = {
+ "Off", "On"
+};
+
+static int input_clamp;
+const char *input_clamp_text[] = {
+ "Off", "On"
+};
+
+static int lineout_mode;
+const char *lineout_mode_text[] = {
+ "Off", "On"
+};
+
+static int aif2_digital_mute;
+const char *switch_mode_text[] = {
+ "Off", "On"
+};
+
+#ifndef CONFIG_SEC_DEV_JACK
+/* To support PBA function test */
+static struct class *jack_class;
+static struct device *jack_dev;
+#endif
+
+struct wm1811_machine_priv {
+ struct snd_soc_jack jack;
+ struct snd_soc_codec *codec;
+ struct delayed_work mic_work;
+ struct wake_lock jackdet_wake_lock;
+};
+
+static void tab3_gpio_init(void)
+{
+#ifdef CONFIG_SND_USE_LINEOUT_SWITCH
+ int err;
+ err = gpio_request(GPIO_LINEOUT_EN, "LINEOUT_EN");
+ if (err) {
+ pr_err(KERN_ERR "LINEOUT_EN GPIO set error!\n");
+ return;
+ }
+ gpio_direction_output(GPIO_LINEOUT_EN, 1);
+ gpio_set_value(GPIO_LINEOUT_EN, 0);
+ gpio_free(GPIO_LINEOUT_EN);
+#endif
+}
+
+static const struct soc_enum lineout_mode_enum[] = {
+ SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(lineout_mode_text), lineout_mode_text),
+};
+
+static int get_lineout_mode(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ ucontrol->value.integer.value[0] = lineout_mode;
+ return 0;
+}
+
+static int set_lineout_mode(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+
+ lineout_mode = ucontrol->value.integer.value[0];
+ dev_dbg(codec->dev, "set lineout mode : %s\n",
+ lineout_mode_text[lineout_mode]);
+ return 0;
+
+}
+static const struct soc_enum aif2_mode_enum[] = {
+ SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(aif2_mode_text), aif2_mode_text),
+};
+
+static const struct soc_enum kpcs_mode_enum[] = {
+ SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(kpcs_mode_text), kpcs_mode_text),
+};
+
+static const struct soc_enum input_clamp_enum[] = {
+ SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(input_clamp_text), input_clamp_text),
+};
+
+static const struct soc_enum switch_mode_enum[] = {
+ SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(switch_mode_text), switch_mode_text),
+};
+
+static int get_aif2_mode(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ ucontrol->value.integer.value[0] = aif2_mode;
+ return 0;
+}
+
+static int set_aif2_mode(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ if (aif2_mode == ucontrol->value.integer.value[0])
+ return 0;
+
+ aif2_mode = ucontrol->value.integer.value[0];
+
+ pr_info("set aif2 mode : %s\n", aif2_mode_text[aif2_mode]);
+
+ return 0;
+}
+
+static int get_kpcs_mode(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ ucontrol->value.integer.value[0] = kpcs_mode;
+ return 0;
+}
+
+static int set_kpcs_mode(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+
+ kpcs_mode = ucontrol->value.integer.value[0];
+
+ pr_info("set kpcs mode : %d\n", kpcs_mode);
+
+ return 0;
+}
+
+static int get_input_clamp(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ ucontrol->value.integer.value[0] = input_clamp;
+ return 0;
+}
+
+static int set_input_clamp(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+
+ input_clamp = ucontrol->value.integer.value[0];
+
+ if (input_clamp) {
+ snd_soc_update_bits(codec, WM8994_INPUT_MIXER_1,
+ WM8994_INPUTS_CLAMP, WM8994_INPUTS_CLAMP);
+ msleep(100);
+ } else {
+ snd_soc_update_bits(codec, WM8994_INPUT_MIXER_1,
+ WM8994_INPUTS_CLAMP, 0);
+ }
+ pr_info("set fm input_clamp : %s\n", input_clamp_text[input_clamp]);
+
+ return 0;
+}
+
+static int get_aif2_mute_status(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ ucontrol->value.integer.value[0] = aif2_digital_mute;
+ return 0;
+}
+
+static int set_aif2_mute_status(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+ int reg;
+
+ aif2_digital_mute = ucontrol->value.integer.value[0];
+
+ if (snd_soc_read(codec, WM8994_POWER_MANAGEMENT_6)
+ & WM8994_AIF2_DACDAT_SRC)
+ aif2_digital_mute = 0;
+
+ if (aif2_digital_mute)
+ reg = WM8994_AIF1DAC1_MUTE;
+ else
+ reg = 0;
+
+ snd_soc_update_bits(codec, WM8994_AIF2_DAC_FILTERS_1,
+ WM8994_AIF1DAC1_MUTE, reg);
+
+ pr_info("set aif2_digital_mute : %s\n",
+ switch_mode_text[aif2_digital_mute]);
+
+ return 0;
+}
+
+static int tab3_main_micbias(struct snd_soc_dapm_widget *w,
+ struct snd_kcontrol *kcontrol, int event)
+{
+ struct snd_soc_codec *codec = w->codec;
+
+ dev_dbg(codec->dev, "%s event is %02X", w->name, event);
+
+ switch (event) {
+ case SND_SOC_DAPM_PRE_PMU:
+ msleep(100);
+ break;
+ case SND_SOC_DAPM_POST_PMD:
+ break;
+ }
+ return 0;
+}
+
+static int tab3_sub_micbias(struct snd_soc_dapm_widget *w,
+ struct snd_kcontrol *kcontrol, int event)
+{
+ struct snd_soc_codec *codec = w->codec;
+
+ dev_dbg(codec->dev, "%s event is %02X", w->name, event);
+
+ switch (event) {
+ case SND_SOC_DAPM_PRE_PMU:
+ msleep(100);
+ break;
+ case SND_SOC_DAPM_POST_PMD:
+ break;
+ }
+ return 0;
+}
+
+static int tab3_ext_micbias(struct snd_soc_dapm_widget *w,
+ struct snd_kcontrol *kcontrol, int event)
+{
+ struct snd_soc_codec *codec = w->codec;
+
+ dev_dbg(codec->dev, "%s event is %02X", w->name, event);
+
+#ifdef CONFIG_SND_SOC_USE_EXTERNAL_MIC_BIAS
+ switch (event) {
+ case SND_SOC_DAPM_PRE_PMU:
+ gpio_set_value(GPIO_MIC_BIAS_EN, 1);
+ msleep(150);
+ break;
+ case SND_SOC_DAPM_POST_PMD:
+ gpio_set_value(GPIO_MIC_BIAS_EN, 0);
+ break;
+ }
+#endif
+ return 0;
+}
+
+static int tab3_bias1_event(struct snd_soc_dapm_widget *w,
+ struct snd_kcontrol *kcontrol, int event)
+{
+ struct snd_soc_codec *codec = w->codec;
+ int reg = 0;
+
+ reg = snd_soc_read(codec, WM8994_POWER_MANAGEMENT_1);
+ if (reg & WM8994_MICB2_ENA_MASK)
+ return 0;
+
+ switch (event) {
+ case SND_SOC_DAPM_POST_PMU:
+ pr_err("wm1811: %s event is %02X", w->name, event);
+
+ snd_soc_update_bits(codec, WM8994_INPUT_MIXER_1,
+ WM8994_INPUTS_CLAMP, WM8994_INPUTS_CLAMP);
+
+ msleep(200);
+
+ snd_soc_update_bits(codec, WM8994_INPUT_MIXER_1,
+ WM8994_INPUTS_CLAMP, 0);
+ break;
+ default:
+ break;
+ }
+
+ return 0;
+}
+
+static int tab3_bias2_event(struct snd_soc_dapm_widget *w,
+ struct snd_kcontrol *kcontrol, int event)
+{
+ struct snd_soc_codec *codec = w->codec;
+
+ switch (event) {
+ case SND_SOC_DAPM_POST_PMU:
+ pr_err("wm1811: %s event is %02X", w->name, event);
+
+ snd_soc_update_bits(codec, WM8994_INPUT_MIXER_1,
+ WM8994_INPUTS_CLAMP, WM8994_INPUTS_CLAMP);
+ msleep(200);
+
+ snd_soc_update_bits(codec, WM8994_INPUT_MIXER_1,
+ WM8994_INPUTS_CLAMP, 0);
+ break;
+ default:
+ break;
+ }
+
+ return 0;
+}
+
+/*
+ * tab3_ext_spkmode :
+ * For phone device have 1 external speaker
+ * should mix LR data in a speaker mixer (mono setting)
+ */
+static int tab3_ext_spkmode(struct snd_soc_dapm_widget *w,
+ struct snd_kcontrol *kcontrol, int event)
+{
+ int ret = 0;
+#ifndef CONFIG_SND_USE_STEREO_SPEAKER
+ struct snd_soc_codec *codec = w->codec;
+
+ ret = snd_soc_update_bits(codec, WM8994_SPKOUT_MIXERS,
+ WM8994_SPKMIXR_TO_SPKOUTL_MASK,
+ WM8994_SPKMIXR_TO_SPKOUTL);
+#endif
+ return ret;
+}
+
+static int tab3_lineout_switch(struct snd_soc_dapm_widget *w,
+ struct snd_kcontrol *kcontrol, int event)
+{
+ struct snd_soc_codec *codec = w->codec;
+
+ dev_dbg(codec->dev, "%s event is %02X", w->name, event);
+
+#if defined(CONFIG_SND_USE_MUIC_SWITCH)
+ switch (event) {
+ case SND_SOC_DAPM_POST_PMU:
+ msleep(150);
+ max77693_muic_set_audio_switch(1);
+ break;
+ case SND_SOC_DAPM_PRE_PMD:
+ max77693_muic_set_audio_switch(0);
+ break;
+ }
+#endif
+
+#ifdef CONFIG_SND_USE_LINEOUT_SWITCH
+ switch (event) {
+ case SND_SOC_DAPM_POST_PMU:
+ gpio_set_value(GPIO_LINEOUT_EN, 1);
+ break;
+ case SND_SOC_DAPM_PRE_PMD:
+ gpio_set_value(GPIO_LINEOUT_EN, 0);
+ break;
+ }
+#endif
+ return 0;
+}
+
+static void tab3_micd_set_rate(struct snd_soc_codec *codec)
+{
+ struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
+ int best, i, sysclk, val;
+ bool idle;
+ const struct wm8958_micd_rate *rates = NULL;
+ int num_rates = 0;
+
+ idle = !wm8994->jack_mic;
+
+ sysclk = snd_soc_read(codec, WM8994_CLOCKING_1);
+ if (sysclk & WM8994_SYSCLK_SRC)
+ sysclk = wm8994->aifclk[1];
+ else
+ sysclk = wm8994->aifclk[0];
+
+ if (wm8994->jackdet) {
+ rates = tab3_jackdet_rates;
+ num_rates = ARRAY_SIZE(tab3_jackdet_rates);
+ wm8994->pdata->micd_rates = tab3_jackdet_rates;
+ wm8994->pdata->num_micd_rates = num_rates;
+ } else {
+ rates = tab3_det_rates;
+ num_rates = ARRAY_SIZE(tab3_det_rates);
+ wm8994->pdata->micd_rates = tab3_det_rates;
+ wm8994->pdata->num_micd_rates = num_rates;
+ }
+
+ best = 0;
+ for (i = 0; i < num_rates; i++) {
+ if (rates[i].idle != idle)
+ continue;
+ if (abs(rates[i].sysclk - sysclk) <
+ abs(rates[best].sysclk - sysclk))
+ best = i;
+ else if (rates[best].idle != idle)
+ best = i;
+ }
+
+ val = rates[best].start << WM8958_MICD_BIAS_STARTTIME_SHIFT
+ | rates[best].rate << WM8958_MICD_RATE_SHIFT;
+
+ snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
+ WM8958_MICD_BIAS_STARTTIME_MASK |
+ WM8958_MICD_RATE_MASK, val);
+}
+
+static void tab3_mic_id(void *data, u16 status)
+{
+ struct wm1811_machine_priv *wm1811 = data;
+ struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(wm1811->codec);
+ int report;
+ int reg;
+ bool present;
+
+ wake_lock_timeout(&wm1811->jackdet_wake_lock, 5 * HZ);
+
+ /* Either nothing present or just starting detection */
+ if (!(status & WM8958_MICD_STS)) {
+ if (!wm8994->jackdet) {
+ /* If nothing present then clear our statuses */
+ dev_dbg(wm1811->codec->dev, "Detected open circuit\n");
+ wm8994->jack_mic = false;
+ wm8994->mic_detecting = true;
+
+ tab3_micd_set_rate(wm1811->codec);
+
+ snd_soc_jack_report(wm8994->micdet[0].jack, 0,
+ wm8994->btn_mask |
+ SND_JACK_HEADSET);
+ }
+ /*ToDo*/
+ /*return;*/
+ }
+
+ /* If the measurement is showing a high impedence we've got a
+ * microphone.
+ */
+ if (wm8994->mic_detecting && (status & 0x400)) {
+ dev_info(wm1811->codec->dev, "Detected microphone\n");
+
+ wm8994->mic_detecting = false;
+ wm8994->jack_mic = true;
+
+ tab3_micd_set_rate(wm1811->codec);
+
+ snd_soc_jack_report(wm8994->micdet[0].jack, SND_JACK_HEADSET,
+ SND_JACK_HEADSET);
+ }
+
+ if (wm8994->mic_detecting && status & 0x4) {
+ dev_info(wm1811->codec->dev, "Detected headphone\n");
+ wm8994->mic_detecting = false;
+
+ tab3_micd_set_rate(wm1811->codec);
+
+ snd_soc_jack_report(wm8994->micdet[0].jack, SND_JACK_HEADPHONE,
+ SND_JACK_HEADSET);
+
+ /* If we have jackdet that will detect removal */
+ if (wm8994->jackdet) {
+ mutex_lock(&wm8994->accdet_lock);
+
+ snd_soc_update_bits(wm1811->codec, WM8958_MIC_DETECT_1,
+ WM8958_MICD_ENA, 0);
+
+ if (wm8994->active_refcount) {
+ snd_soc_update_bits(wm1811->codec,
+ WM8994_ANTIPOP_2,
+ WM1811_JACKDET_MODE_MASK,
+ WM1811_JACKDET_MODE_AUDIO);
+ }
+
+ mutex_unlock(&wm8994->accdet_lock);
+
+ if (wm8994->pdata->jd_ext_cap) {
+ mutex_lock(&wm1811->codec->mutex);
+ snd_soc_dapm_disable_pin(&wm1811->codec->dapm,
+ "MICBIAS2");
+ snd_soc_dapm_sync(&wm1811->codec->dapm);
+ mutex_unlock(&wm1811->codec->mutex);
+ }
+ }
+ }
+}
+
+static int tab3_wm1811_aif1_hw_params(struct snd_pcm_substream *substream,
+ struct snd_pcm_hw_params *params)
+{
+ struct snd_soc_pcm_runtime *rtd = substream->private_data;
+ struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
+ struct snd_soc_dai *codec_dai = rtd->codec_dai;
+ unsigned int pll_out;
+ int ret;
+
+ dev_info(codec_dai->dev, "%s ++\n", __func__);
+ /* AIF1CLK should be >=3MHz for optimal performance */
+ if (params_rate(params) == 8000 || params_rate(params) == 11025)
+ pll_out = params_rate(params) * 512;
+ else
+ pll_out = params_rate(params) * 256;
+
+ ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
+ | SND_SOC_DAIFMT_NB_NF
+ | SND_SOC_DAIFMT_CBM_CFM);
+ if (ret < 0)
+ return ret;
+
+ /* Set the cpu DAI configuration */
+ ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S
+ | SND_SOC_DAIFMT_NB_NF
+ | SND_SOC_DAIFMT_CBM_CFM);
+ if (ret < 0)
+ return ret;
+
+ /* Switch the FLL */
+ ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL1,
+ WM8994_FLL_SRC_MCLK1, MIDAS_DEFAULT_MCLK1,
+ pll_out);
+ if (ret < 0)
+ dev_err(codec_dai->dev, "Unable to start FLL1: %d\n", ret);
+
+ ret = snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_FLL1,
+ pll_out, SND_SOC_CLOCK_IN);
+ if (ret < 0) {
+ dev_err(codec_dai->dev, "Unable to switch to FLL1: %d\n", ret);
+ return ret;
+ }
+
+ ret = snd_soc_dai_set_sysclk(cpu_dai, SAMSUNG_I2S_OPCLK,
+ 0, MOD_OPCLK_PCLK);
+ if (ret < 0)
+ return ret;
+
+ dev_info(codec_dai->dev, "%s --\n", __func__);
+
+ return 0;
+}
+
+/*
+ * TAB3 WM1811 DAI operations.
+ */
+static struct snd_soc_ops tab3_wm1811_aif1_ops = {
+ .hw_params = tab3_wm1811_aif1_hw_params,
+};
+
+static int tab3_wm1811_aif2_hw_params(struct snd_pcm_substream *substream,
+ struct snd_pcm_hw_params *params)
+{
+ struct snd_soc_pcm_runtime *rtd = substream->private_data;
+ struct snd_soc_codec *codec = rtd->codec;
+ struct snd_soc_dai *codec_dai = rtd->codec_dai;
+ int ret;
+ int prate;
+ int bclk;
+
+ dev_info(codec_dai->dev, "%s ++\n", __func__);
+ prate = params_rate(params);
+ switch (params_rate(params)) {
+ case 8000:
+ case 16000:
+ break;
+ default:
+ dev_warn(codec_dai->dev, "Unsupported LRCLK %d, falling back to 8000Hz\n",
+ (int)params_rate(params));
+ prate = 8000;
+ }
+
+ /* Set the codec DAI configuration, aif2_mode:0 is slave */
+ if (aif2_mode == 0)
+ ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
+ | SND_SOC_DAIFMT_NB_NF
+ | SND_SOC_DAIFMT_CBS_CFS);
+ else
+ ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
+ | SND_SOC_DAIFMT_NB_NF
+ | SND_SOC_DAIFMT_CBM_CFM);
+
+ if (ret < 0)
+ return ret;
+
+ switch (prate) {
+ case 8000:
+ bclk = 256000;
+ break;
+ case 16000:
+ bclk = 512000;
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ if (aif2_mode == 0) {
+ ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL2,
+ WM8994_FLL_SRC_BCLK,
+ bclk, prate * 256);
+ } else {
+ ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL2,
+ WM8994_FLL_SRC_MCLK1,
+ MIDAS_DEFAULT_MCLK1, prate * 256);
+ }
+
+ if (ret < 0)
+ dev_err(codec_dai->dev, "Unable to configure FLL2: %d\n", ret);
+
+ ret = snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_FLL2,
+ prate * 256, SND_SOC_CLOCK_IN);
+ if (ret < 0)
+ dev_err(codec_dai->dev, "Unable to switch to FLL2: %d\n", ret);
+
+ if (!(snd_soc_read(codec, WM8994_INTERRUPT_RAW_STATUS_2)
+ & WM8994_FLL2_LOCK_STS)) {
+ dev_info(codec_dai->dev, "%s: use mclk1 for FLL2\n", __func__);
+ ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL2,
+ WM8994_FLL_SRC_MCLK1,
+ MIDAS_DEFAULT_MCLK1, prate * 256);
+ }
+
+ dev_info(codec_dai->dev, "%s --\n", __func__);
+ return 0;
+}
+
+static struct snd_soc_ops tab3_wm1811_aif2_ops = {
+ .hw_params = tab3_wm1811_aif2_hw_params,
+};
+
+static int tab3_wm1811_aif3_hw_params(struct snd_pcm_substream *substream,
+ struct snd_pcm_hw_params *params)
+{
+ pr_err("%s: enter\n", __func__);
+ return 0;
+}
+
+static struct snd_soc_ops tab3_wm1811_aif3_ops = {
+ .hw_params = tab3_wm1811_aif3_hw_params,
+};
+
+static const struct snd_kcontrol_new tab3_controls[] = {
+ SOC_DAPM_PIN_SWITCH("HP"),
+ SOC_DAPM_PIN_SWITCH("SPK"),
+ SOC_DAPM_PIN_SWITCH("RCV"),
+ SOC_DAPM_PIN_SWITCH("LINE"),
+ SOC_DAPM_PIN_SWITCH("HDMI"),
+ SOC_DAPM_PIN_SWITCH("Main Mic"),
+ SOC_DAPM_PIN_SWITCH("Sub Mic"),
+ SOC_DAPM_PIN_SWITCH("Headset Mic"),
+
+ SOC_ENUM_EXT("AIF2 Mode", aif2_mode_enum[0],
+ get_aif2_mode, set_aif2_mode),
+
+ SOC_ENUM_EXT("KPCS Mode", kpcs_mode_enum[0],
+ get_kpcs_mode, set_kpcs_mode),
+
+ SOC_ENUM_EXT("Input Clamp", input_clamp_enum[0],
+ get_input_clamp, set_input_clamp),
+
+ SOC_ENUM_EXT("LineoutSwitch Mode", lineout_mode_enum[0],
+ get_lineout_mode, set_lineout_mode),
+
+ SOC_ENUM_EXT("AIF2 digital mute", switch_mode_enum[0],
+ get_aif2_mute_status, set_aif2_mute_status),
+
+};
+
+const struct snd_soc_dapm_widget tab3_dapm_widgets_rev0[] = {
+ SND_SOC_DAPM_HP("HP", NULL),
+ SND_SOC_DAPM_SPK("SPK", tab3_ext_spkmode),
+ SND_SOC_DAPM_SPK("RCV", NULL),
+ SND_SOC_DAPM_LINE("LINE", tab3_lineout_switch),
+ SND_SOC_DAPM_LINE("HDMI", NULL),
+
+ SND_SOC_DAPM_MIC("Main Mic", NULL),
+ SND_SOC_DAPM_MIC("Headset Mic", NULL),
+ SND_SOC_DAPM_MIC("Sub Mic", tab3_ext_micbias),
+
+ SND_SOC_DAPM_INPUT("S5P RP"),
+};
+
+const struct snd_soc_dapm_widget tab3_dapm_widgets[] = {
+ SND_SOC_DAPM_HP("HP", NULL),
+ SND_SOC_DAPM_SPK("SPK", tab3_ext_spkmode),
+ SND_SOC_DAPM_SPK("RCV", NULL),
+ SND_SOC_DAPM_LINE("LINE", tab3_lineout_switch),
+ SND_SOC_DAPM_LINE("HDMI", NULL),
+
+ SND_SOC_DAPM_MIC("Main Mic", NULL),
+ SND_SOC_DAPM_MIC("Headset Mic", NULL),
+ SND_SOC_DAPM_MIC("Sub Mic", NULL),
+ SND_SOC_DAPM_INPUT("S5P RP"),
+
+ SND_SOC_DAPM_MICBIAS_E("BIAS2 Event", WM8994_POWER_MANAGEMENT_1, 5, 0,
+ tab3_bias2_event, SND_SOC_DAPM_POST_PMU),
+ SND_SOC_DAPM_MICBIAS_E("BIAS1 Event", WM8994_POWER_MANAGEMENT_1, 4, 0,
+ tab3_bias1_event, SND_SOC_DAPM_POST_PMU),
+};
+
+const struct snd_soc_dapm_route tab3_dapm_routes_rev0[] = {
+ { "HP", NULL, "HPOUT1L" },
+ { "HP", NULL, "HPOUT1R" },
+
+ { "SPK", NULL, "SPKOUTLN" },
+ { "SPK", NULL, "SPKOUTLP" },
+ { "SPK", NULL, "SPKOUTRN" },
+ { "SPK", NULL, "SPKOUTRP" },
+
+ { "RCV", NULL, "HPOUT2N" },
+ { "RCV", NULL, "HPOUT2P" },
+
+ { "LINE", NULL, "LINEOUT2N" },
+ { "LINE", NULL, "LINEOUT2P" },
+
+ { "HDMI", NULL, "LINEOUT1N" },
+ { "HDMI", NULL, "LINEOUT1P" },
+
+ { "IN2LP:VXRN", NULL, "MICBIAS1" },
+ { "IN2LN", NULL, "MICBIAS1" },
+ { "MICBIAS1", NULL, "Main Mic" },
+
+ { "IN1RP", NULL, "Sub Mic" },
+ { "IN1RN", NULL, "Sub Mic" },
+
+ { "IN1LP", NULL, "MICBIAS2" },
+ { "IN1LN", NULL, "MICBIAS2" },
+ { "MICBIAS2", NULL, "Headset Mic" },
+
+ { "AIF1DAC1L", NULL, "S5P RP" },
+ { "AIF1DAC1R", NULL, "S5P RP" },
+
+};
+
+const struct snd_soc_dapm_route tab3_dapm_routes[] = {
+ { "HP", NULL, "HPOUT1L" },
+ { "HP", NULL, "HPOUT1R" },
+
+ { "SPK", NULL, "SPKOUTLN" },
+ { "SPK", NULL, "SPKOUTLP" },
+ { "SPK", NULL, "SPKOUTRN" },
+ { "SPK", NULL, "SPKOUTRP" },
+
+ { "RCV", NULL, "HPOUT2N" },
+ { "RCV", NULL, "HPOUT2P" },
+
+ { "LINE", NULL, "LINEOUT2N" },
+ { "LINE", NULL, "LINEOUT2P" },
+
+ { "HDMI", NULL, "LINEOUT1N" },
+ { "HDMI", NULL, "LINEOUT1P" },
+
+ { "IN2LP:VXRN", NULL, "BIAS1 Event" },
+ { "IN2LN", NULL, "BIAS1 Event" },
+ { "BIAS1 Event", NULL, "Main Mic" },
+
+ { "IN1RP", NULL, "BIAS2 Event" },
+ { "IN1RN", NULL, "BIAS2 Event" },
+ { "BIAS2 Event", NULL, "Sub Mic" },
+
+ { "IN1LP", NULL, "Headset Mic" },
+ { "IN1LN", NULL, "Headset Mic" },
+
+ { "AIF1DAC1L", NULL, "S5P RP" },
+ { "AIF1DAC1R", NULL, "S5P RP" },
+
+};
+
+static struct snd_soc_dai_driver tab3_ext_dai[] = {
+ {
+ .name = "tab3.cp",
+ .playback = {
+ .channels_min = 1,
+ .channels_max = 2,
+ .rate_min = 8000,
+ .rate_max = 16000,
+ .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000,
+ .formats = SNDRV_PCM_FMTBIT_S16_LE,
+ },
+ .capture = {
+ .channels_min = 1,
+ .channels_max = 2,
+ .rate_min = 8000,
+ .rate_max = 16000,
+ .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000,
+ .formats = SNDRV_PCM_FMTBIT_S16_LE,
+ },
+ },
+ {
+ .name = "tab3.bt",
+ .playback = {
+ .channels_min = 1,
+ .channels_max = 2,
+ .rate_min = 8000,
+ .rate_max = 16000,
+ .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000,
+ .formats = SNDRV_PCM_FMTBIT_S16_LE,
+ },
+ .capture = {
+ .channels_min = 1,
+ .channels_max = 2,
+ .rate_min = 8000,
+ .rate_max = 16000,
+ .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000,
+ .formats = SNDRV_PCM_FMTBIT_S16_LE,
+ },
+ },
+};
+
+#ifndef CONFIG_SEC_DEV_JACK
+static ssize_t earjack_state_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct snd_soc_codec *codec = dev_get_drvdata(dev);
+ struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
+
+ int report = 0;
+
+ if ((wm8994->micdet[0].jack->status & SND_JACK_HEADPHONE) ||
+ (wm8994->micdet[0].jack->status & SND_JACK_HEADSET)) {
+ report = 1;
+ }
+
+ return sprintf(buf, "%d\n", report);
+}
+
+static ssize_t earjack_state_store(struct device *dev,
+ struct device_attribute *attr, const char *buf, size_t size)
+{
+ pr_info("%s : operate nothing\n", __func__);
+
+ return size;
+}
+
+static ssize_t earjack_key_state_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct snd_soc_codec *codec = dev_get_drvdata(dev);
+ struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
+
+ int report = 0;
+
+ if (wm8994->micdet[0].jack->status & SND_JACK_BTN_0)
+ report = 1;
+
+ return sprintf(buf, "%d\n", report);
+}
+
+static ssize_t earjack_key_state_store(struct device *dev,
+ struct device_attribute *attr, const char *buf, size_t size)
+{
+ pr_info("%s : operate nothing\n", __func__);
+
+ return size;
+}
+
+static ssize_t earjack_select_jack_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ pr_info("%s : operate nothing\n", __func__);
+
+ return 0;
+}
+
+static ssize_t earjack_select_jack_store(struct device *dev,
+ struct device_attribute *attr, const char *buf, size_t size)
+{
+ struct snd_soc_codec *codec = dev_get_drvdata(dev);
+ struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
+
+ wm8994->mic_detecting = false;
+ wm8994->jack_mic = true;
+
+ tab3_micd_set_rate(codec);
+
+ if ((!size) || (buf[0] != '1')) {
+ snd_soc_jack_report(wm8994->micdet[0].jack,
+ 0, SND_JACK_HEADSET);
+ dev_info(codec->dev, "Forced remove microphone\n");
+ } else {
+
+ snd_soc_jack_report(wm8994->micdet[0].jack,
+ SND_JACK_HEADSET, SND_JACK_HEADSET);
+ dev_info(codec->dev, "Forced detect microphone\n");
+ }
+
+ return size;
+}
+
+static ssize_t reselect_jack_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ pr_info("%s : operate nothing\n", __func__);
+ return 0;
+}
+
+static ssize_t reselect_jack_store(struct device *dev,
+ struct device_attribute *attr, const char *buf, size_t size)
+{
+ struct snd_soc_codec *codec = dev_get_drvdata(dev);
+ struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
+ int reg = 0;
+
+ reg = snd_soc_read(codec, WM8958_MIC_DETECT_3);
+ if (reg == 0x402) {
+ dev_info(codec->dev, "Detected open circuit\n");
+
+ snd_soc_update_bits(codec, WM8958_MICBIAS2,
+ WM8958_MICB2_DISCH, WM8958_MICB2_DISCH);
+ /* Enable debounce while removed */
+ snd_soc_update_bits(codec, WM1811_JACKDET_CTRL,
+ WM1811_JACKDET_DB, WM1811_JACKDET_DB);
+
+ wm8994->mic_detecting = false;
+ wm8994->jack_mic = false;
+ snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
+ WM8958_MICD_ENA, 0);
+
+ if (wm8994->active_refcount) {
+ snd_soc_update_bits(codec,
+ WM8994_ANTIPOP_2,
+ WM1811_JACKDET_MODE_MASK,
+ WM1811_JACKDET_MODE_AUDIO);
+ } else {
+ snd_soc_update_bits(codec,
+ WM8994_ANTIPOP_2,
+ WM1811_JACKDET_MODE_MASK,
+ WM1811_JACKDET_MODE_JACK);
+ }
+
+ snd_soc_jack_report(wm8994->micdet[0].jack, 0,
+ SND_JACK_MECHANICAL | SND_JACK_HEADSET |
+ wm8994->btn_mask);
+ }
+ return size;
+}
+
+static DEVICE_ATTR(reselect_jack, S_IRUGO | S_IWUSR | S_IWGRP,
+ reselect_jack_show, reselect_jack_store);
+
+static DEVICE_ATTR(select_jack, S_IRUGO | S_IWUSR | S_IWGRP,
+ earjack_select_jack_show, earjack_select_jack_store);
+
+static DEVICE_ATTR(key_state, S_IRUGO | S_IWUSR | S_IWGRP,
+ earjack_key_state_show, earjack_key_state_store);
+
+static DEVICE_ATTR(state, S_IRUGO | S_IWUSR | S_IWGRP,
+ earjack_state_show, earjack_state_store);
+#endif
+
+static int tab3_wm1811_init_paiftx(struct snd_soc_pcm_runtime *rtd)
+{
+ struct snd_soc_codec *codec = rtd->codec;
+ struct wm1811_machine_priv *wm1811
+ = snd_soc_card_get_drvdata(codec->card);
+ struct snd_soc_dai *aif1_dai = rtd->codec_dai;
+ struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
+ int ret;
+
+ midas_snd_set_mclk(true, false);
+
+ rtd->codec_dai->driver->playback.channels_max =
+ rtd->cpu_dai->driver->playback.channels_max;
+
+ ret = snd_soc_add_controls(codec, tab3_controls,
+ ARRAY_SIZE(tab3_controls));
+
+#if defined(CONFIG_TAB3_00_BD)
+ if(system_rev < 2) {
+ ret = snd_soc_dapm_new_controls(&codec->dapm, tab3_dapm_widgets_rev0,
+ ARRAY_SIZE(tab3_dapm_widgets_rev0));
+ if (ret != 0)
+ dev_err(codec->dev, "Failed to add DAPM widgets: %d\n", ret);
+
+ ret = snd_soc_dapm_add_routes(&codec->dapm, tab3_dapm_routes_rev0,
+ ARRAY_SIZE(tab3_dapm_routes_rev0));
+ if (ret != 0)
+ dev_err(codec->dev, "Failed to add DAPM routes: %d\n", ret);
+ } else {
+ ret = snd_soc_dapm_new_controls(&codec->dapm, tab3_dapm_widgets,
+ ARRAY_SIZE(tab3_dapm_widgets));
+ if (ret != 0)
+ dev_err(codec->dev, "Failed to add DAPM widgets: %d\n", ret);
+
+ ret = snd_soc_dapm_add_routes(&codec->dapm, tab3_dapm_routes,
+ ARRAY_SIZE(tab3_dapm_routes));
+ if (ret != 0)
+ dev_err(codec->dev, "Failed to add DAPM routes: %d\n", ret);
+ }
+#else
+ ret = snd_soc_dapm_new_controls(&codec->dapm, tab3_dapm_widgets,
+ ARRAY_SIZE(tab3_dapm_widgets));
+ if (ret != 0)
+ dev_err(codec->dev, "Failed to add DAPM widgets: %d\n", ret);
+
+ ret = snd_soc_dapm_add_routes(&codec->dapm, tab3_dapm_routes,
+ ARRAY_SIZE(tab3_dapm_routes));
+ if (ret != 0)
+ dev_err(codec->dev, "Failed to add DAPM routes: %d\n", ret);
+
+#endif
+
+ ret = snd_soc_dai_set_sysclk(aif1_dai, WM8994_SYSCLK_MCLK2,
+ MIDAS_DEFAULT_MCLK2, SND_SOC_CLOCK_IN);
+ if (ret < 0)
+ dev_err(codec->dev, "Failed to boot clocking\n");
+
+ /* Force AIF1CLK on as it will be master for jack detection */
+ if (wm8994->revision > 1) {
+ ret = snd_soc_dapm_force_enable_pin(&codec->dapm, "AIF1CLK");
+ if (ret < 0)
+ dev_err(codec->dev, "Failed to enable AIF1CLK: %d\n",
+ ret);
+ }
+
+ ret = snd_soc_dapm_disable_pin(&codec->dapm, "S5P RP");
+ if (ret < 0)
+ dev_err(codec->dev, "Failed to disable S5P RP: %d\n", ret);
+
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "RCV");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "SPK");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "HP");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "Headset Mic");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "Sub Mic");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "Main Mic");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "AIF1DACDAT");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "AIF2DACDAT");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "AIF3DACDAT");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "AIF1ADCDAT");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "AIF2ADCDAT");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "AIF3ADCDAT");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "FM In");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "LINE");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "HDMI");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "Third Mic");
+
+ wm1811->codec = codec;
+
+ tab3_micd_set_rate(codec);
+
+#ifdef CONFIG_SEC_DEV_JACK
+ /* By default use idle_bias_off, will override for WM8994 */
+ codec->dapm.idle_bias_off = 0;
+#if defined (CONFIG_TAB3_00_BD)
+ if(system_rev < 2) {
+ ret = snd_soc_dapm_force_enable_pin(&codec->dapm, "MICBIAS2");
+ if (ret < 0)
+ dev_err(codec->dev, "Failed to enable MICBIAS2: %d\n",
+ ret);
+ }
+#endif
+#else /* CONFIG_SEC_DEV_JACK */
+ wm1811->jack.status = 0;
+
+ ret = snd_soc_jack_new(codec, "Tab3 Jack",
+ SND_JACK_HEADSET | SND_JACK_BTN_0 |
+ SND_JACK_BTN_1 | SND_JACK_BTN_2,
+ &wm1811->jack);
+
+ if (ret < 0)
+ dev_err(codec->dev, "Failed to create jack: %d\n", ret);
+
+ ret = snd_jack_set_key(wm1811->jack.jack, SND_JACK_BTN_0, KEY_MEDIA);
+
+ if (ret < 0)
+ dev_err(codec->dev, "Failed to set KEY_MEDIA: %d\n", ret);
+
+ ret = snd_jack_set_key(wm1811->jack.jack, SND_JACK_BTN_1,
+ KEY_VOLUMEUP);
+ if (ret < 0)
+ dev_err(codec->dev, "Failed to set KEY_VOLUMEUP: %d\n", ret);
+
+ ret = snd_jack_set_key(wm1811->jack.jack, SND_JACK_BTN_2,
+ KEY_VOLUMEDOWN);
+
+ if (ret < 0)
+ dev_err(codec->dev, "Failed to set KEY_VOLUMEDOWN: %d\n", ret);
+
+ if (wm8994->revision > 1) {
+ dev_info(codec->dev, "wm1811: Rev %c support mic detection\n",
+ 'A' + wm8994->revision);
+ ret = wm8958_mic_detect(codec, &wm1811->jack, NULL,
+ NULL, tab3_mic_id, wm1811);
+
+ if (ret < 0)
+ dev_err(codec->dev, "Failed start detection: %d\n",
+ ret);
+ } else {
+ dev_info(codec->dev, "wm1811: Rev %c doesn't support mic detection\n",
+ 'A' + wm8994->revision);
+ codec->dapm.idle_bias_off = 0;
+ }
+ /* To wakeup for earjack event in suspend mode */
+ enable_irq_wake(control->irq);
+
+ wake_lock_init(&wm1811->jackdet_wake_lock,
+ WAKE_LOCK_SUSPEND, "Tab3_jackdet");
+
+ /* To support PBA function test */
+ jack_class = class_create(THIS_MODULE, "audio");
+
+ if (IS_ERR(jack_class))
+ pr_err("Failed to create class\n");
+
+ jack_dev = device_create(jack_class, NULL, 0, codec, "earjack");
+
+ if (device_create_file(jack_dev, &dev_attr_select_jack) < 0)
+ pr_err("Failed to create device file (%s)!\n",
+ dev_attr_select_jack.attr.name);
+
+ if (device_create_file(jack_dev, &dev_attr_key_state) < 0)
+ pr_err("Failed to create device file (%s)!\n",
+ dev_attr_key_state.attr.name);
+
+ if (device_create_file(jack_dev, &dev_attr_state) < 0)
+ pr_err("Failed to create device file (%s)!\n",
+ dev_attr_state.attr.name);
+
+ if (device_create_file(jack_dev, &dev_attr_reselect_jack) < 0)
+ pr_err("Failed to create device file (%s)!\n",
+ dev_attr_reselect_jack.attr.name);
+
+#endif /* CONFIG_SEC_DEV_JACK */
+ return snd_soc_dapm_sync(&codec->dapm);
+}
+
+static struct snd_soc_dai_link tab3_dai[] = {
+ { /* Sec_Fifo DAI i/f */
+ .name = "Sec_FIFO TX",
+ .stream_name = "Sec_Dai",
+ .cpu_dai_name = "samsung-i2s.4",
+ .codec_dai_name = "wm8994-aif1",
+#ifndef CONFIG_SND_SOC_SAMSUNG_USE_DMA_WRAPPER
+ .platform_name = "samsung-audio-idma",
+#else
+ .platform_name = "samsung-audio",
+#endif
+ .codec_name = "wm8994-codec",
+ .init = tab3_wm1811_init_paiftx,
+ .ops = &tab3_wm1811_aif1_ops,
+ },
+ {
+ .name = "TAB3_WM1811 Voice",
+ .stream_name = "Voice Tx/Rx",
+ .cpu_dai_name = "tab3.cp",
+ .codec_dai_name = "wm8994-aif2",
+ .platform_name = "snd-soc-dummy",
+ .codec_name = "wm8994-codec",
+ .ops = &tab3_wm1811_aif2_ops,
+ .ignore_suspend = 1,
+ },
+ {
+ .name = "TAB3_WM1811 BT",
+ .stream_name = "BT Tx/Rx",
+ .cpu_dai_name = "tab3.bt",
+ .codec_dai_name = "wm8994-aif3",
+ .platform_name = "snd-soc-dummy",
+ .codec_name = "wm8994-codec",
+ .ops = &tab3_wm1811_aif3_ops,
+ .ignore_suspend = 1,
+ },
+ { /* Primary DAI i/f */
+ .name = "WM8994 AIF1",
+ .stream_name = "Pri_Dai",
+ .cpu_dai_name = "samsung-i2s.0",
+ .codec_dai_name = "wm8994-aif1",
+ .platform_name = "samsung-audio",
+ .codec_name = "wm8994-codec",
+ .ops = &tab3_wm1811_aif1_ops,
+ },
+};
+
+static int tab3_card_suspend_pre(struct snd_soc_card *card)
+{
+#ifdef CONFIG_SEC_DEV_JACK
+ struct snd_soc_codec *codec = card->rtd->codec;
+
+ snd_soc_dapm_disable_pin(&codec->dapm, "AIF1CLK");
+#endif
+
+ return 0;
+}
+
+static int tab3_card_suspend_post(struct snd_soc_card *card)
+{
+ struct snd_soc_codec *codec = card->rtd->codec;
+ struct snd_soc_dai *aif1_dai = card->rtd[0].codec_dai;
+ struct snd_soc_dai *aif2_dai = card->rtd[1].codec_dai;
+ int ret;
+
+ if (!codec->active) {
+ ret = snd_soc_dai_set_sysclk(aif2_dai,
+ WM8994_SYSCLK_MCLK2,
+ MIDAS_DEFAULT_MCLK2,
+ SND_SOC_CLOCK_IN);
+
+ if (ret < 0)
+ dev_err(codec->dev, "Unable to switch to MCLK2: %d\n",
+ ret);
+
+ ret = snd_soc_dai_set_pll(aif2_dai, WM8994_FLL2, 0, 0, 0);
+
+ if (ret < 0)
+ dev_err(codec->dev, "Unable to stop FLL2\n");
+
+ ret = snd_soc_dai_set_sysclk(aif1_dai,
+ WM8994_SYSCLK_MCLK2,
+ MIDAS_DEFAULT_MCLK2,
+ SND_SOC_CLOCK_IN);
+ if (ret < 0)
+ dev_err(codec->dev, "Unable to switch to MCLK2\n");
+
+ ret = snd_soc_dai_set_pll(aif1_dai, WM8994_FLL1, 0, 0, 0);
+
+ if (ret < 0)
+ dev_err(codec->dev, "Unable to stop FLL1\n");
+
+ midas_snd_set_mclk(false, true);
+ }
+
+#ifdef CONFIG_ARCH_EXYNOS5
+ exynos5_sys_powerdown_xxti_control(midas_snd_get_mclk() ? 1 : 0);
+#else /* for CONFIG_ARCH_EXYNOS5 */
+ exynos4_sys_powerdown_xusbxti_control(midas_snd_get_mclk() ? 1 : 0);
+#endif
+
+ return 0;
+}
+
+static int tab3_card_resume_pre(struct snd_soc_card *card)
+{
+ struct snd_soc_dai *aif1_dai = card->rtd[0].codec_dai;
+ int ret;
+
+ midas_snd_set_mclk(true, false);
+
+ /* Switch the FLL */
+ ret = snd_soc_dai_set_pll(aif1_dai, WM8994_FLL1,
+ WM8994_FLL_SRC_MCLK1,
+ MIDAS_DEFAULT_MCLK1,
+ MIDAS_DEFAULT_SYNC_CLK);
+
+ if (ret < 0)
+ dev_err(aif1_dai->dev, "Unable to start FLL1: %d\n", ret);
+
+ /* Then switch AIF1CLK to it */
+ ret = snd_soc_dai_set_sysclk(aif1_dai,
+ WM8994_SYSCLK_FLL1,
+ MIDAS_DEFAULT_SYNC_CLK,
+ SND_SOC_CLOCK_IN);
+
+ if (ret < 0)
+ dev_err(aif1_dai->dev, "Unable to switch to FLL1: %d\n", ret);
+
+ return 0;
+}
+
+static int tab3_card_resume_post(struct snd_soc_card *card)
+{
+ struct snd_soc_codec *codec = card->rtd->codec;
+ int reg = 0;
+
+ /* workaround for jack detection
+ * sometimes WM8994_GPIO_1 type changed wrong function type
+ * so if type mismatched, update to IRQ type
+ */
+ reg = snd_soc_read(codec, WM8994_GPIO_1);
+
+ if ((reg & WM8994_GPN_FN_MASK) != WM8994_GP_FN_IRQ) {
+ dev_err(codec->dev, "%s: GPIO1 type 0x%x\n", __func__, reg);
+ snd_soc_write(codec, WM8994_GPIO_1, WM8994_GP_FN_IRQ);
+ }
+
+#ifdef CONFIG_SEC_DEV_JACK
+ snd_soc_dapm_force_enable_pin(&codec->dapm, "AIF1CLK");
+#endif
+
+ return 0;
+}
+
+static struct snd_soc_card tab3 = {
+ .name = "TAB3_WM1811",
+ .dai_link = tab3_dai,
+
+ /* If you want to use sec_fifo device,
+ * changes the num_link = 2 or ARRAY_SIZE(tab3_dai). */
+ .num_links = ARRAY_SIZE(tab3_dai),
+
+ .suspend_post = tab3_card_suspend_post,
+ .resume_pre = tab3_card_resume_pre,
+ .suspend_pre = tab3_card_suspend_pre,
+ .resume_post = tab3_card_resume_post
+};
+
+static struct platform_device *tab3_snd_device;
+
+static int __init tab3_audio_init(void)
+{
+ struct wm1811_machine_priv *wm1811;
+ int ret;
+
+ wm1811 = kzalloc(sizeof *wm1811, GFP_KERNEL);
+ if (!wm1811) {
+ pr_err("Failed to allocate memory\n");
+ ret = -ENOMEM;
+ goto err_kzalloc;
+ }
+ snd_soc_card_set_drvdata(&tab3, wm1811);
+
+ tab3_snd_device = platform_device_alloc("soc-audio", -1);
+ if (!tab3_snd_device) {
+ ret = -ENOMEM;
+ goto err_device_alloc;
+ }
+
+ ret = snd_soc_register_dais(&tab3_snd_device->dev, tab3_ext_dai,
+ ARRAY_SIZE(tab3_ext_dai));
+ if (ret != 0)
+ pr_err("Failed to register external DAIs: %d\n", ret);
+
+ platform_set_drvdata(tab3_snd_device, &tab3);
+
+ ret = platform_device_add(tab3_snd_device);
+ if (ret)
+ platform_device_put(tab3_snd_device);
+
+ tab3_gpio_init();
+
+ return ret;
+
+err_device_alloc:
+ kfree(wm1811);
+err_kzalloc:
+ return ret;
+}
+module_init(tab3_audio_init);
+
+static void __exit tab3_audio_exit(void)
+{
+ struct snd_soc_card *card = &tab3;
+ struct wm1811_machine_priv *wm1811 = snd_soc_card_get_drvdata(card);
+ platform_device_unregister(tab3_snd_device);
+ kfree(wm1811);
+}
+module_exit(tab3_audio_exit);
+
+MODULE_AUTHOR("JS. Park <aitdark.park@samsung.com>");
+MODULE_DESCRIPTION("ALSA SoC TAB3 WM1811");
+MODULE_LICENSE("GPL");
diff --git a/sound/soc/samsung/watch_ymu831.c b/sound/soc/samsung/watch_ymu831.c
new file mode 100644
index 0000000..4226074
--- /dev/null
+++ b/sound/soc/samsung/watch_ymu831.c
@@ -0,0 +1,210 @@
+/*
+ * watch_ymu831.c
+ *
+ * Copyright (c) 2013 Samsung Electronics Co. Ltd
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ */
+
+#include <linux/clk.h>
+#include <linux/delay.h>
+#include <linux/gpio.h>
+#include <linux/io.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/suspend.h>
+
+#include <mach/midas-sound.h>
+#include <mach/pmu.h>
+#include <mach/regs-clock.h>
+#include <mach/watch-sound.h>
+
+#include <plat/gpio-cfg.h>
+
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include <sound/soc.h>
+#include <sound/soc-dapm.h>
+
+#include "../codecs/ymu831/ymu831.h"
+
+struct watch_machine_priv {
+ int (*set_mic_bias) (int on);
+ int micbias_status;
+};
+
+static int watch_hifi_hw_params(struct snd_pcm_substream *substream,
+ struct snd_pcm_hw_params *params)
+{
+ struct snd_soc_pcm_runtime *rtd = substream->private_data;
+ struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
+ struct snd_soc_dai *codec_dai = rtd->codec_dai;
+ int ret;
+
+ /* Set the codec DAI configuration */
+ ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
+ | SND_SOC_DAIFMT_NB_NF
+ | SND_SOC_DAIFMT_CBM_CFM);
+ if (ret < 0)
+ return ret;
+
+ /* Set the cpu DAI configuration */
+ ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S
+ | SND_SOC_DAIFMT_NB_NF
+ | SND_SOC_DAIFMT_CBM_CFM);
+ if (ret < 0)
+ return ret;
+
+ ret = snd_soc_dai_set_clkdiv(codec_dai, MC_ASOC_BCLK_MULT,
+ MC_ASOC_LRCK_X32);
+
+ if (ret < 0)
+ return ret;
+
+ return 0;
+}
+
+
+/*
+ * WATCH YMU831 DAI operations.
+ */
+static struct snd_soc_ops watch_hifi_ops = {
+ .hw_params = watch_hifi_hw_params,
+};
+
+const char *micbias_control_text[] = {
+ "Off", "On"
+};
+
+static const struct soc_enum micbias_control_enum[] = {
+ SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(micbias_control_text), micbias_control_text),
+};
+
+static int get_micbias_switch(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+ struct watch_machine_priv *machine_watch
+ = snd_soc_card_get_drvdata(codec->card);
+
+ ucontrol->value.integer.value[0] = machine_watch->micbias_status;
+ return 0;
+}
+
+static int set_micbias_switch(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+ struct watch_machine_priv *machine_watch
+ = snd_soc_card_get_drvdata(codec->card);
+ int status = ucontrol->value.integer.value[0];
+
+ machine_watch->set_mic_bias(status);
+ machine_watch->micbias_status = status;
+ return 0;
+}
+
+static const struct snd_kcontrol_new watch_controls[] = {
+ SOC_ENUM_EXT("MICBIAS SWITCH", micbias_control_enum[0],
+ get_micbias_switch, set_micbias_switch),
+};
+
+static struct snd_soc_dai_link watch_dai[] = {
+ { /* Primary DAI i/f */
+ .name = "YMU831 AIF1",
+ .stream_name = "Pri_Dai",
+ .cpu_dai_name = "samsung-i2s.0",
+ .codec_dai_name = "ymu831-da0",
+ .platform_name = "samsung-audio",
+ .codec_name = "spi0.0", /* SPI bus:0, chipselect:0 */
+ .ops = &watch_hifi_ops,
+ },
+};
+
+static struct snd_soc_card ymu831_snd_card = {
+ .name = "WATCH-YMU831",
+ .dai_link = watch_dai,
+ .num_links = ARRAY_SIZE(watch_dai),
+
+ .controls = watch_controls,
+ .num_controls = ARRAY_SIZE(watch_controls),
+};
+
+static struct platform_device *watch_snd_device;
+
+static int __devinit snd_watch_probe(struct platform_device *pdev)
+{
+ int ret;
+ struct watch_machine_priv *machine_watch;
+ struct watch_audio_platform_data *audio_pdata =
+ pdev->dev.platform_data;
+
+ machine_watch = kzalloc(sizeof *machine_watch, GFP_KERNEL);
+ if (!machine_watch) {
+ pr_err("Failed to allocate memory\n");
+ return -ENOMEM;
+ }
+ machine_watch->set_mic_bias = audio_pdata->set_micbias;
+
+ snd_soc_card_set_drvdata(&ymu831_snd_card, machine_watch);
+
+ midas_snd_set_mclk(1, 0);
+
+ watch_snd_device = platform_device_alloc("soc-audio", -1);
+ if (!watch_snd_device) {
+ ret = -ENOMEM;
+ goto err_device_alloc;
+ }
+
+ platform_set_drvdata(watch_snd_device, &ymu831_snd_card);
+
+ ret = platform_device_add(watch_snd_device);
+ if (ret) {
+ platform_device_put(watch_snd_device);
+ }
+
+ return ret;
+
+err_device_alloc:
+ kfree(machine_watch);
+ return ret;
+}
+
+static int __devexit snd_watch_remove(struct platform_device *pdev)
+{
+ struct watch_machine_priv *machine_watch = snd_soc_card_get_drvdata(&ymu831_snd_card);
+ platform_device_unregister(watch_snd_device);
+ kfree(machine_watch);
+
+ return 0;
+}
+
+
+static struct platform_driver snd_watch_driver = {
+ .driver = {
+ .owner = THIS_MODULE,
+ .name = "ymu831-card",
+ },
+ .probe = snd_watch_probe,
+ .remove = __devexit_p(snd_watch_remove),
+};
+
+
+static int __init watch_audio_init(void)
+{
+ return platform_driver_register(&snd_watch_driver);
+}
+module_init(watch_audio_init);
+
+static void __exit watch_audio_exit(void)
+{
+ platform_driver_unregister(&snd_watch_driver);
+}
+
+module_exit(watch_audio_exit);
+
+MODULE_DESCRIPTION("ALSA SoC WATCH YMU831");
+MODULE_LICENSE("GPL");
diff --git a/sound/soc/samsung/zest_wm1811.c b/sound/soc/samsung/zest_wm1811.c
new file mode 100644
index 0000000..12a20b7
--- /dev/null
+++ b/sound/soc/samsung/zest_wm1811.c
@@ -0,0 +1,1735 @@
+/*
+ * zest_wm1811.c
+ *
+ * Copyright (c) 2011 Samsung Electronics Co. Ltd
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ */
+#include <linux/platform_device.h>
+#include <linux/clk.h>
+#include <linux/io.h>
+#include <linux/gpio.h>
+#include <linux/delay.h>
+#include <linux/slab.h>
+#include <linux/workqueue.h>
+#include <linux/input.h>
+#include <linux/wakelock.h>
+#include <linux/suspend.h>
+#include <linux/irq.h>
+#include <linux/interrupt.h>
+
+#include <sound/soc.h>
+#include <sound/soc-dapm.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include <sound/jack.h>
+
+#include <mach/regs-clock.h>
+#include <mach/pmu.h>
+#include <mach/midas-sound.h>
+
+#include <linux/mfd/wm8994/core.h>
+#include <linux/mfd/wm8994/registers.h>
+#include <linux/mfd/wm8994/pdata.h>
+#include <linux/mfd/wm8994/gpio.h>
+
+#include <linux/exynos_audio.h>
+
+#ifdef CONFIG_USE_ADC_DET
+#include <plat/adc.h>
+#endif
+
+#if defined(CONFIG_SND_USE_MUIC_SWITCH)
+#include <linux/mfd/max77693-private.h>
+#endif
+
+
+#include "i2s.h"
+#include "s3c-i2s-v2.h"
+#include "../codecs/wm8994.h"
+
+
+#define MIDAS_DEFAULT_MCLK1 24000000
+#define MIDAS_DEFAULT_MCLK2 32768
+#define MIDAS_DEFAULT_SYNC_CLK 11289600
+
+#define WM1811_JACKDET_MODE_NONE 0x0000
+#define WM1811_JACKDET_MODE_JACK 0x0100
+#define WM1811_JACKDET_MODE_MIC 0x0080
+#define WM1811_JACKDET_MODE_AUDIO 0x0180
+
+#define WM1811_JACKDET_BTN0 0x04
+#define WM1811_JACKDET_BTN1 0x10
+#define WM1811_JACKDET_BTN2 0x08
+
+#define WM1811_MIC_IRQ_NUM (IRQ_BOARD_CODEC_START + WM8994_IRQ_MIC1_DET)
+#define WM1811_JACKDET_IRQ_NUM (IRQ_BOARD_CODEC_START + WM8994_IRQ_GPIO(6))
+
+#define MIC_DISABLE 0
+#define MIC_ENABLE 1
+#define MIC_FORCE_DISABLE 2
+#define MIC_FORCE_ENABLE 3
+
+#define JACK_ADC_CH 3
+#define JACK_SAMPLE_SIZE 5
+
+#define MAX_ZONE_LIMIT 10
+/* keep this value if you support double-pressed concept */
+#define WAKE_LOCK_TIME (HZ * 5) /* 5 sec */
+#define EAR_CHECK_LOOP_CNT 10
+
+struct wm1811_machine_priv {
+ struct snd_soc_jack jack;
+ struct snd_soc_codec *codec;
+ struct wake_lock jackdet_wake_lock;
+ void (*lineout_switch_f) (int on);
+ void (*set_main_mic_f) (int on);
+ void (*set_sub_mic_f) (int on);
+ int (*get_g_det_value_f) (void);
+ int (*get_g_det_irq_num_f) (void);
+#ifdef CONFIG_USE_ADC_DET
+ struct s3c_adc_client *padc;
+ struct jack_zone *zones;
+ int num_zones;
+ int use_jackdet_type;
+#endif
+};
+
+enum {
+ SEC_JACK_NO_DEVICE = 0x0,
+ SEC_HEADSET_4POLE = 0x01 << 0,
+ SEC_HEADSET_3POLE = 0x01 << 1,
+ SEC_TTY_DEVICE = 0x01 << 2,
+ SEC_FM_HEADSET = 0x01 << 3,
+ SEC_FM_SPEAKER = 0x01 << 4,
+ SEC_TVOUT_DEVICE = 0x01 << 5,
+ SEC_EXTRA_DOCK_SPEAKER = 0x01 << 6,
+ SEC_EXTRA_CAR_DOCK_SPEAKER = 0x01 << 7,
+ SEC_UNKNOWN_DEVICE = 0x01 << 8,
+};
+
+#ifdef CONFIG_USE_ADC_DET
+static bool recheck_jack;
+static int jack_get_adc_data(struct s3c_adc_client *padc);
+static void jack_set_type(struct wm1811_machine_priv *wm1811, int jack_type);
+#endif
+
+static struct wm8958_micd_rate zest_det_rates[] = {
+ { MIDAS_DEFAULT_MCLK2, true, 0, 0 },
+ { MIDAS_DEFAULT_MCLK2, false, 0, 0 },
+ { MIDAS_DEFAULT_SYNC_CLK, true, 7, 7 },
+ { MIDAS_DEFAULT_SYNC_CLK, false, 7, 7 },
+};
+
+static struct wm8958_micd_rate zest_jackdet_rates[] = {
+ { MIDAS_DEFAULT_MCLK2, true, 0, 0 },
+ { MIDAS_DEFAULT_MCLK2, false, 0, 0 },
+ { MIDAS_DEFAULT_SYNC_CLK, true, 12, 12 },
+ { MIDAS_DEFAULT_SYNC_CLK, false, 7, 8 },
+};
+
+static int aif2_mode;
+const char *aif2_mode_text[] = {
+ "Slave", "Master"
+};
+
+const char *switch_mode_text[] = {
+ "Off", "On"
+};
+
+const char *mic_bias_mode_text[] = {
+ "Disable", "Force Disable", "Enable", "Force Enable"
+};
+
+static int input_clamp;
+static int lineout_mode;
+static int aif2_digital_mute;
+static int main_mic_bias_mode;
+static int sub_mic_bias_mode;
+
+#ifndef CONFIG_SEC_DEV_JACK
+/* To support PBA function test */
+static struct class *jack_class;
+static struct device *jack_dev;
+#endif
+
+static struct platform_device *zest_snd_device;
+
+static const struct soc_enum switch_mode_enum[] = {
+ SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(switch_mode_text), switch_mode_text),
+};
+
+static const struct soc_enum aif2_mode_enum[] = {
+ SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(aif2_mode_text), aif2_mode_text),
+};
+
+static const struct soc_enum mic_bias_mode_enum[] = {
+ SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(mic_bias_mode_text), mic_bias_mode_text),
+};
+
+static const struct soc_enum sub_bias_mode_enum[] = {
+ SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(mic_bias_mode_text), mic_bias_mode_text),
+};
+
+static int get_lineout_mode(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ ucontrol->value.integer.value[0] = lineout_mode;
+ return 0;
+}
+
+static int set_lineout_mode(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+ struct wm1811_machine_priv *wm1811
+ = snd_soc_card_get_drvdata(codec->card);
+
+ lineout_mode = ucontrol->value.integer.value[0];
+
+ if (lineout_mode) {
+ wm8994_vmid_mode(codec, WM8994_VMID_FORCE);
+ if (wm1811->lineout_switch_f)
+ wm1811->lineout_switch_f(1);
+ } else {
+ if (wm1811->lineout_switch_f)
+ wm1811->lineout_switch_f(0);
+ wm8994_vmid_mode(codec, WM8994_VMID_NORMAL);
+ }
+
+ dev_info(codec->dev, "set lineout mode : %s\n",
+ switch_mode_text[lineout_mode]);
+ return 0;
+
+}
+
+static int get_aif2_mode(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ ucontrol->value.integer.value[0] = aif2_mode;
+ return 0;
+}
+
+static int set_aif2_mode(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ if (aif2_mode == ucontrol->value.integer.value[0])
+ return 0;
+
+ aif2_mode = ucontrol->value.integer.value[0];
+
+ pr_info("set aif2 mode : %s\n", aif2_mode_text[aif2_mode]);
+
+ return 0;
+}
+
+static int get_input_clamp(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ ucontrol->value.integer.value[0] = input_clamp;
+ return 0;
+}
+
+static int set_input_clamp(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+
+ input_clamp = ucontrol->value.integer.value[0];
+
+ if (input_clamp) {
+ snd_soc_update_bits(codec, WM8994_INPUT_MIXER_1,
+ WM8994_INPUTS_CLAMP, WM8994_INPUTS_CLAMP);
+ msleep(100);
+ } else {
+ snd_soc_update_bits(codec, WM8994_INPUT_MIXER_1,
+ WM8994_INPUTS_CLAMP, 0);
+ }
+ pr_info("set fm input_clamp : %s\n", switch_mode_text[input_clamp]);
+
+ return 0;
+}
+
+static int get_aif2_mute_status(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ ucontrol->value.integer.value[0] = aif2_digital_mute;
+ return 0;
+}
+
+static int set_aif2_mute_status(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+ int reg;
+
+ aif2_digital_mute = ucontrol->value.integer.value[0];
+
+ if (snd_soc_read(codec, WM8994_POWER_MANAGEMENT_6)
+ & WM8994_AIF2_DACDAT_SRC)
+ aif2_digital_mute = 0;
+
+ if (aif2_digital_mute)
+ reg = WM8994_AIF1DAC1_MUTE;
+ else
+ reg = 0;
+
+ snd_soc_update_bits(codec, WM8994_AIF2_DAC_FILTERS_1,
+ WM8994_AIF1DAC1_MUTE, reg);
+
+ pr_info("set aif2_digital_mute : %s\n",
+ switch_mode_text[aif2_digital_mute]);
+
+ return 0;
+}
+
+static int get_sub_mic_bias_mode(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ ucontrol->value.integer.value[0] = sub_mic_bias_mode;
+ return 0;
+}
+
+static int set_sub_mic_bias_mode(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+ struct wm1811_machine_priv *wm1811
+ = snd_soc_card_get_drvdata(codec->card);
+ int status = 0;
+
+ status = ucontrol->value.integer.value[0];
+
+ switch (status) {
+ case MIC_FORCE_ENABLE:
+ sub_mic_bias_mode = status;
+ snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_1,
+ WM8994_MICB1_ENA, WM8994_MICB1_ENA);
+
+ if (wm1811->set_sub_mic_f)
+ wm1811->set_sub_mic_f(1);
+ break;
+ case MIC_ENABLE:
+ snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_1,
+ WM8994_MICB1_ENA, WM8994_MICB1_ENA);
+ if (wm1811->set_sub_mic_f)
+ wm1811->set_sub_mic_f(1);
+ if (sub_mic_bias_mode != MIC_FORCE_ENABLE)
+ msleep(100);
+ break;
+ case MIC_FORCE_DISABLE:
+ sub_mic_bias_mode = status;
+ snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_1,
+ WM8994_MICB1_ENA, 0);
+
+ if (wm1811->set_sub_mic_f)
+ wm1811->set_sub_mic_f(0);
+ break;
+ case MIC_DISABLE:
+ if (sub_mic_bias_mode != MIC_FORCE_ENABLE) {
+ snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_1,
+ WM8994_MICB1_ENA, 0);
+ if (wm1811->set_sub_mic_f)
+ wm1811->set_sub_mic_f(0);
+ } else
+ dev_info(codec->dev,
+ "SKIP submic disable=%d\n", status);
+ break;
+ default:
+ break;
+ }
+
+ dev_info(codec->dev, "sub_mic_bias_mod=%d: status=%d\n",
+ sub_mic_bias_mode, status);
+
+ return 0;
+
+}
+
+static int get_main_mic_bias_mode(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ ucontrol->value.integer.value[0] = main_mic_bias_mode;
+ return 0;
+}
+
+static int set_main_mic_bias_mode(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+ struct wm1811_machine_priv *wm1811
+ = snd_soc_card_get_drvdata(codec->card);
+ int status = 0;
+
+ status = ucontrol->value.integer.value[0];
+
+ switch (status) {
+ case MIC_FORCE_ENABLE:
+ main_mic_bias_mode = status;
+
+ if (wm1811->set_main_mic_f)
+ wm1811->set_main_mic_f(1);
+ break;
+ case MIC_ENABLE:
+ if (wm1811->set_main_mic_f)
+ wm1811->set_main_mic_f(1);
+ if (main_mic_bias_mode != MIC_FORCE_ENABLE)
+ msleep(100);
+ break;
+ case MIC_FORCE_DISABLE:
+ main_mic_bias_mode = status;
+
+ if (wm1811->set_main_mic_f)
+ wm1811->set_main_mic_f(0);
+ break;
+ case MIC_DISABLE:
+ if (main_mic_bias_mode != MIC_FORCE_ENABLE) {
+ if (wm1811->set_main_mic_f)
+ wm1811->set_main_mic_f(0);
+ } else
+ dev_info(codec->dev,
+ "SKIP mainmic disable=%d\n", status);
+ break;
+ default:
+ break;
+ }
+
+ dev_info(codec->dev, "main_mic_bias_mod=%d: status=%d\n",
+ main_mic_bias_mode, status);
+
+ return 0;
+
+}
+
+static int set_ext_micbias(struct snd_soc_dapm_widget *w,
+ struct snd_kcontrol *kcontrol, int event)
+{
+ struct snd_soc_codec *codec = w->codec;
+ struct wm1811_machine_priv *wm1811
+ = snd_soc_card_get_drvdata(codec->card);
+
+ dev_info(codec->dev, "%s event is %02X", w->name, event);
+
+ switch (event) {
+ case SND_SOC_DAPM_PRE_PMU:
+ if (wm1811->set_main_mic_f)
+ wm1811->set_main_mic_f(1);
+ break;
+ case SND_SOC_DAPM_POST_PMD:
+ if (wm1811->set_main_mic_f)
+ wm1811->set_main_mic_f(0);
+ break;
+ }
+
+ return 0;
+}
+
+static int set_ext_submicbias(struct snd_soc_dapm_widget *w,
+ struct snd_kcontrol *kcontrol, int event)
+{
+ struct snd_soc_codec *codec = w->codec;
+ struct wm1811_machine_priv *wm1811
+ = snd_soc_card_get_drvdata(codec->card);
+
+ dev_info(codec->dev, "%s event is %02X", w->name, event);
+
+ switch (event) {
+ case SND_SOC_DAPM_PRE_PMU:
+ if (wm1811->set_sub_mic_f)
+ wm1811->set_sub_mic_f(1);
+ break;
+ case SND_SOC_DAPM_POST_PMD:
+ if (wm1811->set_sub_mic_f)
+ wm1811->set_sub_mic_f(0);
+ break;
+ }
+
+ return 0;
+}
+
+static int set_muic_switch(struct snd_soc_dapm_widget *w,
+ struct snd_kcontrol *kcontrol, int event)
+{
+ struct snd_soc_codec *codec = w->codec;
+
+ dev_info(codec->dev, "%s event is %02X", w->name, event);
+
+#if defined(CONFIG_SND_USE_MUIC_SWITCH)
+ switch (event) {
+ case SND_SOC_DAPM_POST_PMU:
+ msleep(150);
+ max77693_muic_set_audio_switch(1);
+ break;
+ case SND_SOC_DAPM_PRE_PMD:
+ max77693_muic_set_audio_switch(0);
+ break;
+ }
+#endif
+
+ return 0;
+}
+
+static void zest_micd_set_rate(struct snd_soc_codec *codec)
+{
+ struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
+ int best, i, sysclk, val;
+ bool idle;
+ const struct wm8958_micd_rate *rates = NULL;
+ int num_rates = 0;
+
+ idle = !wm8994->jack_mic;
+
+ sysclk = snd_soc_read(codec, WM8994_CLOCKING_1);
+ if (sysclk & WM8994_SYSCLK_SRC)
+ sysclk = wm8994->aifclk[1];
+ else
+ sysclk = wm8994->aifclk[0];
+
+ if (wm8994->jackdet) {
+ rates = zest_jackdet_rates;
+ num_rates = ARRAY_SIZE(zest_jackdet_rates);
+ wm8994->pdata->micd_rates = zest_jackdet_rates;
+ wm8994->pdata->num_micd_rates = num_rates;
+ } else {
+ rates = zest_det_rates;
+ num_rates = ARRAY_SIZE(zest_det_rates);
+ wm8994->pdata->micd_rates = zest_det_rates;
+ wm8994->pdata->num_micd_rates = num_rates;
+ }
+
+ best = 0;
+ for (i = 0; i < num_rates; i++) {
+ if (rates[i].idle != idle)
+ continue;
+ if (abs(rates[i].sysclk - sysclk) <
+ abs(rates[best].sysclk - sysclk))
+ best = i;
+ else if (rates[best].idle != idle)
+ best = i;
+ }
+
+ val = rates[best].start << WM8958_MICD_BIAS_STARTTIME_SHIFT
+ | rates[best].rate << WM8958_MICD_RATE_SHIFT;
+
+ snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
+ WM8958_MICD_BIAS_STARTTIME_MASK |
+ WM8958_MICD_RATE_MASK, val);
+}
+
+#ifdef CONFIG_USE_ADC_DET
+static int jack_get_adc_data(struct s3c_adc_client *padc)
+{
+ int adc_data;
+ int adc_max = 0;
+ int adc_min = 0xFFFF;
+ int adc_total = 0;
+ int adc_retry_cnt = 0;
+ int i;
+
+ for (i = 0; i < JACK_SAMPLE_SIZE; i++) {
+
+ adc_data = s3c_adc_read(padc, JACK_ADC_CH);
+
+ if (adc_data < 0) {
+
+ adc_retry_cnt++;
+
+ if (adc_retry_cnt > 10)
+ return adc_data;
+ }
+
+ if (i != 0) {
+ if (adc_data > adc_max)
+ adc_max = adc_data;
+ else if (adc_data < adc_min)
+ adc_min = adc_data;
+ } else {
+ adc_max = adc_data;
+ adc_min = adc_data;
+ }
+ adc_total += adc_data;
+ }
+
+ return (adc_total - adc_max - adc_min) / (JACK_SAMPLE_SIZE - 2);
+}
+
+static void determine_jack_type(struct wm1811_machine_priv *wm1811)
+{
+ struct jack_zone *zones = wm1811->zones;
+ struct snd_soc_codec *codec = wm1811->codec;
+ int size = wm1811->num_zones;
+ int count[MAX_ZONE_LIMIT] = {0};
+ int adc;
+ int i;
+
+ /* set mic bias to enable adc */
+ while (snd_soc_read(codec, WM1811_JACKDET_CTRL) & WM1811_JACKDET_LVL) {
+ adc = jack_get_adc_data(wm1811->padc);
+
+ pr_info("%s: adc = %d\n", __func__, adc);
+
+ if (adc < 0)
+ break;
+
+ /* determine the type of headset based on the
+ * adc value. An adc value can fall in various
+ * ranges or zones. Within some ranges, the type
+ * can be returned immediately. Within others, the
+ * value is considered unstable and we need to sample
+ * a few more types (up to the limit determined by
+ * the range) before we return the type for that range.
+ */
+ for (i = 0; i < size; i++) {
+ if (adc <= zones[i].adc_high) {
+ if (++count[i] > zones[i].check_count) {
+ if (recheck_jack == true && i == 4) {
+ pr_info("%s : something wrong connection!\n",
+ __func__);
+
+ recheck_jack = false;
+ return;
+ }
+ jack_set_type(wm1811,
+ zones[i].jack_type);
+ return;
+ }
+ msleep(zones[i].delay_ms);
+ break;
+ }
+ }
+ }
+
+ recheck_jack = false;
+ /* jack removed before detection complete */
+ pr_debug("%s : jack removed before detection complete\n", __func__);
+}
+
+static void jack_set_type(struct wm1811_machine_priv *wm1811, int jack_type)
+{
+ struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(wm1811->codec);
+
+ if (jack_type == SEC_HEADSET_4POLE) {
+ dev_info(wm1811->codec->dev, "Detected microphone\n");
+
+ wm8994->mic_detecting = false;
+ wm8994->jack_mic = true;
+
+ zest_micd_set_rate(wm1811->codec);
+
+ snd_soc_jack_report(wm8994->micdet[0].jack, SND_JACK_HEADSET,
+ SND_JACK_HEADSET);
+
+ snd_soc_update_bits(wm1811->codec, WM8958_MIC_DETECT_1,
+ WM8958_MICD_ENA, 1);
+ } else {
+ dev_info(wm1811->codec->dev, "Detected headphone\n");
+ wm8994->mic_detecting = false;
+
+ zest_micd_set_rate(wm1811->codec);
+
+ snd_soc_jack_report(wm8994->micdet[0].jack, SND_JACK_HEADPHONE,
+ SND_JACK_HEADSET);
+
+ /* If we have jackdet that will detect removal */
+ if (wm8994->jackdet) {
+ snd_soc_update_bits(wm1811->codec, WM8958_MIC_DETECT_1,
+ WM8958_MICD_ENA, 0);
+
+ if (wm8994->active_refcount) {
+ snd_soc_update_bits(wm1811->codec,
+ WM8994_ANTIPOP_2,
+ WM1811_JACKDET_MODE_MASK,
+ WM1811_JACKDET_MODE_AUDIO);
+ }
+
+ if (wm8994->pdata->jd_ext_cap) {
+ mutex_lock(&wm1811->codec->mutex);
+ snd_soc_dapm_disable_pin(&wm1811->codec->dapm,
+ "MICBIAS2");
+ snd_soc_dapm_sync(&wm1811->codec->dapm);
+ mutex_unlock(&wm1811->codec->mutex);
+ }
+ }
+ }
+}
+
+static void zest_micdet(void *data)
+{
+ struct wm1811_machine_priv *wm1811 = data;
+ struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(wm1811->codec);
+
+ struct snd_soc_codec *codec = wm1811->codec;
+
+ pr_info("%s: detected jack\n", __func__);
+ wm8994->mic_detecting = true;
+
+ wake_lock_timeout(&wm1811->jackdet_wake_lock, 5 * HZ);
+
+ snd_soc_update_bits(codec, WM8958_MICBIAS2,
+ WM8958_MICB2_MODE, 0);
+
+ /* Apply delay time(150ms) to remove pop noise
+ * during to enable micbias */
+ msleep(150);
+
+ determine_jack_type(wm1811);
+ }
+#endif
+
+static void zest_mic_id(void *data, u16 status)
+{
+ struct wm1811_machine_priv *wm1811 = data;
+ struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(wm1811->codec);
+
+ pr_info("%s: detected jack\n", __func__);
+ wake_lock_timeout(&wm1811->jackdet_wake_lock, 5 * HZ);
+
+ /* Either nothing present or just starting detection */
+ if (!(status & WM8958_MICD_STS)) {
+ if (!wm8994->jackdet) {
+ /* If nothing present then clear our statuses */
+ dev_dbg(wm1811->codec->dev, "Detected open circuit\n");
+ wm8994->jack_mic = false;
+ wm8994->mic_detecting = true;
+
+ zest_micd_set_rate(wm1811->codec);
+
+ snd_soc_jack_report(wm8994->micdet[0].jack, 0,
+ wm8994->btn_mask |
+ SND_JACK_HEADSET);
+ }
+ /*ToDo*/
+ /*return;*/
+ }
+
+ /* If the measurement is showing a high impedence we've got a
+ * microphone.
+ */
+ if (wm8994->mic_detecting && (status & 0x400)) {
+ dev_info(wm1811->codec->dev, "Detected microphone\n");
+
+ wm8994->mic_detecting = false;
+ wm8994->jack_mic = true;
+
+ zest_micd_set_rate(wm1811->codec);
+
+ snd_soc_jack_report(wm8994->micdet[0].jack, SND_JACK_HEADSET,
+ SND_JACK_HEADSET);
+ }
+
+ if (wm8994->mic_detecting && status & 0x4) {
+ dev_info(wm1811->codec->dev, "Detected headphone\n");
+ wm8994->mic_detecting = false;
+
+ zest_micd_set_rate(wm1811->codec);
+
+ snd_soc_jack_report(wm8994->micdet[0].jack, SND_JACK_HEADPHONE,
+ SND_JACK_HEADSET);
+
+ /* If we have jackdet that will detect removal */
+ if (wm8994->jackdet) {
+ mutex_lock(&wm8994->accdet_lock);
+
+ snd_soc_update_bits(wm1811->codec, WM8958_MIC_DETECT_1,
+ WM8958_MICD_ENA, 0);
+
+ if (wm8994->active_refcount) {
+ snd_soc_update_bits(wm1811->codec,
+ WM8994_ANTIPOP_2,
+ WM1811_JACKDET_MODE_MASK,
+ WM1811_JACKDET_MODE_AUDIO);
+ }
+
+ mutex_unlock(&wm8994->accdet_lock);
+
+ if (wm8994->pdata->jd_ext_cap) {
+ mutex_lock(&wm1811->codec->mutex);
+ snd_soc_dapm_disable_pin(&wm1811->codec->dapm,
+ "MICBIAS2");
+ snd_soc_dapm_sync(&wm1811->codec->dapm);
+ mutex_unlock(&wm1811->codec->mutex);
+ }
+ }
+ }
+}
+
+static int zest_wm1811_aif1_hw_params(struct snd_pcm_substream *substream,
+ struct snd_pcm_hw_params *params)
+{
+ struct snd_soc_pcm_runtime *rtd = substream->private_data;
+ struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
+ struct snd_soc_dai *codec_dai = rtd->codec_dai;
+ unsigned int pll_out;
+ int ret;
+
+ dev_info(codec_dai->dev, "%s ++\n", __func__);
+ /* AIF1CLK should be >=3MHz for optimal performance */
+ if (params_rate(params) == 8000 || params_rate(params) == 11025)
+ pll_out = params_rate(params) * 512;
+ else
+ pll_out = params_rate(params) * 256;
+
+ ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
+ | SND_SOC_DAIFMT_NB_NF
+ | SND_SOC_DAIFMT_CBM_CFM);
+ if (ret < 0)
+ return ret;
+
+ /* Set the cpu DAI configuration */
+ ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S
+ | SND_SOC_DAIFMT_NB_NF
+ | SND_SOC_DAIFMT_CBM_CFM);
+ if (ret < 0)
+ return ret;
+
+ /* Switch the FLL */
+ ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL1,
+ WM8994_FLL_SRC_MCLK1, MIDAS_DEFAULT_MCLK1,
+ pll_out);
+ if (ret < 0)
+ dev_err(codec_dai->dev, "Unable to start FLL1: %d\n", ret);
+
+ ret = snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_FLL1,
+ pll_out, SND_SOC_CLOCK_IN);
+ if (ret < 0) {
+ dev_err(codec_dai->dev, "Unable to switch to FLL1: %d\n", ret);
+ return ret;
+ }
+
+ ret = snd_soc_dai_set_sysclk(cpu_dai, SAMSUNG_I2S_OPCLK,
+ 0, MOD_OPCLK_PCLK);
+ if (ret < 0)
+ return ret;
+
+ dev_info(codec_dai->dev, "%s --\n", __func__);
+
+ return 0;
+}
+
+/*
+ * ZEST WM1811 DAI operations.
+ */
+static struct snd_soc_ops zest_wm1811_aif1_ops = {
+ .hw_params = zest_wm1811_aif1_hw_params,
+};
+
+static int zest_wm1811_aif2_hw_params(struct snd_pcm_substream *substream,
+ struct snd_pcm_hw_params *params)
+{
+ struct snd_soc_pcm_runtime *rtd = substream->private_data;
+ struct snd_soc_dai *codec_dai = rtd->codec_dai;
+ int ret;
+ int prate;
+ int bclk;
+
+ dev_info(codec_dai->dev, "%s ++\n", __func__);
+
+ prate = params_rate(params);
+
+ switch (params_rate(params)) {
+ case 8000:
+ case 16000:
+ break;
+ default:
+ dev_warn(codec_dai->dev, "Unsupported LRCLK %d, falling back to 8000Hz\n",
+ (int)params_rate(params));
+ prate = 8000;
+ }
+
+ /* Set the codec DAI configuration */
+ if (aif2_mode == 0) {
+ ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_DSP_A
+ | SND_SOC_DAIFMT_IB_NF | SND_SOC_DAIFMT_CBS_CFS);
+ } else {
+ ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_DSP_A
+ | SND_SOC_DAIFMT_IB_NF
+ | SND_SOC_DAIFMT_CBM_CFM);
+ }
+ if (ret < 0)
+ return ret;
+
+ /* The Shannon Audio interface is setted only 2048 bclk */
+ switch (prate) {
+ case 8000:
+ case 16000:
+ bclk = 2048000;
+ break;
+ default:
+ return -EINVAL;
+ }
+
+
+ if (aif2_mode == 0) {
+ ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL2,
+ WM8994_FLL_SRC_BCLK,
+ bclk, prate * 256);
+ } else {
+ ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL2,
+ WM8994_FLL_SRC_MCLK1,
+ MIDAS_DEFAULT_MCLK1, prate * 256);
+ }
+
+ if (ret < 0)
+ dev_err(codec_dai->dev, "Unable to configure FLL2: %d\n", ret);
+
+ ret = snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_FLL2,
+ prate * 256, SND_SOC_CLOCK_IN);
+ if (ret < 0)
+ dev_err(codec_dai->dev, "Unable to switch to FLL2: %d\n", ret);
+
+ dev_info(codec_dai->dev, "%s --\n", __func__);
+
+ return 0;
+}
+
+static struct snd_soc_ops zest_wm1811_aif2_ops = {
+ .hw_params = zest_wm1811_aif2_hw_params,
+};
+
+static int zest_wm1811_aif3_hw_params(struct snd_pcm_substream *substream,
+ struct snd_pcm_hw_params *params)
+{
+ pr_err("%s: enter\n", __func__);
+ return 0;
+}
+
+static bool playback_stream_status;
+static bool capture_stream_status;
+
+static int zest_wm1811_aif3_startup(struct snd_pcm_substream *substream)
+{
+ struct snd_soc_pcm_runtime *rtd = substream->private_data;
+ struct snd_soc_codec *codec = rtd->codec;
+ struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
+ struct wm8994_pdata *pdata = wm8994->pdata;
+ int base = WM8994_GPIO_8 - WM8994_GPIO_1;
+ int i;
+
+ pr_err("%s: enter\n", __func__);
+
+ if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
+ capture_stream_status = 1;
+ else
+ playback_stream_status = 1;
+
+ for (i = 0; i < 4; i++) {
+ if (pdata->gpio_defaults[base + i]) {
+ snd_soc_update_bits(wm8994->codec, WM8994_GPIO_8 + i,
+ 0xffff,
+ pdata->gpio_defaults[base + i]);
+ }
+ }
+ return 0;
+}
+
+static void zest_wm1811_aif3_shutdown(struct snd_pcm_substream *substream)
+{
+ struct snd_soc_pcm_runtime *rtd = substream->private_data;
+ struct snd_soc_codec *codec = rtd->codec;
+ struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
+ int i;
+
+ pr_err("%s: enter, stream=%d\n", __func__, substream->stream);
+
+ if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
+ capture_stream_status = 0;
+ else
+ playback_stream_status = 0;
+
+ if (playback_stream_status || capture_stream_status)
+ return;
+
+ pr_info("%s: set input gpios for AIF3\n", __func__);
+
+ for (i = 0; i < 4; i++) {
+ snd_soc_update_bits(wm8994->codec, WM8994_GPIO_8 + i,
+ 0xffff,
+ 0xA101);
+ }
+ return;
+}
+
+static struct snd_soc_ops zest_wm1811_aif3_ops = {
+ .startup = zest_wm1811_aif3_startup,
+ .shutdown = zest_wm1811_aif3_shutdown,
+ .hw_params = zest_wm1811_aif3_hw_params,
+};
+
+static const struct snd_kcontrol_new zest_controls[] = {
+ SOC_DAPM_PIN_SWITCH("HP"),
+ SOC_DAPM_PIN_SWITCH("SPK"),
+ SOC_DAPM_PIN_SWITCH("RCV"),
+ SOC_DAPM_PIN_SWITCH("FM In"),
+ SOC_DAPM_PIN_SWITCH("LINE"),
+ SOC_DAPM_PIN_SWITCH("HDMI"),
+ SOC_DAPM_PIN_SWITCH("Main Mic"),
+ SOC_DAPM_PIN_SWITCH("Sub Mic"),
+ SOC_DAPM_PIN_SWITCH("Headset Mic"),
+
+ SOC_ENUM_EXT("AIF2 Mode", aif2_mode_enum[0],
+ get_aif2_mode, set_aif2_mode),
+
+ SOC_ENUM_EXT("Input Clamp", switch_mode_enum[0],
+ get_input_clamp, set_input_clamp),
+
+ SOC_ENUM_EXT("LineoutSwitch Mode", switch_mode_enum[0],
+ get_lineout_mode, set_lineout_mode),
+
+ SOC_ENUM_EXT("MainMicBias Mode", mic_bias_mode_enum[0],
+ get_main_mic_bias_mode, set_main_mic_bias_mode),
+
+ SOC_ENUM_EXT("SubMicBias Mode", mic_bias_mode_enum[0],
+ get_sub_mic_bias_mode, set_sub_mic_bias_mode),
+
+ SOC_ENUM_EXT("AIF2 digital mute", switch_mode_enum[0],
+ get_aif2_mute_status, set_aif2_mute_status),
+};
+
+const struct snd_soc_dapm_widget zest_dapm_widgets[] = {
+ SND_SOC_DAPM_HP("HP", NULL),
+ SND_SOC_DAPM_SPK("SPK", NULL),
+ SND_SOC_DAPM_SPK("RCV", NULL),
+ SND_SOC_DAPM_LINE("LINE", set_muic_switch),
+ SND_SOC_DAPM_LINE("HDMI", NULL),
+
+ SND_SOC_DAPM_MIC("Headset Mic", NULL),
+ SND_SOC_DAPM_MIC("Main Mic", NULL),
+ SND_SOC_DAPM_MIC("Sub Mic", NULL),
+ SND_SOC_DAPM_LINE("FM In", NULL),
+
+ SND_SOC_DAPM_INPUT("S5P RP"),
+};
+
+const struct snd_soc_dapm_route zest_dapm_routes[] = {
+ { "HP", NULL, "HPOUT1L" },
+ { "HP", NULL, "HPOUT1R" },
+
+ { "SPK", NULL, "SPKOUTLN" },
+ { "SPK", NULL, "SPKOUTLP" },
+
+ { "RCV", NULL, "HPOUT2N" },
+ { "RCV", NULL, "HPOUT2P" },
+
+ { "LINE", NULL, "LINEOUT2N" },
+ { "LINE", NULL, "LINEOUT2P" },
+
+ { "HDMI", NULL, "LINEOUT1N" },
+ { "HDMI", NULL, "LINEOUT1P" },
+
+ { "IN1LP", NULL, "Main Mic" },
+ { "IN1LN", NULL, "Main Mic" },
+
+ { "IN2RN", NULL, "Sub Mic" },
+ { "IN2RP:VXRP", NULL, "Sub Mic" },
+
+ { "IN1RP", NULL, "MICBIAS2" },
+ { "MICBIAS2", NULL, "Headset Mic" },
+ { "IN1RP", NULL, "MICBIAS2" },
+ { "MICBIAS2", NULL, "Headset Mic" },
+
+ { "AIF1DAC1L", NULL, "S5P RP" },
+ { "AIF1DAC1R", NULL, "S5P RP" },
+
+ { "IN2LP:VXRN", NULL, "FM In" },
+ { "IN2LN", NULL, "FM In" },
+};
+
+static struct snd_soc_dai_driver zest_ext_dai[] = {
+ {
+ .name = "zest.cp",
+ .playback = {
+ .channels_min = 1,
+ .channels_max = 2,
+ .rate_min = 8000,
+ .rate_max = 16000,
+ .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000,
+ .formats = SNDRV_PCM_FMTBIT_S16_LE,
+ },
+ .capture = {
+ .channels_min = 1,
+ .channels_max = 2,
+ .rate_min = 8000,
+ .rate_max = 16000,
+ .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000,
+ .formats = SNDRV_PCM_FMTBIT_S16_LE,
+ },
+ },
+ {
+ .name = "zest.bt",
+ .playback = {
+ .channels_min = 1,
+ .channels_max = 2,
+ .rate_min = 8000,
+ .rate_max = 16000,
+ .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000,
+ .formats = SNDRV_PCM_FMTBIT_S16_LE,
+ },
+ .capture = {
+ .channels_min = 1,
+ .channels_max = 2,
+ .rate_min = 8000,
+ .rate_max = 16000,
+ .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000,
+ .formats = SNDRV_PCM_FMTBIT_S16_LE,
+ },
+ },
+};
+
+#ifndef CONFIG_SEC_DEV_JACK
+static ssize_t earjack_state_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct snd_soc_codec *codec = dev_get_drvdata(dev);
+ struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
+
+ int report = 0;
+
+ if ((wm8994->micdet[0].jack->status & SND_JACK_HEADPHONE) ||
+ (wm8994->micdet[0].jack->status & SND_JACK_HEADSET)) {
+ report = 1;
+ }
+
+ return sprintf(buf, "%d\n", report);
+}
+
+static ssize_t earjack_state_store(struct device *dev,
+ struct device_attribute *attr, const char *buf, size_t size)
+{
+ pr_info("%s : operate nothing\n", __func__);
+
+ return size;
+}
+
+static ssize_t earjack_key_state_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct snd_soc_codec *codec = dev_get_drvdata(dev);
+ struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
+
+ int report = 0;
+
+ if (wm8994->micdet[0].jack->status & SND_JACK_BTN_0)
+ report = 1;
+
+ return sprintf(buf, "%d\n", report);
+}
+
+static ssize_t earjack_key_state_store(struct device *dev,
+ struct device_attribute *attr, const char *buf, size_t size)
+{
+ pr_info("%s : operate nothing\n", __func__);
+
+ return size;
+}
+
+static ssize_t earjack_select_jack_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ pr_info("%s : operate nothing\n", __func__);
+
+ return 0;
+}
+
+static ssize_t earjack_select_jack_store(struct device *dev,
+ struct device_attribute *attr, const char *buf, size_t size)
+{
+ struct snd_soc_codec *codec = dev_get_drvdata(dev);
+ struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
+
+ wm8994->mic_detecting = false;
+ wm8994->jack_mic = true;
+
+ zest_micd_set_rate(codec);
+
+ if ((!size) || (buf[0] != '1')) {
+ snd_soc_jack_report(wm8994->micdet[0].jack,
+ 0, SND_JACK_HEADSET);
+ dev_info(codec->dev, "Forced remove microphone\n");
+ } else {
+
+ snd_soc_jack_report(wm8994->micdet[0].jack,
+ SND_JACK_HEADSET, SND_JACK_HEADSET);
+ dev_info(codec->dev, "Forced detect microphone\n");
+ }
+
+ return size;
+}
+
+static ssize_t reselect_jack_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ pr_info("%s : operate nothing\n", __func__);
+ return 0;
+}
+
+static ssize_t reselect_jack_store(struct device *dev,
+ struct device_attribute *attr, const char *buf, size_t size)
+{
+ pr_info("%s : operate nothing\n", __func__);
+ return size;
+}
+
+static DEVICE_ATTR(reselect_jack, S_IRUGO | S_IWUSR | S_IWGRP,
+ reselect_jack_show, reselect_jack_store);
+
+static DEVICE_ATTR(select_jack, S_IRUGO | S_IWUSR | S_IWGRP,
+ earjack_select_jack_show, earjack_select_jack_store);
+
+static DEVICE_ATTR(key_state, S_IRUGO | S_IWUSR | S_IWGRP,
+ earjack_key_state_show, earjack_key_state_store);
+
+static DEVICE_ATTR(state, S_IRUGO | S_IWUSR | S_IWGRP,
+ earjack_state_show, earjack_state_store);
+#endif
+
+static int zest_wm1811_init_paiftx(struct snd_soc_pcm_runtime *rtd)
+{
+ struct snd_soc_codec *codec = rtd->codec;
+ struct wm1811_machine_priv *wm1811
+ = snd_soc_card_get_drvdata(codec->card);
+ struct snd_soc_dai *aif1_dai = rtd->codec_dai;
+ struct wm8994 *control = codec->control_data;
+ struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
+ const struct exynos_sound_platform_data *sound_pdata;
+ int ret;
+
+ sound_pdata = exynos_sound_get_platform_data();
+
+ midas_snd_set_mclk(true, false);
+
+ rtd->codec_dai->driver->playback.channels_max =
+ rtd->cpu_dai->driver->playback.channels_max;
+
+ ret = snd_soc_add_controls(codec, zest_controls,
+ ARRAY_SIZE(zest_controls));
+
+ ret = snd_soc_dapm_new_controls(&codec->dapm, zest_dapm_widgets,
+ ARRAY_SIZE(zest_dapm_widgets));
+ if (ret != 0)
+ dev_err(codec->dev, "Failed to add DAPM widgets: %d\n", ret);
+
+ ret = snd_soc_dapm_add_routes(&codec->dapm, zest_dapm_routes,
+ ARRAY_SIZE(zest_dapm_routes));
+ if (ret != 0)
+ dev_err(codec->dev, "Failed to add DAPM routes: %d\n", ret);
+
+ ret = snd_soc_dai_set_sysclk(aif1_dai, WM8994_SYSCLK_MCLK2,
+ MIDAS_DEFAULT_MCLK2, SND_SOC_CLOCK_IN);
+ if (ret < 0)
+ dev_err(codec->dev, "Failed to boot clocking\n");
+
+ /* Force AIF1CLK on as it will be master for jack detection */
+ if (wm8994->revision > 1) {
+ ret = snd_soc_dapm_force_enable_pin(&codec->dapm, "AIF1CLK");
+ if (ret < 0)
+ dev_err(codec->dev, "Failed to enable AIF1CLK: %d\n",
+ ret);
+ }
+
+ ret = snd_soc_dapm_disable_pin(&codec->dapm, "S5P RP");
+ if (ret < 0)
+ dev_err(codec->dev, "Failed to disable S5P RP: %d\n", ret);
+
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "RCV");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "SPK");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "HP");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "Headset Mic");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "Sub Mic");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "Main Mic");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "AIF1DACDAT");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "AIF2DACDAT");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "AIF3DACDAT");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "AIF1ADCDAT");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "AIF2ADCDAT");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "AIF3ADCDAT");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "FM In");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "LINE");
+ snd_soc_dapm_ignore_suspend(&codec->dapm, "HDMI");
+
+ wm1811->codec = codec;
+
+ /* Configure Hidden registers of WM1811 to conform of
+ * the Samsung's standard Revision 1.1 for earphones */
+ snd_soc_write(codec, 0x102, 0x3);
+ snd_soc_write(codec, 0xcb, 0x5151);
+ snd_soc_write(codec, 0xd3, 0x3f3f);
+ snd_soc_write(codec, 0xd4, 0x3f3f);
+ snd_soc_write(codec, 0xd5, 0x3f3f);
+ snd_soc_write(codec, 0xd6, 0x3228);
+ snd_soc_write(codec, 0x102, 0x0);
+
+ zest_micd_set_rate(codec);
+
+#ifdef CONFIG_SEC_DEV_JACK
+ /* By default use idle_bias_off, will override for WM8994 */
+ codec->dapm.idle_bias_off = 0;
+#else /* CONFIG_SEC_DEV_JACK */
+ wm1811->jack.status = 0;
+
+ ret = snd_soc_jack_new(codec, "ZEST Jack",
+ SND_JACK_HEADSET | SND_JACK_BTN_0 |
+ SND_JACK_BTN_1 | SND_JACK_BTN_2,
+ &wm1811->jack);
+
+ if (ret < 0)
+ dev_err(codec->dev, "Failed to create jack: %d\n", ret);
+
+ ret = snd_jack_set_key(wm1811->jack.jack, SND_JACK_BTN_0, KEY_MEDIA);
+
+ if (ret < 0)
+ dev_err(codec->dev, "Failed to set KEY_MEDIA: %d\n", ret);
+
+ ret = snd_jack_set_key(wm1811->jack.jack, SND_JACK_BTN_1,
+ KEY_VOLUMEUP);
+ if (ret < 0)
+ dev_err(codec->dev, "Failed to set KEY_VOLUMEUP: %d\n", ret);
+
+ ret = snd_jack_set_key(wm1811->jack.jack, SND_JACK_BTN_2,
+ KEY_VOLUMEDOWN);
+
+ if (ret < 0)
+ dev_err(codec->dev, "Failed to set KEY_VOLUMEDOWN: %d\n", ret);
+
+ if (wm8994->revision > 1) {
+ dev_info(codec->dev, "wm1811: Rev %c support mic detection\n",
+ 'A' + wm8994->revision);
+#ifdef CONFIG_USE_ADC_DET
+ if (sound_pdata->use_jackdet_type) {
+ ret = wm8958_mic_detect(codec, &wm1811->jack,
+ zest_micdet, wm1811, NULL, NULL);
+ } else {
+ ret = wm8958_mic_detect(codec, &wm1811->jack, NULL,
+ NULL, zest_mic_id, wm1811);
+ }
+#else
+ ret = wm8958_mic_detect(codec, &wm1811->jack, NULL,
+ NULL, zest_mic_id, wm1811);
+#endif
+ if (ret < 0)
+ dev_err(codec->dev, "Failed start detection: %d\n",
+ ret);
+ } else {
+ dev_info(codec->dev, "wm1811: Rev %c doesn't support mic detection\n",
+ 'A' + wm8994->revision);
+ codec->dapm.idle_bias_off = 0;
+ }
+ /* To wakeup for earjack event in suspend mode */
+ enable_irq_wake(control->irq);
+
+ wake_lock_init(&wm1811->jackdet_wake_lock,
+ WAKE_LOCK_SUSPEND, "zest_jackdet");
+
+ /* To support PBA function test */
+ jack_class = class_create(THIS_MODULE, "audio");
+
+ if (IS_ERR(jack_class))
+ pr_err("Failed to create class\n");
+
+ jack_dev = device_create(jack_class, NULL, 0, codec, "earjack");
+
+ if (device_create_file(jack_dev, &dev_attr_select_jack) < 0)
+ pr_err("Failed to create device file (%s)!\n",
+ dev_attr_select_jack.attr.name);
+
+ if (device_create_file(jack_dev, &dev_attr_key_state) < 0)
+ pr_err("Failed to create device file (%s)!\n",
+ dev_attr_key_state.attr.name);
+
+ if (device_create_file(jack_dev, &dev_attr_state) < 0)
+ pr_err("Failed to create device file (%s)!\n",
+ dev_attr_state.attr.name);
+
+ if (device_create_file(jack_dev, &dev_attr_reselect_jack) < 0)
+ pr_err("Failed to create device file (%s)!\n",
+ dev_attr_reselect_jack.attr.name);
+
+#endif /* CONFIG_SEC_DEV_JACK */
+ sound_pdata = exynos_sound_get_platform_data();
+
+ if (sound_pdata) {
+ wm8994->hubs.dcs_codes_l = sound_pdata->dcs_offset_l;
+ wm8994->hubs.dcs_codes_r = sound_pdata->dcs_offset_r;
+ }
+
+#ifdef CONFIG_USE_ADC_DET
+ pr_info("%s: register adc client\n", __func__);
+ wm1811->padc = s3c_adc_register(zest_snd_device, NULL, NULL, 0);
+#endif
+ return snd_soc_dapm_sync(&codec->dapm);
+}
+
+static struct snd_soc_dai_link zest_dai[] = {
+ { /* Sec_Fifo DAI i/f */
+ .name = "Sec_FIFO TX",
+ .stream_name = "Sec_Dai",
+ .cpu_dai_name = "samsung-i2s.4",
+ .codec_dai_name = "wm8994-aif1",
+#ifndef CONFIG_SND_SOC_SAMSUNG_USE_DMA_WRAPPER
+ .platform_name = "samsung-audio-idma",
+#else
+ .platform_name = "samsung-audio",
+#endif
+ .codec_name = "wm8994-codec",
+ .init = zest_wm1811_init_paiftx,
+ .ops = &zest_wm1811_aif1_ops,
+ },
+ {
+ .name = "ZEST_WM1811 Voice",
+ .stream_name = "Voice Tx/Rx",
+ .cpu_dai_name = "zest.cp",
+ .codec_dai_name = "wm8994-aif2",
+ .platform_name = "snd-soc-dummy",
+ .codec_name = "wm8994-codec",
+ .ops = &zest_wm1811_aif2_ops,
+ .ignore_suspend = 1,
+ },
+ {
+ .name = "ZEST_WM1811 BT",
+ .stream_name = "BT Tx/Rx",
+ .cpu_dai_name = "zest.bt",
+ .codec_dai_name = "wm8994-aif3",
+ .platform_name = "snd-soc-dummy",
+ .codec_name = "wm8994-codec",
+ .ops = &zest_wm1811_aif3_ops,
+ .ignore_suspend = 1,
+ },
+ { /* Primary DAI i/f */
+ .name = "WM8994 AIF1",
+ .stream_name = "Pri_Dai",
+ .cpu_dai_name = "samsung-i2s.0",
+ .codec_dai_name = "wm8994-aif1",
+ .platform_name = "samsung-audio",
+ .codec_name = "wm8994-codec",
+ .ops = &zest_wm1811_aif1_ops,
+ },
+};
+
+static int zest_card_suspend_pre(struct snd_soc_card *card)
+{
+ struct snd_soc_codec *codec = card->rtd->codec;
+ struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
+
+#ifdef CONFIG_SND_USE_LINEOUT_SWITCH
+ struct wm1811_machine_priv *wm1811
+ = snd_soc_card_get_drvdata(codec->card);
+ if (lineout_mode == 1 &&
+ wm8994->vmid_mode == WM8994_VMID_FORCE) {
+ dev_info(codec->dev,
+ "%s: entering force vmid mode\n", __func__);
+ if (wm1811->lineout_switch_f)
+ wm1811->lineout_switch_f(0);
+ wm8994_vmid_mode(codec, WM8994_VMID_NORMAL);
+ }
+#endif
+#ifdef CONFIG_SEC_DEV_JACK
+ snd_soc_dapm_disable_pin(&codec->dapm, "AIF1CLK");
+#endif
+
+ return 0;
+}
+
+static int zest_card_suspend_post(struct snd_soc_card *card)
+{
+ struct snd_soc_codec *codec = card->rtd->codec;
+ struct snd_soc_dai *aif1_dai = card->rtd[0].codec_dai;
+ struct snd_soc_dai *aif2_dai = card->rtd[1].codec_dai;
+ int ret;
+
+ if (!codec->active) {
+ ret = snd_soc_dai_set_sysclk(aif2_dai,
+ WM8994_SYSCLK_MCLK2,
+ MIDAS_DEFAULT_MCLK2,
+ SND_SOC_CLOCK_IN);
+
+ if (ret < 0)
+ dev_err(codec->dev, "Unable to switch to MCLK2: %d\n",
+ ret);
+
+ ret = snd_soc_dai_set_pll(aif2_dai, WM8994_FLL2, 0, 0, 0);
+
+ if (ret < 0)
+ dev_err(codec->dev, "Unable to stop FLL2\n");
+
+ ret = snd_soc_dai_set_sysclk(aif1_dai,
+ WM8994_SYSCLK_MCLK2,
+ MIDAS_DEFAULT_MCLK2,
+ SND_SOC_CLOCK_IN);
+ if (ret < 0)
+ dev_err(codec->dev, "Unable to switch to MCLK2\n");
+
+ ret = snd_soc_dai_set_pll(aif1_dai, WM8994_FLL1, 0, 0, 0);
+
+ if (ret < 0)
+ dev_err(codec->dev, "Unable to stop FLL1\n");
+
+ midas_snd_set_mclk(false, true);
+ }
+
+#ifdef CONFIG_ARCH_EXYNOS5
+ exynos5_sys_powerdown_xxti_control(midas_snd_get_mclk() ? 1 : 0);
+#else /* for CONFIG_ARCH_EXYNOS5 */
+ exynos4_sys_powerdown_xusbxti_control(midas_snd_get_mclk() ? 1 : 0);
+#endif
+
+ return 0;
+}
+
+static int zest_card_resume_pre(struct snd_soc_card *card)
+{
+ struct snd_soc_codec *codec = card->rtd->codec;
+ struct snd_soc_dai *aif1_dai = card->rtd[0].codec_dai;
+ int ret;
+
+ midas_snd_set_mclk(true, false);
+
+ /* Switch the FLL */
+ ret = snd_soc_dai_set_pll(aif1_dai, WM8994_FLL1,
+ WM8994_FLL_SRC_MCLK1,
+ MIDAS_DEFAULT_MCLK1,
+ MIDAS_DEFAULT_SYNC_CLK);
+
+ if (ret < 0)
+ dev_err(aif1_dai->dev, "Unable to start FLL1: %d\n", ret);
+
+ /* Then switch AIF1CLK to it */
+ ret = snd_soc_dai_set_sysclk(aif1_dai,
+ WM8994_SYSCLK_FLL1,
+ MIDAS_DEFAULT_SYNC_CLK,
+ SND_SOC_CLOCK_IN);
+
+ if (ret < 0)
+ dev_err(aif1_dai->dev, "Unable to switch to FLL1: %d\n", ret);
+
+ return 0;
+}
+
+static int zest_card_resume_post(struct snd_soc_card *card)
+{
+ struct snd_soc_codec *codec = card->rtd->codec;
+ struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
+ int reg = 0;
+
+#ifdef CONFIG_SND_USE_LINEOUT_SWITCH
+ struct wm1811_machine_priv *wm1811
+ = snd_soc_card_get_drvdata(codec->card);
+
+ if (lineout_mode == 1 &&
+ wm8994->vmid_mode == WM8994_VMID_NORMAL) {
+ dev_info(codec->dev,
+ "%s: entering normal vmid mode\n", __func__);
+ wm8994_vmid_mode(codec, WM8994_VMID_FORCE);
+ if (wm1811->lineout_switch_f)
+ wm1811->lineout_switch_f(1);
+ }
+#endif
+ /* workaround for jack detection
+ * sometimes WM8994_GPIO_1 type changed wrong function type
+ * so if type mismatched, update to IRQ type
+ */
+ reg = snd_soc_read(codec, WM8994_GPIO_1);
+
+ if ((reg & WM8994_GPN_FN_MASK) != WM8994_GP_FN_IRQ) {
+ dev_err(codec->dev, "%s: GPIO1 type 0x%x\n", __func__, reg);
+ snd_soc_write(codec, WM8994_GPIO_1, WM8994_GP_FN_IRQ);
+ }
+
+#ifdef CONFIG_SEC_DEV_JACK
+ snd_soc_dapm_force_enable_pin(&codec->dapm, "AIF1CLK");
+#endif
+
+ return 0;
+}
+
+static struct snd_soc_card zest_card = {
+ .name = "ZEST_WM1811",
+ .dai_link = zest_dai,
+
+ /* If you want to use sec_fifo device,
+ * changes the num_link = 2 or ARRAY_SIZE(zest_dai). */
+ .num_links = ARRAY_SIZE(zest_dai),
+
+ .suspend_pre = zest_card_suspend_pre,
+ .suspend_post = zest_card_suspend_post,
+ .resume_pre = zest_card_resume_pre,
+ .resume_post = zest_card_resume_post
+};
+
+static void zest_jackdet_set_mode(struct snd_soc_codec *codec, u16 mode)
+{
+ struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
+
+ if (!wm8994->jackdet || !wm8994->micdet[0].jack)
+ return;
+
+ if (wm8994->active_refcount)
+ mode = WM1811_JACKDET_MODE_AUDIO;
+
+ if (mode == wm8994->jackdet_mode)
+ return;
+
+ wm8994->jackdet_mode = mode;
+
+ /* Always use audio mode to detect while the system is active */
+ if (mode != WM1811_JACKDET_MODE_NONE)
+ mode = WM1811_JACKDET_MODE_AUDIO;
+
+ snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
+ WM1811_JACKDET_MODE_MASK, mode);
+}
+
+static irqreturn_t zest_g_det_thread(int irq, void *data)
+{
+ struct wm1811_machine_priv *wm1811 = data;
+ struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(wm1811->codec);
+ struct snd_soc_codec *codec = wm8994->codec;
+
+
+ if (wm1811->get_g_det_value_f()) {
+
+ pr_info("%s: G_DET_N GPIO is High!!!!", __func__);
+
+ mutex_lock(&wm8994->accdet_lock);
+
+ snd_soc_update_bits(codec, WM8958_MICBIAS2,
+ WM8958_MICB2_DISCH, WM8958_MICB2_DISCH);
+
+ /* Enable debounce while removed */
+ snd_soc_update_bits(codec, WM1811_JACKDET_CTRL,
+ WM1811_JACKDET_DB, WM1811_JACKDET_DB);
+
+ wm8994->mic_detecting = false;
+ wm8994->jack_mic = false;
+
+ snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
+ WM8958_MICD_ENA, 0);
+
+ zest_jackdet_set_mode(codec, WM1811_JACKDET_MODE_JACK);
+
+ mutex_unlock(&wm8994->accdet_lock);
+
+ mutex_lock(&codec->mutex);
+
+ snd_soc_dapm_disable_pin(&codec->dapm, "MICBIAS2");
+ snd_soc_dapm_sync(&codec->dapm);
+
+ mutex_unlock(&codec->mutex);
+
+ snd_soc_jack_report(wm8994->micdet[0].jack, 0,
+ SND_JACK_MECHANICAL | SND_JACK_HEADSET |
+ wm8994->btn_mask);
+ } else {
+ pr_info("%s: G_DET_N GPIO is Low!!!!", __func__);
+
+ handle_nested_irq(WM1811_JACKDET_IRQ_NUM);
+ msleep(100);
+ handle_nested_irq(WM1811_MIC_IRQ_NUM);
+ }
+
+ return IRQ_HANDLED;
+
+}
+
+static int __init zest_audio_init(void)
+{
+ struct wm1811_machine_priv *wm1811;
+ const struct exynos_sound_platform_data *sound_pdata;
+ int ret;
+
+ wm1811 = kzalloc(sizeof *wm1811, GFP_KERNEL);
+ if (!wm1811) {
+ pr_err("Failed to allocate memory\n");
+ ret = -ENOMEM;
+ goto err_kzalloc;
+ }
+ snd_soc_card_set_drvdata(&zest_card, wm1811);
+
+ zest_snd_device = platform_device_alloc("soc-audio", -1);
+ if (!zest_snd_device) {
+ ret = -ENOMEM;
+ goto err_device_alloc;
+ }
+
+ ret = snd_soc_register_dais(&zest_snd_device->dev, zest_ext_dai,
+ ARRAY_SIZE(zest_ext_dai));
+ if (ret != 0)
+ pr_err("Failed to register external DAIs: %d\n", ret);
+
+ platform_set_drvdata(zest_snd_device, &zest_card);
+
+ ret = platform_device_add(zest_snd_device);
+ if (ret)
+ platform_device_put(zest_snd_device);
+
+ sound_pdata = exynos_sound_get_platform_data();
+ if (!sound_pdata) {
+ pr_info("%s: don't use sound pdata\n", __func__);
+ goto err_out_free;
+ }
+
+#ifdef CONFIG_USE_ADC_DET
+ if (sound_pdata->zones) {
+ wm1811->zones = sound_pdata->zones;
+ wm1811->num_zones = sound_pdata->num_zones;
+ }
+ pr_info("%s:use_jackdet_type = %d\n", __func__,
+ sound_pdata->use_jackdet_type);
+ wm1811->use_jackdet_type = sound_pdata->use_jackdet_type;
+#endif
+ if (sound_pdata->set_lineout_switch)
+ wm1811->lineout_switch_f = sound_pdata->set_lineout_switch;
+
+ if (sound_pdata->set_ext_main_mic)
+ wm1811->set_main_mic_f = sound_pdata->set_ext_main_mic;
+
+ if (sound_pdata->set_ext_sub_mic)
+ wm1811->set_sub_mic_f = sound_pdata->set_ext_sub_mic;
+
+ if (sound_pdata->get_ground_det_value)
+ wm1811->get_g_det_value_f = sound_pdata->get_ground_det_value;
+
+ if (sound_pdata->get_ground_det_irq_num) {
+ wm1811->get_g_det_irq_num_f =
+ sound_pdata->get_ground_det_irq_num;
+ ret = request_threaded_irq(wm1811->get_g_det_irq_num_f(), NULL,
+ zest_g_det_thread, IRQF_TRIGGER_RISING |
+ IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
+ "g_det irq", wm1811);
+ if (ret != 0)
+ pr_err("%s: Failed to register IRQ\n", __func__);
+
+ /* to handle insert/removal when we're sleeping in a call */
+ ret = enable_irq_wake(wm1811->get_g_det_irq_num_f());
+ if (ret)
+ pr_err("%s : Failed to enable_irq_wake\n", __func__);
+ }
+
+ return ret;
+
+err_out_free:
+ platform_device_put(zest_snd_device);
+err_device_alloc:
+ kfree(wm1811);
+err_kzalloc:
+ return ret;
+}
+module_init(zest_audio_init);
+
+static void __exit zest_audio_exit(void)
+{
+ struct snd_soc_card *card = &zest_card;
+ struct wm1811_machine_priv *wm1811 = snd_soc_card_get_drvdata(card);
+
+#ifdef CONFIG_USE_ADC_DET
+ s3c_adc_release(wm1811->padc);
+#endif
+ platform_device_unregister(zest_snd_device);
+ kfree(wm1811);
+}
+module_exit(zest_audio_exit);
+
+MODULE_AUTHOR("MIN LEE <min47.lee@samsung.com>");
+MODULE_DESCRIPTION("ALSA SoC ZEST WM1811");
+MODULE_LICENSE("GPL");