diff --git a/arch/arm/mach-msm/board-8064.c b/arch/arm/mach-msm/board-8064.c index 4dcc626b26c..a903cadad50 100644 --- a/arch/arm/mach-msm/board-8064.c +++ b/arch/arm/mach-msm/board-8064.c @@ -466,27 +466,28 @@ static struct platform_device *common_devices[] __initdata = { #ifdef CONFIG_HW_RANDOM_MSM &apq8064_device_rng, #endif - &msm_pcm, - &msm_pcm_routing, - &msm_cpudai0, - &msm_cpudai1, - &msm_cpudai_hdmi_rx, - &msm_cpudai_bt_rx, - &msm_cpudai_bt_tx, - &msm_cpudai_fm_rx, - &msm_cpudai_fm_tx, - &msm_cpu_fe, - &msm_stub_codec, - &msm_voice, - &msm_voip, - &msm_lpa_pcm, - &msm_cpudai_afe_01_rx, - &msm_cpudai_afe_01_tx, - &msm_cpudai_afe_02_rx, - &msm_cpudai_afe_02_tx, - &msm_pcm_afe, - &msm_cpudai_auxpcm_rx, - &msm_cpudai_auxpcm_tx, + &apq_pcm, + &apq_pcm_routing, + &apq_cpudai0, + &apq_cpudai1, + &apq_cpudai_hdmi_rx, + &apq_cpudai_bt_rx, + &apq_cpudai_bt_tx, + &apq_cpudai_fm_rx, + &apq_cpudai_fm_tx, + &apq_cpu_fe, + &apq_stub_codec, + &apq_voice, + &apq_voip, + &apq_lpa_pcm, + &apq_pcm_hostless, + &apq_cpudai_afe_01_rx, + &apq_cpudai_afe_01_tx, + &apq_cpudai_afe_02_rx, + &apq_cpudai_afe_02_tx, + &apq_pcm_afe, + &apq_cpudai_auxpcm_rx, + &apq_cpudai_auxpcm_tx, }; static struct platform_device *sim_devices[] __initdata = { diff --git a/arch/arm/mach-msm/devices-8064.c b/arch/arm/mach-msm/devices-8064.c index 7420bc01925..b0f4c9f949d 100644 --- a/arch/arm/mach-msm/devices-8064.c +++ b/arch/arm/mach-msm/devices-8064.c @@ -22,6 +22,8 @@ #include #include #include +#include +#include #include "clock.h" #include "devices.h" #include "msm_watchdog.h" @@ -206,6 +208,134 @@ struct platform_device apq8064_device_qup_spi_gsbi5 = { .resource = resources_qup_spi_gsbi5, }; +struct platform_device apq_pcm = { + .name = "msm-pcm-dsp", + .id = -1, +}; + +struct platform_device apq_pcm_routing = { + .name = "msm-pcm-routing", + .id = -1, +}; + +struct platform_device apq_cpudai0 = { + .name = "msm-dai-q6", + .id = 0x4000, +}; + +struct platform_device apq_cpudai1 = { + .name = "msm-dai-q6", + .id = 0x4001, +}; + +struct platform_device apq_cpudai_hdmi_rx = { + .name = "msm-dai-q6", + .id = 8, +}; + +struct platform_device apq_cpudai_bt_rx = { + .name = "msm-dai-q6", + .id = 0x3000, +}; + +struct platform_device apq_cpudai_bt_tx = { + .name = "msm-dai-q6", + .id = 0x3001, +}; + +struct platform_device apq_cpudai_fm_rx = { + .name = "msm-dai-q6", + .id = 0x3004, +}; + +struct platform_device apq_cpudai_fm_tx = { + .name = "msm-dai-q6", + .id = 0x3005, +}; + +/* + * Machine specific data for AUX PCM Interface + * which the driver will be unware of. + */ +struct msm_dai_auxpcm_pdata apq_auxpcm_rx_pdata = { + .clk = "pcm_clk", + .mode = AFE_PCM_CFG_MODE_PCM, + .sync = AFE_PCM_CFG_SYNC_INT, + .frame = AFE_PCM_CFG_FRM_256BPF, + .quant = AFE_PCM_CFG_QUANT_LINEAR_NOPAD, + .slot = 0, + .data = AFE_PCM_CFG_CDATAOE_MASTER, + .pcm_clk_rate = 2048000, +}; + +struct platform_device apq_cpudai_auxpcm_rx = { + .name = "msm-dai-q6", + .id = 2, + .dev = { + .platform_data = &apq_auxpcm_rx_pdata, + }, +}; + +struct platform_device apq_cpudai_auxpcm_tx = { + .name = "msm-dai-q6", + .id = 3, +}; + +struct platform_device apq_cpu_fe = { + .name = "msm-dai-fe", + .id = -1, +}; + +struct platform_device apq_stub_codec = { + .name = "msm-stub-codec", + .id = 1, +}; + +struct platform_device apq_voice = { + .name = "msm-pcm-voice", + .id = -1, +}; + +struct platform_device apq_voip = { + .name = "msm-voip-dsp", + .id = -1, +}; + +struct platform_device apq_lpa_pcm = { + .name = "msm-pcm-lpa", + .id = -1, +}; + +struct platform_device apq_pcm_hostless = { + .name = "msm-pcm-hostless", + .id = -1, +}; + +struct platform_device apq_cpudai_afe_01_rx = { + .name = "msm-dai-q6", + .id = 0xE0, +}; + +struct platform_device apq_cpudai_afe_01_tx = { + .name = "msm-dai-q6", + .id = 0xF0, +}; + +struct platform_device apq_cpudai_afe_02_rx = { + .name = "msm-dai-q6", + .id = 0xF1, +}; + +struct platform_device apq_cpudai_afe_02_tx = { + .name = "msm-dai-q6", + .id = 0xE1, +}; + +struct platform_device apq_pcm_afe = { + .name = "msm-pcm-afe", + .id = -1, +}; + static struct resource resources_ssbi_pmic1[] = { { .start = MSM_PMIC1_SSBI_CMD_PHYS, diff --git a/arch/arm/mach-msm/devices.h b/arch/arm/mach-msm/devices.h index 9743ee212a7..264e9a95888 100644 --- a/arch/arm/mach-msm/devices.h +++ b/arch/arm/mach-msm/devices.h @@ -179,6 +179,29 @@ extern struct platform_device msm_8960_q6_lpass; extern struct platform_device msm_8960_q6_mss_fw; extern struct platform_device msm_8960_q6_mss_sw; +extern struct platform_device apq_pcm; +extern struct platform_device apq_pcm_routing; +extern struct platform_device apq_cpudai0; +extern struct platform_device apq_cpudai1; +extern struct platform_device apq_cpudai_hdmi_rx; +extern struct platform_device apq_cpudai_bt_rx; +extern struct platform_device apq_cpudai_bt_tx; +extern struct platform_device apq_cpudai_fm_rx; +extern struct platform_device apq_cpudai_fm_tx; +extern struct platform_device apq_cpudai_auxpcm_rx; +extern struct platform_device apq_cpudai_auxpcm_tx; +extern struct platform_device apq_cpu_fe; +extern struct platform_device apq_stub_codec; +extern struct platform_device apq_voice; +extern struct platform_device apq_voip; +extern struct platform_device apq_lpa_pcm; +extern struct platform_device apq_pcm_hostless; +extern struct platform_device apq_cpudai_afe_01_rx; +extern struct platform_device apq_cpudai_afe_01_tx; +extern struct platform_device apq_cpudai_afe_02_rx; +extern struct platform_device apq_cpudai_afe_02_tx; +extern struct platform_device apq_pcm_afe; + extern struct platform_device *msm_footswitch_devices[]; extern unsigned msm_num_footswitch_devices; diff --git a/sound/soc/msm/Makefile b/sound/soc/msm/Makefile index 3b257a6031c..c583ce23d49 100644 --- a/sound/soc/msm/Makefile +++ b/sound/soc/msm/Makefile @@ -61,7 +61,7 @@ obj-$(CONFIG_SND_SOC_VOICE) += msm-pcm-voice.o msm-pcm-voip.o snd-soc-qdsp6-objs += msm-pcm-lpa.o msm-pcm-afe.o obj-$(CONFIG_SND_SOC_QDSP6) += snd-soc-qdsp6.o -snd-soc-msm8960-objs := msm8960.o +snd-soc-msm8960-objs := msm8960.o apq8064.o obj-$(CONFIG_SND_SOC_MSM8960) += snd-soc-msm8960.o # Generic MSM drivers diff --git a/sound/soc/msm/apq8064.c b/sound/soc/msm/apq8064.c new file mode 100644 index 00000000000..870bd200f62 --- /dev/null +++ b/sound/soc/msm/apq8064.c @@ -0,0 +1,1161 @@ +/* Copyright (c) 2011, Code Aurora Forum. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 and + * only version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "msm-pcm-routing.h" +#include "../codecs/wcd9310.h" + +/* 8064 machine driver */ + +#define PM8921_GPIO_BASE NR_GPIO_IRQS +#define PM8921_GPIO_PM_TO_SYS(pm_gpio) (pm_gpio - 1 + PM8921_GPIO_BASE) + +#define MSM8064_SPK_ON 1 +#define MSM8064_SPK_OFF 0 + +#define MSM_SLIM_0_RX_MAX_CHANNELS 2 +#define MSM_SLIM_0_TX_MAX_CHANNELS 4 + +#define BTSCO_RATE_8KHZ 8000 +#define BTSCO_RATE_16KHZ 16000 + +#define BOTTOM_SPK_AMP_POS 0x1 +#define BOTTOM_SPK_AMP_NEG 0x2 +#define TOP_SPK_AMP_POS 0x4 +#define TOP_SPK_AMP_NEG 0x8 + +#define GPIO_AUX_PCM_DOUT 43 +#define GPIO_AUX_PCM_DIN 44 +#define GPIO_AUX_PCM_SYNC 45 +#define GPIO_AUX_PCM_CLK 46 + +static u32 top_spk_pamp_gpio = PM8921_GPIO_PM_TO_SYS(18); +static u32 bottom_spk_pamp_gpio = PM8921_GPIO_PM_TO_SYS(19); +static int msm_spk_control; +static int msm_ext_bottom_spk_pamp; +static int msm_ext_top_spk_pamp; +static int msm_slim_0_rx_ch = 1; +static int msm_slim_0_tx_ch = 1; + +static int msm_btsco_rate = BTSCO_RATE_8KHZ; +static int msm_btsco_ch = 1; + +struct tabla_mbhc_calibration tabla_calib = { + .bias = TABLA_MICBIAS2, + .tldoh = 100, + .bg_fast_settle = 100, + .mic_current = TABLA_PID_MIC_5_UA, + .mic_pid = 100, + .hph_current = TABLA_PID_MIC_5_UA, + .setup_plug_removal_delay = 1000000, + .shutdown_plug_removal = 100000, +}; + +static struct clk *codec_clk; +static int clk_users; + +static int msm_headset_gpios_configured; + +static struct snd_soc_jack hs_jack; +static struct snd_soc_jack button_jack; + +static void msm_enable_ext_spk_amp_gpio(u32 spk_amp_gpio) +{ + int ret = 0; + + struct pm_gpio param = { + .direction = PM_GPIO_DIR_OUT, + .output_buffer = PM_GPIO_OUT_BUF_CMOS, + .output_value = 1, + .pull = PM_GPIO_PULL_NO, + .vin_sel = PM_GPIO_VIN_S4, + .out_strength = PM_GPIO_STRENGTH_MED, + . + function = PM_GPIO_FUNC_NORMAL, + }; + + if (spk_amp_gpio == bottom_spk_pamp_gpio) { + + ret = gpio_request(bottom_spk_pamp_gpio, "BOTTOM_SPK_AMP"); + if (ret) { + pr_err("%s: Error requesting BOTTOM SPK AMP GPIO %u\n", + __func__, bottom_spk_pamp_gpio); + return; + } + ret = pm8xxx_gpio_config(bottom_spk_pamp_gpio, ¶m); + if (ret) + pr_err("%s: Failed to configure Bottom Spk Ampl" + " gpio %u\n", __func__, bottom_spk_pamp_gpio); + else { + pr_debug("%s: enable Bottom spkr amp gpio\n", __func__); + gpio_direction_output(bottom_spk_pamp_gpio, 1); + } + + } else if (spk_amp_gpio == top_spk_pamp_gpio) { + + ret = gpio_request(top_spk_pamp_gpio, "TOP_SPK_AMP"); + if (ret) { + pr_err("%s: Error requesting GPIO %d\n", __func__, + top_spk_pamp_gpio); + return; + } + ret = pm8xxx_gpio_config(top_spk_pamp_gpio, ¶m); + if (ret) + pr_err("%s: Failed to configure Top Spk Ampl" + " gpio %u\n", __func__, top_spk_pamp_gpio); + else { + pr_debug("%s: enable Top spkr amp gpio\n", __func__); + gpio_direction_output(top_spk_pamp_gpio, 1); + } + } else { + pr_err("%s: ERROR : Invalid External Speaker Ampl GPIO." + " gpio = %u\n", __func__, spk_amp_gpio); + return; + } +} + +static void msm_ext_spk_power_amp_on(u32 spk) +{ + if (spk & (BOTTOM_SPK_AMP_POS | BOTTOM_SPK_AMP_NEG)) { + + if ((msm_ext_bottom_spk_pamp & BOTTOM_SPK_AMP_POS) && + (msm_ext_bottom_spk_pamp & BOTTOM_SPK_AMP_NEG)) { + + pr_debug("%s() External Bottom Speaker Ampl already " + "turned on. spk = 0x%08x\n", __func__, spk); + return; + } + + msm_ext_bottom_spk_pamp |= spk; + + if ((msm_ext_bottom_spk_pamp & BOTTOM_SPK_AMP_POS) && + (msm_ext_bottom_spk_pamp & BOTTOM_SPK_AMP_NEG)) { + + msm_enable_ext_spk_amp_gpio(bottom_spk_pamp_gpio); + pr_debug("%s: slepping 4 ms after turning on external " + " Bottom Speaker Ampl\n", __func__); + usleep_range(4000, 4000); + } + + } else if (spk & (TOP_SPK_AMP_POS | TOP_SPK_AMP_NEG)) { + + if ((msm_ext_top_spk_pamp & TOP_SPK_AMP_POS) && + (msm_ext_top_spk_pamp & TOP_SPK_AMP_NEG)) { + + pr_debug("%s() External Top Speaker Ampl already" + "turned on. spk = 0x%08x\n", __func__, spk); + return; + } + + msm_ext_top_spk_pamp |= spk; + + if ((msm_ext_top_spk_pamp & TOP_SPK_AMP_POS) && + (msm_ext_top_spk_pamp & TOP_SPK_AMP_NEG)) { + + msm_enable_ext_spk_amp_gpio(top_spk_pamp_gpio); + pr_debug("%s: sleeping 4 ms after turning on " + " external Top Speaker Ampl\n", __func__); + usleep_range(4000, 4000); + } + } else { + + pr_err("%s: ERROR : Invalid External Speaker Ampl. spk = 0x%08x\n", + __func__, spk); + return; + } +} + +static void msm_ext_spk_power_amp_off(u32 spk) +{ + if (spk & (BOTTOM_SPK_AMP_POS | BOTTOM_SPK_AMP_NEG)) { + + if (!msm_ext_bottom_spk_pamp) + return; + + gpio_direction_output(bottom_spk_pamp_gpio, 0); + gpio_free(bottom_spk_pamp_gpio); + msm_ext_bottom_spk_pamp = 0; + + pr_debug("%s: sleeping 4 ms after turning off external Bottom" + " Speaker Ampl\n", __func__); + + usleep_range(4000, 4000); + + } else if (spk & (TOP_SPK_AMP_POS | TOP_SPK_AMP_NEG)) { + + if (!msm_ext_top_spk_pamp) + return; + + gpio_direction_output(top_spk_pamp_gpio, 0); + gpio_free(top_spk_pamp_gpio); + msm_ext_top_spk_pamp = 0; + + pr_debug("%s: sleeping 4 ms after turning off external Top" + " Spkaker Ampl\n", __func__); + + usleep_range(4000, 4000); + } else { + + pr_err("%s: ERROR : Invalid Ext Spk Ampl. spk = 0x%08x\n", + __func__, spk); + return; + } +} + +static void msm_ext_control(struct snd_soc_codec *codec) +{ + struct snd_soc_dapm_context *dapm = &codec->dapm; + + pr_debug("%s: msm_spk_control = %d", __func__, msm_spk_control); + if (msm_spk_control == MSM8064_SPK_ON) { + snd_soc_dapm_enable_pin(dapm, "Ext Spk Bottom Pos"); + snd_soc_dapm_enable_pin(dapm, "Ext Spk Bottom Neg"); + snd_soc_dapm_enable_pin(dapm, "Ext Spk Top Pos"); + snd_soc_dapm_enable_pin(dapm, "Ext Spk Top Neg"); + } else { + snd_soc_dapm_disable_pin(dapm, "Ext Spk Bottom Pos"); + snd_soc_dapm_disable_pin(dapm, "Ext Spk Bottom Neg"); + snd_soc_dapm_disable_pin(dapm, "Ext Spk Top Pos"); + snd_soc_dapm_disable_pin(dapm, "Ext Spk Top Neg"); + } + + snd_soc_dapm_sync(dapm); +} + +static int msm_get_spk(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + pr_debug("%s: msm_spk_control = %d", __func__, msm_spk_control); + ucontrol->value.integer.value[0] = msm_spk_control; + return 0; +} +static int msm_set_spk(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); + + pr_debug("%s()\n", __func__); + if (msm_spk_control == ucontrol->value.integer.value[0]) + return 0; + + msm_spk_control = ucontrol->value.integer.value[0]; + msm_ext_control(codec); + return 1; +} +static int msm_spkramp_event(struct snd_soc_dapm_widget *w, + struct snd_kcontrol *k, int event) +{ + pr_debug("%s() %x\n", __func__, SND_SOC_DAPM_EVENT_ON(event)); + + if (SND_SOC_DAPM_EVENT_ON(event)) { + if (!strncmp(w->name, "Ext Spk Bottom Pos", 18)) + msm_ext_spk_power_amp_on(BOTTOM_SPK_AMP_POS); + else if (!strncmp(w->name, "Ext Spk Bottom Neg", 18)) + msm_ext_spk_power_amp_on(BOTTOM_SPK_AMP_NEG); + else if (!strncmp(w->name, "Ext Spk Top Pos", 15)) + msm_ext_spk_power_amp_on(TOP_SPK_AMP_POS); + else if (!strncmp(w->name, "Ext Spk Top Neg", 15)) + msm_ext_spk_power_amp_on(TOP_SPK_AMP_NEG); + else { + pr_err("%s() Invalid Speaker Widget = %s\n", + __func__, w->name); + return -EINVAL; + } + + } else { + if (!strncmp(w->name, "Ext Spk Bottom Pos", 18)) + msm_ext_spk_power_amp_off(BOTTOM_SPK_AMP_POS); + else if (!strncmp(w->name, "Ext Spk Bottom Neg", 18)) + msm_ext_spk_power_amp_off(BOTTOM_SPK_AMP_NEG); + else if (!strncmp(w->name, "Ext Spk Top Pos", 15)) + msm_ext_spk_power_amp_off(TOP_SPK_AMP_POS); + else if (!strncmp(w->name, "Ext Spk Top Neg", 15)) + msm_ext_spk_power_amp_off(TOP_SPK_AMP_NEG); + else { + pr_err("%s() Invalid Speaker Widget = %s\n", + __func__, w->name); + return -EINVAL; + } + } + return 0; +} + +static int msm_mclk_event(struct snd_soc_dapm_widget *w, + struct snd_kcontrol *kcontrol, int event) +{ + pr_debug("%s: event = %d\n", __func__, event); + + switch (event) { + case SND_SOC_DAPM_PRE_PMU: + + clk_users++; + pr_debug("%s: clk_users = %d\n", __func__, clk_users); + + if (clk_users != 1) + return 0; + + codec_clk = clk_get(NULL, "i2s_spkr_osr_clk"); + if (codec_clk) { + clk_set_rate(codec_clk, 12288000); + clk_enable(codec_clk); + tabla_mclk_enable(w->codec, 1); + + } else { + pr_err("%s: Error setting Tabla MCLK\n", __func__); + clk_users--; + return -EINVAL; + } + break; + case SND_SOC_DAPM_POST_PMD: + + pr_debug("%s: clk_users = %d\n", __func__, clk_users); + + if (clk_users == 0) + return 0; + + clk_users--; + + if (!clk_users) { + pr_debug("%s: disabling MCLK. clk_users = %d\n", + __func__, clk_users); + + clk_disable(codec_clk); + clk_put(codec_clk); + tabla_mclk_enable(w->codec, 0); + } + break; + } + return 0; +} + +static const struct snd_soc_dapm_widget msm_dapm_widgets[] = { + + SND_SOC_DAPM_SUPPLY("MCLK", SND_SOC_NOPM, 0, 0, + msm_mclk_event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), + + SND_SOC_DAPM_SPK("Ext Spk Bottom Pos", msm_spkramp_event), + SND_SOC_DAPM_SPK("Ext Spk Bottom Neg", msm_spkramp_event), + + SND_SOC_DAPM_SPK("Ext Spk Top Pos", msm_spkramp_event), + SND_SOC_DAPM_SPK("Ext Spk Top Neg", msm_spkramp_event), + + SND_SOC_DAPM_MIC("Handset Mic", NULL), + SND_SOC_DAPM_MIC("Headset Mic", NULL), + SND_SOC_DAPM_MIC("Digital Mic1", NULL), + SND_SOC_DAPM_MIC("ANCRight Headset Mic", NULL), + SND_SOC_DAPM_MIC("ANCLeft Headset Mic", NULL), + + SND_SOC_DAPM_MIC("Digital Mic1", NULL), + SND_SOC_DAPM_MIC("Digital Mic2", NULL), + SND_SOC_DAPM_MIC("Digital Mic3", NULL), + SND_SOC_DAPM_MIC("Digital Mic4", NULL), + SND_SOC_DAPM_MIC("Digital Mic5", NULL), + SND_SOC_DAPM_MIC("Digital Mic6", NULL), + +}; + +static const struct snd_soc_dapm_route common_audio_map[] = { + + {"RX_BIAS", NULL, "MCLK"}, + {"LDO_H", NULL, "MCLK"}, + + /* Speaker path */ + {"Ext Spk Bottom Pos", NULL, "LINEOUT1"}, + {"Ext Spk Bottom Neg", NULL, "LINEOUT3"}, + + {"Ext Spk Top Pos", NULL, "LINEOUT2"}, + {"Ext Spk Top Neg", NULL, "LINEOUT4"}, + + /* Microphone path */ + {"AMIC1", NULL, "MIC BIAS1 Internal1"}, + {"MIC BIAS1 Internal1", NULL, "Handset Mic"}, + + {"AMIC2", NULL, "MIC BIAS2 External"}, + {"MIC BIAS2 External", NULL, "Headset Mic"}, + + /** + * AMIC3 and AMIC4 inputs are connected to ANC microphones + * These mics are biased differently on CDP and FLUID + * routing entries below are based on bias arrangement + * on FLUID. + */ + {"AMIC3", NULL, "MIC BIAS3 Internal1"}, + {"MIC BIAS3 Internal1", NULL, "ANCRight Headset Mic"}, + + {"AMIC4", NULL, "MIC BIAS1 Internal2"}, + {"MIC BIAS1 Internal2", NULL, "ANCLeft Headset Mic"}, + + {"HEADPHONE", NULL, "LDO_H"}, + + /** + * The digital Mic routes are setup considering + * fluid as default device. + */ + + /** + * Digital Mic1. Front Bottom left Digital Mic on Fluid and MTP. + * Digital Mic GM5 on CDP mainboard. + * Conncted to DMIC2 Input on Tabla codec. + */ + {"DMIC2", NULL, "MIC BIAS1 External"}, + {"MIC BIAS1 External", NULL, "Digital Mic1"}, + + /** + * Digital Mic2. Front Bottom right Digital Mic on Fluid and MTP. + * Digital Mic GM6 on CDP mainboard. + * Conncted to DMIC1 Input on Tabla codec. + */ + {"DMIC1", NULL, "MIC BIAS1 External"}, + {"MIC BIAS1 External", NULL, "Digital Mic2"}, + + /** + * Digital Mic3. Back Bottom Digital Mic on Fluid. + * Digital Mic GM1 on CDP mainboard. + * Conncted to DMIC4 Input on Tabla codec. + */ + {"DMIC4", NULL, "MIC BIAS3 External"}, + {"MIC BIAS3 External", NULL, "Digital Mic3"}, + + /** + * Digital Mic4. Back top Digital Mic on Fluid. + * Digital Mic GM2 on CDP mainboard. + * Conncted to DMIC3 Input on Tabla codec. + */ + {"DMIC3", NULL, "MIC BIAS3 External"}, + {"MIC BIAS3 External", NULL, "Digital Mic4"}, + + /** + * Digital Mic5. Front top Digital Mic on Fluid. + * Digital Mic GM3 on CDP mainboard. + * Conncted to DMIC5 Input on Tabla codec. + */ + {"DMIC5", NULL, "MIC BIAS4 External"}, + {"MIC BIAS4 External", NULL, "Digital Mic5"}, + + /* Tabla digital Mic6 - back bottom digital Mic on Liquid and + * bottom mic on CDP. FLUID/MTP do not have dmic6 installed. + */ + {"DMIC6", NULL, "MIC BIAS4 External"}, + {"MIC BIAS4 External", NULL, "Digital Mic6"}, +}; + +static const char *spk_function[] = {"Off", "On"}; +static const char *slim0_rx_ch_text[] = {"One", "Two"}; +static const char *slim0_tx_ch_text[] = {"One", "Two", "Three", "Four"}; + +static const struct soc_enum msm_enum[] = { + SOC_ENUM_SINGLE_EXT(2, spk_function), + SOC_ENUM_SINGLE_EXT(2, slim0_rx_ch_text), + SOC_ENUM_SINGLE_EXT(4, slim0_tx_ch_text), +}; + +static const char *btsco_rate_text[] = {"8000", "16000"}; +static const struct soc_enum msm_btsco_enum[] = { + SOC_ENUM_SINGLE_EXT(2, btsco_rate_text), +}; + +static int msm_slim_0_rx_ch_get(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + pr_debug("%s: msm_slim_0_rx_ch = %d\n", __func__, + msm_slim_0_rx_ch); + ucontrol->value.integer.value[0] = msm_slim_0_rx_ch - 1; + return 0; +} + +static int msm_slim_0_rx_ch_put(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + msm_slim_0_rx_ch = ucontrol->value.integer.value[0] + 1; + + pr_debug("%s: msm_slim_0_rx_ch = %d\n", __func__, + msm_slim_0_rx_ch); + return 1; +} + +static int msm_slim_0_tx_ch_get(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + pr_debug("%s: msm_slim_0_tx_ch = %d\n", __func__, + msm_slim_0_tx_ch); + ucontrol->value.integer.value[0] = msm_slim_0_tx_ch - 1; + return 0; +} + +static int msm_slim_0_tx_ch_put(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + msm_slim_0_tx_ch = ucontrol->value.integer.value[0] + 1; + + pr_debug("%s: msm_slim_0_tx_ch = %d\n", __func__, + msm_slim_0_tx_ch); + return 1; +} + +static int msm_btsco_rate_get(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + pr_debug("%s: msm_btsco_rate = %d", __func__, + msm_btsco_rate); + ucontrol->value.integer.value[0] = msm_btsco_rate; + return 0; +} + +static int msm_btsco_rate_put(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + switch (ucontrol->value.integer.value[0]) { + case 0: + msm_btsco_rate = BTSCO_RATE_8KHZ; + break; + case 1: + msm_btsco_rate = BTSCO_RATE_16KHZ; + break; + default: + msm_btsco_rate = BTSCO_RATE_8KHZ; + break; + } + pr_debug("%s: msm_btsco_rate = %d\n", __func__, + msm_btsco_rate); + return 0; +} + +static const struct snd_kcontrol_new tabla_msm_controls[] = { + SOC_ENUM_EXT("Speaker Function", msm_enum[0], msm_get_spk, + msm_set_spk), + SOC_ENUM_EXT("SLIM_0_RX Channels", msm_enum[1], + msm_slim_0_rx_ch_get, msm_slim_0_rx_ch_put), + SOC_ENUM_EXT("SLIM_0_TX Channels", msm_enum[2], + msm_slim_0_tx_ch_get, msm_slim_0_tx_ch_put), +}; + +static const struct snd_kcontrol_new int_btsco_rate_mixer_controls[] = { + SOC_ENUM_EXT("Internal BTSCO SampleRate", msm_btsco_enum[0], + msm_btsco_rate_get, msm_btsco_rate_put), +}; + +static int msm_btsco_init(struct snd_soc_pcm_runtime *rtd) +{ + int err = 0; + struct snd_soc_platform *platform = rtd->platform; + + err = snd_soc_add_platform_controls(platform, + int_btsco_rate_mixer_controls, + ARRAY_SIZE(int_btsco_rate_mixer_controls)); + if (err < 0) + return err; + return 0; +} + +static int msm_audrx_init(struct snd_soc_pcm_runtime *rtd) +{ + int err; + struct snd_soc_codec *codec = rtd->codec; + struct snd_soc_dapm_context *dapm = &codec->dapm; + + pr_debug("%s()\n", __func__); + + /*if (machine_is_msm_liquid()) { + top_spk_pamp_gpio = (PM8921_GPIO_PM_TO_SYS(19)); + bottom_spk_pamp_gpio = (PM8921_GPIO_PM_TO_SYS(18)); + }*/ + + rtd->pmdown_time = 0; + + err = snd_soc_add_controls(codec, tabla_msm_controls, + ARRAY_SIZE(tabla_msm_controls)); + if (err < 0) + return err; + + snd_soc_dapm_new_controls(dapm, msm_dapm_widgets, + ARRAY_SIZE(msm_dapm_widgets)); + + snd_soc_dapm_add_routes(dapm, common_audio_map, + ARRAY_SIZE(common_audio_map)); + + snd_soc_dapm_enable_pin(dapm, "Ext Spk Bottom Pos"); + snd_soc_dapm_enable_pin(dapm, "Ext Spk Bottom Neg"); + snd_soc_dapm_enable_pin(dapm, "Ext Spk Top Pos"); + snd_soc_dapm_enable_pin(dapm, "Ext Spk Top Neg"); + + snd_soc_dapm_sync(dapm); + + err = snd_soc_jack_new(codec, "Headset Jack", + (SND_JACK_HEADSET | SND_JACK_OC_HPHL | SND_JACK_OC_HPHR), + &hs_jack); + if (err) { + pr_err("failed to create new jack\n"); + return err; + } + + err = snd_soc_jack_new(codec, "Button Jack", + SND_JACK_BTN_0, &button_jack); + if (err) { + pr_err("failed to create new jack\n"); + return err; + } + + tabla_hs_detect(codec, &hs_jack, &button_jack, &tabla_calib); + + return 0; +} + +static struct snd_soc_dsp_link lpa_fe_media = { + .playback = true, + .trigger = { + SND_SOC_DSP_TRIGGER_POST, + SND_SOC_DSP_TRIGGER_POST + }, +}; + +static struct snd_soc_dsp_link fe_media = { + .playback = true, + .capture = true, + .trigger = { + SND_SOC_DSP_TRIGGER_POST, + SND_SOC_DSP_TRIGGER_POST + }, +}; + +static struct snd_soc_dsp_link slimbus0_hl_media = { + .playback = true, + .capture = true, + .trigger = { + SND_SOC_DSP_TRIGGER_POST, + SND_SOC_DSP_TRIGGER_POST + }, +}; + +static struct snd_soc_dsp_link int_fm_hl_media = { + .playback = true, + .capture = true, + .trigger = { + SND_SOC_DSP_TRIGGER_POST, + SND_SOC_DSP_TRIGGER_POST + }, +}; + +static int msm_slim_0_rx_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, + struct snd_pcm_hw_params *params) +{ + struct snd_interval *rate = hw_param_interval(params, + SNDRV_PCM_HW_PARAM_RATE); + + struct snd_interval *channels = hw_param_interval(params, + SNDRV_PCM_HW_PARAM_CHANNELS); + + pr_debug("%s()\n", __func__); + rate->min = rate->max = 48000; + channels->min = channels->max = msm_slim_0_rx_ch; + + return 0; +} + +static int msm_slim_0_tx_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, + struct snd_pcm_hw_params *params) +{ + struct snd_interval *rate = hw_param_interval(params, + SNDRV_PCM_HW_PARAM_RATE); + + struct snd_interval *channels = hw_param_interval(params, + SNDRV_PCM_HW_PARAM_CHANNELS); + + pr_debug("%s()\n", __func__); + rate->min = rate->max = 48000; + channels->min = channels->max = msm_slim_0_tx_ch; + + return 0; +} + +static int msm_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, + struct snd_pcm_hw_params *params) +{ + struct snd_interval *rate = hw_param_interval(params, + SNDRV_PCM_HW_PARAM_RATE); + + pr_debug("%s()\n", __func__); + rate->min = rate->max = 48000; + + return 0; +} + +static int msm_btsco_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, + struct snd_pcm_hw_params *params) +{ + struct snd_interval *rate = hw_param_interval(params, + SNDRV_PCM_HW_PARAM_RATE); + + struct snd_interval *channels = hw_param_interval(params, + SNDRV_PCM_HW_PARAM_CHANNELS); + + rate->min = rate->max = msm_btsco_rate; + channels->min = channels->max = msm_btsco_ch; + + return 0; +} +static int msm_auxpcm_be_params_fixup(struct snd_soc_pcm_runtime *rtd, + struct snd_pcm_hw_params *params) +{ + struct snd_interval *rate = hw_param_interval(params, + SNDRV_PCM_HW_PARAM_RATE); + + struct snd_interval *channels = hw_param_interval(params, + SNDRV_PCM_HW_PARAM_CHANNELS); + + /* PCM only supports mono output with 8khz sample rate */ + rate->min = rate->max = 8000; + channels->min = channels->max = 1; + + return 0; +} +static int msm_aux_pcm_get_gpios(void) +{ + int ret = 0; + + pr_debug("%s\n", __func__); + + ret = gpio_request(GPIO_AUX_PCM_DOUT, "AUX PCM DOUT"); + if (ret < 0) { + pr_err("%s: Failed to request gpio(%d): AUX PCM DOUT", + __func__, GPIO_AUX_PCM_DOUT); + goto fail_dout; + } + + ret = gpio_request(GPIO_AUX_PCM_DIN, "AUX PCM DIN"); + if (ret < 0) { + pr_err("%s: Failed to request gpio(%d): AUX PCM DIN", + __func__, GPIO_AUX_PCM_DIN); + goto fail_din; + } + + ret = gpio_request(GPIO_AUX_PCM_SYNC, "AUX PCM SYNC"); + if (ret < 0) { + pr_err("%s: Failed to request gpio(%d): AUX PCM SYNC", + __func__, GPIO_AUX_PCM_SYNC); + goto fail_sync; + } + ret = gpio_request(GPIO_AUX_PCM_CLK, "AUX PCM CLK"); + if (ret < 0) { + pr_err("%s: Failed to request gpio(%d): AUX PCM CLK", + __func__, GPIO_AUX_PCM_CLK); + goto fail_clk; + } + + return 0; + +fail_clk: + gpio_free(GPIO_AUX_PCM_SYNC); +fail_sync: + gpio_free(GPIO_AUX_PCM_DIN); +fail_din: + gpio_free(GPIO_AUX_PCM_DOUT); +fail_dout: + + return ret; +} + +static int msm_aux_pcm_free_gpios(void) +{ + gpio_free(GPIO_AUX_PCM_DIN); + gpio_free(GPIO_AUX_PCM_DOUT); + gpio_free(GPIO_AUX_PCM_SYNC); + gpio_free(GPIO_AUX_PCM_CLK); + + return 0; +} +static int msm_startup(struct snd_pcm_substream *substream) +{ + pr_debug("%s(): substream = %s stream = %d\n", __func__, + substream->name, substream->stream); + return 0; +} + +static int msm_auxpcm_startup(struct snd_pcm_substream *substream) +{ + int ret = 0; + + pr_debug("%s(): substream = %s\n", __func__, substream->name); + ret = msm_aux_pcm_get_gpios(); + if (ret < 0) { + pr_err("%s: Aux PCM GPIO request failed\n", __func__); + return -EINVAL; + } + return 0; +} + +static void msm_auxpcm_shutdown(struct snd_pcm_substream *substream) +{ + + pr_debug("%s(): substream = %s\n", __func__, substream->name); + msm_aux_pcm_free_gpios(); +} + +static void msm_shutdown(struct snd_pcm_substream *substream) +{ + pr_debug("%s(): substream = %s stream = %d\n", __func__, + substream->name, substream->stream); +} + +static struct snd_soc_ops msm_be_ops = { + .startup = msm_startup, + .shutdown = msm_shutdown, +}; + +static struct snd_soc_ops msm_auxpcm_be_ops = { + .startup = msm_auxpcm_startup, + .shutdown = msm_auxpcm_shutdown, +}; + +/* Digital audio interface glue - connects codec <---> CPU */ +static struct snd_soc_dai_link msm_dai[] = { + /* FrontEnd DAI Links */ + { + .name = "MSM8960 Media1", + .stream_name = "MultiMedia1", + .cpu_dai_name = "MultiMedia1", + .platform_name = "msm-pcm-dsp", + .dynamic = 1, + .dsp_link = &fe_media, + .be_id = MSM_FRONTEND_DAI_MULTIMEDIA1 + }, + { + .name = "MSM8960 Media2", + .stream_name = "MultiMedia2", + .cpu_dai_name = "MultiMedia2", + .platform_name = "msm-pcm-dsp", + .dynamic = 1, + .dsp_link = &fe_media, + .be_id = MSM_FRONTEND_DAI_MULTIMEDIA2, + }, + { + .name = "Circuit-Switch Voice", + .stream_name = "CS-Voice", + .cpu_dai_name = "CS-VOICE", + .platform_name = "msm-pcm-voice", + .dynamic = 1, + .dsp_link = &fe_media, + .be_id = MSM_FRONTEND_DAI_CS_VOICE, + .no_host_mode = SND_SOC_DAI_LINK_NO_HOST, + .ignore_suspend = 1, + }, + { + .name = "MSM VoIP", + .stream_name = "VoIP", + .cpu_dai_name = "VoIP", + .platform_name = "msm-voip-dsp", + .dynamic = 1, + .dsp_link = &fe_media, + .be_id = MSM_FRONTEND_DAI_VOIP, + }, + { + .name = "MSM8960 LPA", + .stream_name = "LPA", + .cpu_dai_name = "MultiMedia3", + .platform_name = "msm-pcm-lpa", + .dynamic = 1, + .dsp_link = &lpa_fe_media, + .be_id = MSM_FRONTEND_DAI_MULTIMEDIA3, + }, + /* Hostless PMC purpose */ + { + .name = "SLIMBUS_0 Hostless", + .stream_name = "SLIMBUS_0 Hostless", + .cpu_dai_name = "SLIMBUS0_HOSTLESS", + .platform_name = "msm-pcm-hostless", + .dynamic = 1, + .dsp_link = &slimbus0_hl_media, + .no_host_mode = SND_SOC_DAI_LINK_NO_HOST, + .ignore_suspend = 1, + /* .be_id = do not care */ + }, + { + .name = "INT_FM Hostless", + .stream_name = "INT_FM Hostless", + .cpu_dai_name = "INT_FM_HOSTLESS", + .platform_name = "msm-pcm-hostless", + .dynamic = 1, + .dsp_link = &int_fm_hl_media, + .no_host_mode = SND_SOC_DAI_LINK_NO_HOST, + .ignore_suspend = 1, + /* .be_id = do not care */ + }, + { + .name = "MSM AFE-PCM RX", + .stream_name = "AFE-PROXY RX", + .cpu_dai_name = "msm-dai-q6.241", + .codec_name = "msm-stub-codec.1", + .codec_dai_name = "msm-stub-rx", + .platform_name = "msm-pcm-afe", + .ignore_suspend = 1, + }, + { + .name = "MSM AFE-PCM TX", + .stream_name = "AFE-PROXY TX", + .cpu_dai_name = "msm-dai-q6.240", + .codec_name = "msm-stub-codec.1", + .codec_dai_name = "msm-stub-tx", + .platform_name = "msm-pcm-afe", + .ignore_suspend = 1, + }, + /* Backend DAI Links */ + { + .name = LPASS_BE_SLIMBUS_0_RX, + .stream_name = "Slimbus Playback", + .cpu_dai_name = "msm-dai-q6.16384", + .platform_name = "msm-pcm-routing", + .codec_name = "tabla_codec", + .codec_dai_name = "tabla_rx1", + .no_pcm = 1, + .be_id = MSM_BACKEND_DAI_SLIMBUS_0_RX, + .init = &msm_audrx_init, + .be_hw_params_fixup = msm_slim_0_rx_be_hw_params_fixup, + .ops = &msm_be_ops, + }, + { + .name = LPASS_BE_SLIMBUS_0_TX, + .stream_name = "Slimbus Capture", + .cpu_dai_name = "msm-dai-q6.16385", + .platform_name = "msm-pcm-routing", + .codec_name = "tabla_codec", + .codec_dai_name = "tabla_tx1", + .no_pcm = 1, + .be_id = MSM_BACKEND_DAI_SLIMBUS_0_TX, + .be_hw_params_fixup = msm_slim_0_tx_be_hw_params_fixup, + .ops = &msm_be_ops, + }, + /* Backend BT/FM DAI Links */ + { + .name = LPASS_BE_INT_BT_SCO_RX, + .stream_name = "Internal BT-SCO Playback", + .cpu_dai_name = "msm-dai-q6.12288", + .platform_name = "msm-pcm-routing", + .codec_name = "msm-stub-codec.1", + .codec_dai_name = "msm-stub-rx", + .init = &msm_btsco_init, + .no_pcm = 1, + .be_id = MSM_BACKEND_DAI_INT_BT_SCO_RX, + .be_hw_params_fixup = msm_btsco_be_hw_params_fixup, + }, + { + .name = LPASS_BE_INT_BT_SCO_TX, + .stream_name = "Internal BT-SCO Capture", + .cpu_dai_name = "msm-dai-q6.12289", + .platform_name = "msm-pcm-routing", + .codec_name = "msm-stub-codec.1", + .codec_dai_name = "msm-stub-tx", + .no_pcm = 1, + .be_id = MSM_BACKEND_DAI_INT_BT_SCO_TX, + .be_hw_params_fixup = msm_btsco_be_hw_params_fixup, + }, + { + .name = LPASS_BE_INT_FM_RX, + .stream_name = "Internal FM Playback", + .cpu_dai_name = "msm-dai-q6.12292", + .platform_name = "msm-pcm-routing", + .codec_name = "msm-stub-codec.1", + .codec_dai_name = "msm-stub-rx", + .no_pcm = 1, + .be_id = MSM_BACKEND_DAI_INT_FM_RX, + .be_hw_params_fixup = msm_be_hw_params_fixup, + }, + { + .name = LPASS_BE_INT_FM_TX, + .stream_name = "Internal FM Capture", + .cpu_dai_name = "msm-dai-q6.12293", + .platform_name = "msm-pcm-routing", + .codec_name = "msm-stub-codec.1", + .codec_dai_name = "msm-stub-tx", + .no_pcm = 1, + .be_id = MSM_BACKEND_DAI_INT_FM_TX, + .be_hw_params_fixup = msm_be_hw_params_fixup, + }, + /* HDMI BACK END DAI Link */ + { + .name = LPASS_BE_HDMI, + .stream_name = "HDMI Playback", + .cpu_dai_name = "msm-dai-q6.8", + .platform_name = "msm-pcm-routing", + .codec_name = "msm-stub-codec.1", + .codec_dai_name = "msm-stub-rx", + .no_pcm = 1, + .no_codec = 1, + .be_id = MSM_BACKEND_DAI_HDMI_RX, + .be_hw_params_fixup = msm_be_hw_params_fixup, + }, + /* Backend AFE DAI Links */ + { + .name = LPASS_BE_AFE_PCM_RX, + .stream_name = "AFE Playback", + .cpu_dai_name = "msm-dai-q6.224", + .platform_name = "msm-pcm-routing", + .codec_name = "msm-stub-codec.1", + .codec_dai_name = "msm-stub-rx", + .no_codec = 1, + .no_pcm = 1, + .be_id = MSM_BACKEND_DAI_AFE_PCM_RX, + }, + { + .name = LPASS_BE_AFE_PCM_TX, + .stream_name = "AFE Capture", + .cpu_dai_name = "msm-dai-q6.225", + .platform_name = "msm-pcm-routing", + .codec_name = "msm-stub-codec.1", + .codec_dai_name = "msm-stub-tx", + .no_codec = 1, + .no_pcm = 1, + .be_id = MSM_BACKEND_DAI_AFE_PCM_TX, + }, + /* AUX PCM Backend DAI Links */ + { + .name = LPASS_BE_AUXPCM_RX, + .stream_name = "AUX PCM Playback", + .cpu_dai_name = "msm-dai-q6.2", + .platform_name = "msm-pcm-routing", + .codec_name = "msm-stub-codec.1", + .codec_dai_name = "msm-stub-rx", + .no_pcm = 1, + .be_id = MSM_BACKEND_DAI_AUXPCM_RX, + .be_hw_params_fixup = msm_auxpcm_be_params_fixup, + .ops = &msm_auxpcm_be_ops, + }, + { + .name = LPASS_BE_AUXPCM_TX, + .stream_name = "AUX PCM Capture", + .cpu_dai_name = "msm-dai-q6.3", + .platform_name = "msm-pcm-routing", + .codec_name = "msm-stub-codec.1", + .codec_dai_name = "msm-stub-tx", + .no_pcm = 1, + .be_id = MSM_BACKEND_DAI_AUXPCM_TX, + .be_hw_params_fixup = msm_auxpcm_be_params_fixup, + }, +}; + +struct snd_soc_card snd_soc_card_msm = { + .name = "msm-snd-card", + .dai_link = msm_dai, + .num_links = ARRAY_SIZE(msm_dai), +}; + +static struct platform_device *msm_snd_device; + +static int msm_configure_headset_mic_gpios(void) +{ + int ret; + struct pm_gpio param = { + .direction = PM_GPIO_DIR_OUT, + .output_buffer = PM_GPIO_OUT_BUF_CMOS, + .output_value = 1, + .pull = PM_GPIO_PULL_NO, + .vin_sel = PM_GPIO_VIN_S4, + .out_strength = PM_GPIO_STRENGTH_MED, + .function = PM_GPIO_FUNC_NORMAL, + }; + + ret = gpio_request(PM8921_GPIO_PM_TO_SYS(23), "AV_SWITCH"); + if (ret) { + pr_err("%s: Failed to request gpio %d\n", __func__, + PM8921_GPIO_PM_TO_SYS(23)); + return ret; + } + + ret = pm8xxx_gpio_config(PM8921_GPIO_PM_TO_SYS(23), ¶m); + if (ret) + pr_err("%s: Failed to configure gpio %d\n", __func__, + PM8921_GPIO_PM_TO_SYS(23)); + else + gpio_direction_output(PM8921_GPIO_PM_TO_SYS(23), 0); + + ret = gpio_request(PM8921_GPIO_PM_TO_SYS(35), "US_EURO_SWITCH"); + if (ret) { + pr_err("%s: Failed to request gpio %d\n", __func__, + PM8921_GPIO_PM_TO_SYS(35)); + gpio_free(PM8921_GPIO_PM_TO_SYS(23)); + return ret; + } + ret = pm8xxx_gpio_config(PM8921_GPIO_PM_TO_SYS(35), ¶m); + if (ret) + pr_err("%s: Failed to configure gpio %d\n", __func__, + PM8921_GPIO_PM_TO_SYS(35)); + else + gpio_direction_output(PM8921_GPIO_PM_TO_SYS(35), 0); + + return 0; +} +static void msm_free_headset_mic_gpios(void) +{ + if (msm_headset_gpios_configured) { + gpio_free(PM8921_GPIO_PM_TO_SYS(23)); + gpio_free(PM8921_GPIO_PM_TO_SYS(35)); + } +} + +static int __init msm_audio_init(void) +{ + int ret; + + if (!cpu_is_apq8064()) { + pr_err("%s: Not the right machine type\n", __func__); + return -ENODEV; + } + + msm_snd_device = platform_device_alloc("soc-audio", 0); + if (!msm_snd_device) { + pr_err("Platform device allocation failed\n"); + return -ENOMEM; + } + + platform_set_drvdata(msm_snd_device, &snd_soc_card_msm); + ret = platform_device_add(msm_snd_device); + if (ret) { + platform_device_put(msm_snd_device); + return ret; + } + + if (msm_configure_headset_mic_gpios()) { + pr_err("%s Fail to configure headset mic gpios\n", __func__); + msm_headset_gpios_configured = 0; + } else + msm_headset_gpios_configured = 1; + + return ret; + +} +module_init(msm_audio_init); + +static void __exit msm_audio_exit(void) +{ + if (!cpu_is_apq8064()) { + pr_err("%s: Not the right machine type\n", __func__); + return ; + } + msm_free_headset_mic_gpios(); + platform_device_unregister(msm_snd_device); +} +module_exit(msm_audio_exit); + +MODULE_DESCRIPTION("ALSA SoC msm"); +MODULE_LICENSE("GPL v2"); diff --git a/sound/soc/msm/msm8960.c b/sound/soc/msm/msm8960.c index bfc004e7979..d3f02a9cdd9 100644 --- a/sound/soc/msm/msm8960.c +++ b/sound/soc/msm/msm8960.c @@ -24,6 +24,7 @@ #include #include #include +#include #include "msm-pcm-routing.h" #include "../codecs/wcd9310.h" @@ -1125,6 +1126,10 @@ static int __init msm8960_audio_init(void) { int ret; + if (!cpu_is_msm8960()) { + pr_err("%s: Not the right machine type\n", __func__); + return -ENODEV ; + } msm8960_snd_device = platform_device_alloc("soc-audio", 0); if (!msm8960_snd_device) { pr_err("Platform device allocation failed\n"); @@ -1151,6 +1156,10 @@ module_init(msm8960_audio_init); static void __exit msm8960_audio_exit(void) { + if (!cpu_is_msm8960()) { + pr_err("%s: Not the right machine type\n", __func__); + return ; + } msm8960_free_headset_mic_gpios(); platform_device_unregister(msm8960_snd_device); }