android_kernel_samsung_msm8976/sound/soc/msm/msm8939-slimbus.c
Venkata Narendra Kumar Gutta 7911ec6e78 ASoC: msm: Add QCHAT as Front-end DAI link for msm8939 external codec HW
Add QCHAT as Front-end DAI link to DAI link list. This DAI link is to
support QCHAT on msm8939 with external codec hardware.

CRs-Fixed: 820740
Change-Id: I133d92ad73f09ed2ddcc790200f926665ebc444e
Signed-off-by: Venkata Narendra Kumar Gutta <vgutta@codeaurora.org>
2015-04-14 22:02:21 +05:30

2797 lines
80 KiB
C

/* Copyright (c) 2014-2015, The Linux Foundation. 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 <linux/clk.h>
#include <linux/delay.h>
#include <linux/gpio.h>
#include <linux/of_gpio.h>
#include <linux/platform_device.h>
#include <linux/slab.h>
#include <linux/mfd/pm8xxx/pm8921.h>
#include <linux/qpnp/clkdiv.h>
#include <linux/io.h>
#include <linux/module.h>
#include <linux/workqueue.h>
#include <linux/sched.h>
#include <sound/core.h>
#include <sound/soc.h>
#include <sound/soc-dapm.h>
#include <sound/pcm.h>
#include <sound/jack.h>
#include <sound/q6afe-v2.h>
#include <sound/q6core.h>
#include <sound/pcm_params.h>
#include <soc/qcom/socinfo.h>
#include "qdsp6v2/msm-pcm-routing-v2.h"
#include "../codecs/wcd9xxx-common.h"
#include "../codecs/wcd9306.h"
#include "../codecs/wcd9330.h"
#define DRV_NAME "msm8939-slimbus-wcd"
#define SAMPLING_RATE_8KHZ 8000
#define SAMPLING_RATE_16KHZ 16000
#define SAMPLING_RATE_32KHZ 32000
#define SAMPLING_RATE_48KHZ 48000
#define SAMPLING_RATE_96KHZ 96000
#define SAMPLING_RATE_192KHZ 192000
#define MSM8939_SPK_ON 1
#define MSM8939_SPK_OFF 0
#define MSM_SLIM_0_RX_MAX_CHANNELS 2
#define MSM_SLIM_0_TX_MAX_CHANNELS 4
#define LO_1_SPK_AMP 0x1
#define LO_3_SPK_AMP 0x2
#define LO_2_SPK_AMP 0x4
#define LO_4_SPK_AMP 0x8
#define I2S_PCM_SEL 1
#define I2S_PCM_SEL_OFFSET 1
#define WCD9XXX_MBHC_DEF_BUTTONS 8
#define WCD9XXX_MBHC_DEF_RLOADS 5
#define CODEC_EXT_CLK_RATE 9600000
#define PRI_MI2S_ID (1 << 0)
#define SEC_MI2S_ID (1 << 1)
#define TER_MI2S_ID (1 << 2)
#define QUAT_MI2S_ID (1 << 3)
#define BTSCO_RATE_8KHZ 8000
#define BTSCO_RATE_16KHZ 16000
#define LPASS_CSR_GP_IO_MUX_MIC_CTL 0x07702000
#define LPASS_CSR_GP_IO_MUX_SPKR_CTL 0x07702004
#define ADSP_STATE_READY_TIMEOUT_MS 50
#define HS_STARTWORK_TIMEOUT 4000
static int slim0_rx_sample_rate = SAMPLING_RATE_48KHZ;
static int slim0_rx_bit_format = SNDRV_PCM_FORMAT_S16_LE;
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;
static int msm8939_spk_control = 1;
static int clk_users;
static struct platform_device *spdev;
static int mi2s_rx_bit_format = SNDRV_PCM_FORMAT_S16_LE;
static int msm_proxy_rx_ch = 2;
static void *adsp_state_notifier;
static bool quat_enable_mclk;
atomic_t quat_mi2s_rsc_ref;
static int msm_snd_enable_codec_ext_clk(struct snd_soc_codec *codec, int enable,
bool dapm);
static int msm_snd_enable_quat_mclk(struct snd_soc_codec *codec, int enable,
bool dapm);
static struct wcd9xxx_mbhc_config wcd9xxx_mbhc_cfg = {
.read_fw_bin = false,
.calibration = NULL,
.micbias = MBHC_MICBIAS2,
.anc_micbias = MBHC_MICBIAS2,
.mclk_cb_fn = msm_snd_enable_codec_ext_clk,
.mclk_rate = CODEC_EXT_CLK_RATE,
.gpio = 0,
.gpio_irq = 0,
.gpio_level_insert = 0,
.detect_extn_cable = true,
.micbias_enable_flags = 1 << MBHC_MICBIAS_ENABLE_THRESHOLD_HEADSET,
.insert_detect = true,
.swap_gnd_mic = NULL,
.cs_enable_flags = (1 << MBHC_CS_ENABLE_POLLING |
1 << MBHC_CS_ENABLE_INSERTION |
1 << MBHC_CS_ENABLE_REMOVAL |
1 << MBHC_CS_ENABLE_DET_ANC),
.do_recalibration = true,
.use_vddio_meas = true,
.enable_anc_mic_detect = false,
.hw_jack_type = FOUR_POLE_JACK,
};
static void *def_codec_mbhc_cal(void)
{
void *tapan_cal;
struct wcd9xxx_mbhc_btn_detect_cfg *btn_cfg;
u16 *btn_low, *btn_high;
u8 *n_ready, *n_cic, *gain;
tapan_cal = kzalloc(WCD9XXX_MBHC_CAL_SIZE(WCD9XXX_MBHC_DEF_BUTTONS,
WCD9XXX_MBHC_DEF_RLOADS),
GFP_KERNEL);
if (!tapan_cal) {
pr_err("%s: out of memory\n", __func__);
return NULL;
}
#define S(X, Y) ((WCD9XXX_MBHC_CAL_GENERAL_PTR(tapan_cal)->X) = (Y))
S(t_ldoh, 100);
S(t_bg_fast_settle, 100);
S(t_shutdown_plug_rem, 255);
S(mbhc_nsa, 2);
S(mbhc_navg, 128);
#undef S
#define S(X, Y) ((WCD9XXX_MBHC_CAL_PLUG_DET_PTR(tapan_cal)->X) = (Y))
S(mic_current, TAPAN_PID_MIC_5_UA);
S(hph_current, TAPAN_PID_MIC_5_UA);
S(t_mic_pid, 100);
S(t_ins_complete, 250);
S(t_ins_retry, 200);
#undef S
#define S(X, Y) ((WCD9XXX_MBHC_CAL_PLUG_TYPE_PTR(tapan_cal)->X) = (Y))
S(v_no_mic, 30);
S(v_hs_max, 2450);
#undef S
#define S(X, Y) ((WCD9XXX_MBHC_CAL_BTN_DET_PTR(tapan_cal)->X) = (Y))
S(c[0], 62);
S(c[1], 124);
S(nc, 1);
S(n_meas, 5);
S(mbhc_nsc, 10);
S(n_btn_meas, 1);
S(n_btn_con, 2);
S(num_btn, WCD9XXX_MBHC_DEF_BUTTONS);
S(v_btn_press_delta_sta, 100);
S(v_btn_press_delta_cic, 50);
#undef S
btn_cfg = WCD9XXX_MBHC_CAL_BTN_DET_PTR(tapan_cal);
btn_low = wcd9xxx_mbhc_cal_btn_det_mp(btn_cfg, MBHC_BTN_DET_V_BTN_LOW);
btn_high = wcd9xxx_mbhc_cal_btn_det_mp(btn_cfg,
MBHC_BTN_DET_V_BTN_HIGH);
btn_low[0] = -50;
btn_high[0] = 20;
btn_low[1] = 21;
btn_high[1] = 61;
btn_low[2] = 62;
btn_high[2] = 104;
btn_low[3] = 105;
btn_high[3] = 148;
btn_low[4] = 149;
btn_high[4] = 189;
btn_low[5] = 190;
btn_high[5] = 228;
btn_low[6] = 229;
btn_high[6] = 269;
btn_low[7] = 270;
btn_high[7] = 500;
n_ready = wcd9xxx_mbhc_cal_btn_det_mp(btn_cfg, MBHC_BTN_DET_N_READY);
n_ready[0] = 80;
n_ready[1] = 12;
n_cic = wcd9xxx_mbhc_cal_btn_det_mp(btn_cfg, MBHC_BTN_DET_N_CIC);
n_cic[0] = 60;
n_cic[1] = 47;
gain = wcd9xxx_mbhc_cal_btn_det_mp(btn_cfg, MBHC_BTN_DET_GAIN);
gain[0] = 11;
gain[1] = 14;
return tapan_cal;
}
static struct afe_clk_cfg mi2s_rx_clk = {
AFE_API_VERSION_I2S_CONFIG,
Q6AFE_LPASS_IBIT_CLK_1_P536_MHZ,
Q6AFE_LPASS_OSR_CLK_12_P288_MHZ,
Q6AFE_LPASS_CLK_SRC_INTERNAL,
Q6AFE_LPASS_CLK_ROOT_DEFAULT,
Q6AFE_LPASS_MODE_CLK1_VALID,
0,
};
static struct afe_clk_cfg mi2s_tx_clk = {
AFE_API_VERSION_I2S_CONFIG,
Q6AFE_LPASS_IBIT_CLK_1_P536_MHZ,
Q6AFE_LPASS_OSR_CLK_12_P288_MHZ,
Q6AFE_LPASS_CLK_SRC_INTERNAL,
Q6AFE_LPASS_CLK_ROOT_DEFAULT,
Q6AFE_LPASS_MODE_CLK1_VALID,
0,
};
struct cdc_pinctrl_info {
struct pinctrl *pinctrl;
struct pinctrl_state *cdc_slim_sus;
struct pinctrl_state *cdc_slim_act;
struct pinctrl_state *cross_conn_det_sus;
struct pinctrl_state *cross_conn_det_act;
struct pinctrl_state *cdc_lines_sus;
struct pinctrl_state *cdc_lines_act;
};
struct msm8939_codec {
int (*mclk_enable_fn) (struct snd_soc_codec *codec,
int mclk_enable, bool dapm);
void *(*get_afe_config_fn) (struct snd_soc_codec *codec,
enum afe_config_type config_type);
int (*mbhc_hs_detect) (struct snd_soc_codec *codec,
struct wcd9xxx_mbhc_config *mbhc_cfg);
};
struct msm8939_asoc_mach_data {
int ext_pa;
int mclk_gpio;
u32 mclk_freq;
int us_euro_gpio;
struct mutex cdc_mclk_mutex;
struct afe_digital_clk_cfg digital_cdc_clk;
struct delayed_work hs_detect_dwork;
struct snd_soc_codec *codec;
struct msm8939_codec msm8939_codec_fn;
struct cdc_pinctrl_info pinctrl_info;
};
static inline int param_is_mask(int p)
{
return ((p >= SNDRV_PCM_HW_PARAM_FIRST_MASK) &&
(p <= SNDRV_PCM_HW_PARAM_LAST_MASK));
}
static inline struct snd_mask *param_to_mask(struct snd_pcm_hw_params *p, int n)
{
return &(p->masks[n - SNDRV_PCM_HW_PARAM_FIRST_MASK]);
}
static void param_set_mask(struct snd_pcm_hw_params *p, int n, unsigned bit)
{
if (bit >= SNDRV_MASK_MAX)
return;
if (param_is_mask(n)) {
struct snd_mask *m = param_to_mask(p, n);
m->bits[0] = 0;
m->bits[1] = 0;
m->bits[bit >> 5] |= (1 << (bit & 31));
}
}
static void msm8939_ext_control(struct snd_soc_codec *codec)
{
struct snd_soc_dapm_context *dapm = &codec->dapm;
mutex_lock(&dapm->codec->mutex);
pr_debug("%s: msm8939_spk_control = %d", __func__, msm8939_spk_control);
if (msm8939_spk_control == MSM8939_SPK_ON) {
snd_soc_dapm_enable_pin(dapm, "Lineout_1 amp");
snd_soc_dapm_enable_pin(dapm, "Lineout_3 amp");
} else {
snd_soc_dapm_disable_pin(dapm, "Lineout_1 amp");
snd_soc_dapm_disable_pin(dapm, "Lineout_3 amp");
}
mutex_unlock(&dapm->codec->mutex);
snd_soc_dapm_sync(dapm);
}
static int msm8939_get_spk(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
{
pr_debug("%s: msm8939_spk_control = %d\n",
__func__, msm8939_spk_control);
ucontrol->value.integer.value[0] = msm8939_spk_control;
return 0;
}
static int msm8939_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 (msm8939_spk_control == ucontrol->value.integer.value[0])
return 0;
msm8939_spk_control = ucontrol->value.integer.value[0];
msm8939_ext_control(codec);
return 1;
}
static int msm_snd_enable_codec_ext_clk(struct snd_soc_codec *codec, int enable,
bool dapm)
{
int ret = 0;
struct snd_soc_card *card = codec->card;
struct msm8939_asoc_mach_data *pdata = snd_soc_card_get_drvdata(card);
pr_debug("%s: enable = %d clk_users = %d\n",
__func__, enable, clk_users);
mutex_lock(&pdata->cdc_mclk_mutex);
if (enable) {
clk_users++;
if (clk_users != 1)
goto exit;
pr_debug("clock enable\n");
pdata->digital_cdc_clk.clk_val = 9600000;
ret = afe_set_digital_codec_core_clock(
AFE_PORT_ID_PRIMARY_MI2S_RX,
&pdata->digital_cdc_clk);
if (ret < 0) {
pr_err("%s: failed to enable the MCLK\n",
__func__);
clk_users--;
goto exit;
}
pdata->msm8939_codec_fn.mclk_enable_fn(codec, 1, dapm);
} else {
if (clk_users > 0) {
clk_users--;
if (clk_users == 0) {
pdata->msm8939_codec_fn.mclk_enable_fn(codec,
0, dapm);
pdata->digital_cdc_clk.clk_val = 0;
ret = afe_set_digital_codec_core_clock(
AFE_PORT_ID_PRIMARY_MI2S_RX,
&pdata->digital_cdc_clk);
if (ret < 0)
pr_err("%s: failed disable the MCLK\n",
__func__);
}
} else {
pr_err("%s: Error releasing codec MCLK\n", __func__);
ret = -EINVAL;
goto exit;
}
}
exit:
mutex_unlock(&pdata->cdc_mclk_mutex);
return ret;
}
static int msm8x16_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:
return msm_snd_enable_codec_ext_clk(w->codec, 1, true);
case SND_SOC_DAPM_POST_PMD:
return msm_snd_enable_codec_ext_clk(w->codec, 0, true);
}
return 0;
}
static const struct snd_soc_dapm_widget msm8939_dapm_widgets[] = {
SND_SOC_DAPM_SUPPLY_S("MCLK", -1, SND_SOC_NOPM, 0, 0,
msm8x16_mclk_event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
SND_SOC_DAPM_MIC("Handset Mic", NULL),
SND_SOC_DAPM_MIC("Headset Mic", NULL),
SND_SOC_DAPM_MIC("ANCRight Headset Mic", NULL),
SND_SOC_DAPM_MIC("ANCLeft Headset Mic", NULL),
SND_SOC_DAPM_MIC("Analog Mic4", NULL),
SND_SOC_DAPM_MIC("Analog Mic6", NULL),
SND_SOC_DAPM_MIC("Analog Mic7", 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 int slim0_rx_sample_rate_get(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
{
int sample_rate_val = 0;
switch (slim0_rx_sample_rate) {
case SAMPLING_RATE_192KHZ:
sample_rate_val = 2;
break;
case SAMPLING_RATE_96KHZ:
sample_rate_val = 1;
break;
case SAMPLING_RATE_48KHZ:
default:
sample_rate_val = 0;
break;
}
ucontrol->value.integer.value[0] = sample_rate_val;
pr_debug("%s: slim0_rx_sample_rate = %d\n", __func__,
slim0_rx_sample_rate);
return 0;
}
static int slim0_rx_sample_rate_put(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
{
pr_debug("%s: ucontrol value = %ld\n", __func__,
ucontrol->value.integer.value[0]);
switch (ucontrol->value.integer.value[0]) {
case 2:
slim0_rx_sample_rate = SAMPLING_RATE_192KHZ;
break;
case 1:
slim0_rx_sample_rate = SAMPLING_RATE_96KHZ;
break;
case 0:
default:
slim0_rx_sample_rate = SAMPLING_RATE_48KHZ;
}
pr_debug("%s: slim0_rx_sample_rate = %d\n", __func__,
slim0_rx_sample_rate);
return 0;
}
static int slim0_rx_bit_format_get(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
{
switch (slim0_rx_bit_format) {
case SNDRV_PCM_FORMAT_S24_LE:
ucontrol->value.integer.value[0] = 1;
break;
case SNDRV_PCM_FORMAT_S16_LE:
default:
ucontrol->value.integer.value[0] = 0;
break;
}
pr_debug("%s: slim0_rx_bit_format = %d, ucontrol value = %ld\n",
__func__, slim0_rx_bit_format,
ucontrol->value.integer.value[0]);
return 0;
}
static int slim0_rx_bit_format_put(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
{
switch (ucontrol->value.integer.value[0]) {
case 1:
slim0_rx_bit_format = SNDRV_PCM_FORMAT_S24_LE;
break;
case 0:
default:
slim0_rx_bit_format = SNDRV_PCM_FORMAT_S16_LE;
break;
}
return 0;
}
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 const struct snd_soc_dapm_widget msm8x16_dapm_widgets[] = {
SND_SOC_DAPM_SUPPLY("MCLK", SND_SOC_NOPM, 0, 0,
msm8x16_mclk_event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
SND_SOC_DAPM_MIC("Handset Mic", NULL),
SND_SOC_DAPM_MIC("Headset Mic", NULL),
SND_SOC_DAPM_MIC("ANCRight Headset Mic", NULL),
SND_SOC_DAPM_MIC("ANCLeft Headset Mic", NULL),
SND_SOC_DAPM_MIC("Analog Mic4", NULL),
SND_SOC_DAPM_MIC("Analog Mic6", NULL),
SND_SOC_DAPM_MIC("Analog Mic7", 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 char *const spk_function[] = {"Off", "On"};
static const char *const slim0_rx_ch_text[] = {"One", "Two"};
static const char *const slim0_tx_ch_text[] = {"One", "Two", "Three", "Four",
"Five", "Six", "Seven",
"Eight"};
static char const *rx_bit_format_text[] = {"S16_LE", "S24_LE"};
static char const *slim0_rx_sample_rate_text[] = {"KHZ_48", "KHZ_96",
"KHZ_192"};
static const struct soc_enum msm_snd_enum[] = {
SOC_ENUM_SINGLE_EXT(2, spk_function),
SOC_ENUM_SINGLE_EXT(2, slim0_rx_ch_text),
SOC_ENUM_SINGLE_EXT(8, slim0_tx_ch_text),
SOC_ENUM_SINGLE_EXT(2, rx_bit_format_text),
SOC_ENUM_SINGLE_EXT(3, slim0_rx_sample_rate_text),
};
static const struct snd_kcontrol_new msm_snd_controls[] = {
SOC_ENUM_EXT("Speaker Function", msm_snd_enum[0], msm8939_get_spk,
msm8939_set_spk),
SOC_ENUM_EXT("SLIM_0_RX Channels", msm_snd_enum[1],
msm_slim_0_rx_ch_get, msm_slim_0_rx_ch_put),
SOC_ENUM_EXT("SLIM_0_TX Channels", msm_snd_enum[2],
msm_slim_0_tx_ch_get, msm_slim_0_tx_ch_put),
SOC_ENUM_EXT("SLIM_0_RX Format", msm_snd_enum[3],
slim0_rx_bit_format_get, slim0_rx_bit_format_put),
SOC_ENUM_EXT("SLIM_0_RX SampleRate", msm_snd_enum[4],
slim0_rx_sample_rate_get, slim0_rx_sample_rate_put),
};
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);
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 = 2;
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_proxy_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: msm_proxy_rx_ch =%d\n", __func__, msm_proxy_rx_ch);
if (channels->max < 2)
channels->min = channels->max = 2;
channels->min = channels->max = msm_proxy_rx_ch;
rate->min = rate->max = 48000;
return 0;
}
static int msm_proxy_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);
rate->min = rate->max = 48000;
return 0;
}
static int msm_afe_set_config(struct snd_soc_codec *codec)
{
int rc;
void *config_data;
struct snd_soc_card *card = codec->card;
struct msm8939_asoc_mach_data *pdata = snd_soc_card_get_drvdata(card);
pr_debug("%s: enter\n", __func__);
config_data = pdata->msm8939_codec_fn.get_afe_config_fn(codec,
AFE_CDC_REGISTERS_CONFIG);
rc = afe_set_config(AFE_CDC_REGISTERS_CONFIG, config_data, 0);
if (rc) {
pr_err("%s: Failed to set codec registers config %d\n",
__func__, rc);
return rc;
}
config_data = pdata->msm8939_codec_fn.get_afe_config_fn(codec,
AFE_SLIMBUS_SLAVE_CONFIG);
rc = afe_set_config(AFE_SLIMBUS_SLAVE_CONFIG, config_data, 0);
if (rc) {
pr_err("%s: Failed to set slimbus slave config %d\n", __func__,
rc);
return rc;
}
config_data = pdata->msm8939_codec_fn.get_afe_config_fn(codec,
AFE_AANC_VERSION);
rc = afe_set_config(AFE_AANC_VERSION, config_data, 0);
if (rc) {
pr_err("%s: Failed to set AANC version %d\n", __func__,
rc);
return rc;
}
return 0;
}
static void msm_afe_clear_config(void)
{
afe_clear_config(AFE_CDC_REGISTERS_CONFIG);
afe_clear_config(AFE_SLIMBUS_SLAVE_CONFIG);
}
static int ext_mi2s_clk_ctl(struct snd_pcm_substream *substream, bool enable)
{
int ret = 0;
if (enable) {
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
mi2s_rx_clk.clk_val1 = Q6AFE_LPASS_IBIT_CLK_1_P536_MHZ;
ret = afe_set_lpass_clock(
AFE_PORT_ID_QUATERNARY_MI2S_RX,
&mi2s_rx_clk);
} else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
mi2s_tx_clk.clk_val1 = Q6AFE_LPASS_IBIT_CLK_1_P536_MHZ;
ret = afe_set_lpass_clock(
AFE_PORT_ID_QUATERNARY_MI2S_TX,
&mi2s_tx_clk);
} else
pr_err("%s:Not valid substream.\n", __func__);
if (ret < 0)
pr_err("%s:afe_set_lpass_clock failed ret=%d\n",
__func__, ret);
} else {
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
mi2s_rx_clk.clk_val1 = Q6AFE_LPASS_IBIT_CLK_DISABLE;
ret = afe_set_lpass_clock(
AFE_PORT_ID_QUATERNARY_MI2S_RX,
&mi2s_rx_clk);
} else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
mi2s_tx_clk.clk_val1 = Q6AFE_LPASS_IBIT_CLK_DISABLE;
ret = afe_set_lpass_clock(
AFE_PORT_ID_QUATERNARY_MI2S_TX,
&mi2s_tx_clk);
} else
pr_err("%s:Not valid substream %d\n", __func__,
substream->stream);
if (ret < 0)
pr_err("%s:afe_set_lpass_clock failed ret=%d\n",
__func__, ret);
}
return ret;
}
static int msm8939_adsp_state_callback(struct notifier_block *nb,
unsigned long value, void *priv)
{
if (value == SUBSYS_BEFORE_SHUTDOWN) {
pr_debug("%s: ADSP is about to shutdown. Clearing AFE config\n",
__func__);
msm_afe_clear_config();
} else if (value == SUBSYS_AFTER_POWERUP) {
pr_debug("%s: ADSP is up\n", __func__);
}
return NOTIFY_OK;
}
static struct notifier_block adsp_state_notifier_block = {
.notifier_call = msm8939_adsp_state_callback,
.priority = -INT_MAX,
};
static int msm8939_wcd93xx_codec_up(struct snd_soc_codec *codec)
{
int err;
bool timedout;
unsigned long timeout;
int adsp_ready = 0;
if (!q6core_is_adsp_ready()) {
dev_err(codec->dev,
"ADSP isn't ready\n");
timeout = jiffies +
msecs_to_jiffies(ADSP_STATE_READY_TIMEOUT_MS);
while (!(timedout = time_after(jiffies, timeout))) {
if (!q6core_is_adsp_ready()) {
dev_err(codec->dev,
"ADSP isn't ready\n");
} else {
dev_err(codec->dev,
"ADSP is ready\n");
adsp_ready = 1;
break;
}
}
} else {
adsp_ready = 1;
dev_err(codec->dev,
"%s: DSP is ready\n", __func__);
}
if (!adsp_ready) {
pr_err("%s: timed out waiting for ADSP Audio\n", __func__);
return -ETIMEDOUT;
}
err = msm_afe_set_config(codec);
if (err)
pr_err("%s: Failed to set AFE config. err %d\n",
__func__, err);
return err;
}
static int msm8939_gpio_set_mux_ctl(void)
{
void __iomem *vaddr = NULL;
int val = 0;
vaddr = ioremap(LPASS_CSR_GP_IO_MUX_MIC_CTL , 4);
if (!vaddr) {
pr_err("%s ioremap failure for addr %x\n",
__func__,
LPASS_CSR_GP_IO_MUX_MIC_CTL);
return -ENOMEM;
}
val = ioread32(vaddr);
val = val | 0x0;
iowrite32(val, vaddr);
pr_debug("%s:val_mic_mux gpio %x\n", __func__, val);
iounmap(vaddr);
vaddr = ioremap(LPASS_CSR_GP_IO_MUX_SPKR_CTL , 4);
if (!vaddr) {
pr_err("%s ioremap failure for addr %x\n",
__func__,
LPASS_CSR_GP_IO_MUX_SPKR_CTL);
return -ENOMEM;
}
val = ioread32(vaddr);
val = val | 0x00000002;
iowrite32(val, vaddr);
pr_debug("%s:val_spkr_mux gpio %x\n", __func__, val);
iounmap(vaddr);
vaddr = ioremap(0x103f004, 4);
if (!vaddr) {
pr_err("%s ioremap failure for addr\n",
__func__);
return -ENOMEM;
}
val = ioread32(vaddr);
pr_debug("%s:val1 %x\n", __func__, val);
iounmap(vaddr);
vaddr = ioremap(0x103f000, 4);
if (!vaddr) {
pr_err("%s ioremap failure for addr2\n",
__func__);
return -ENOMEM;
}
val = ioread32(vaddr);
pr_debug("%s:val2 %x\n", __func__, val);
iounmap(vaddr);
return 0;
}
static int msm8939_codec_event_cb(struct snd_soc_codec *codec,
enum wcd9xxx_codec_event codec_event)
{
int ret = 0;
switch (codec_event) {
case WCD9XXX_CODEC_EVENT_CODEC_UP:
ret = msm8939_gpio_set_mux_ctl();
if (ret < 0) {
pr_err("%s: failed to set MUX ctl\n", __func__);
return ret;
}
return msm8939_wcd93xx_codec_up(codec);
default:
pr_err("%s: UnSupported codec event %d\n",
__func__, codec_event);
return -EINVAL;
}
}
static int msm_snd_get_ext_clk_cnt(void)
{
return clk_users;
}
static int msm_audrx_init_tomtom(struct snd_soc_pcm_runtime *rtd)
{
int err;
void *config_data;
struct snd_soc_codec *codec = rtd->codec;
struct snd_soc_dapm_context *dapm = &codec->dapm;
struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
struct snd_soc_dai *codec_dai = rtd->codec_dai;
struct snd_soc_card *card = codec->card;
struct msm8939_asoc_mach_data *pdata = snd_soc_card_get_drvdata(card);
/* Codec SLIMBUS configuration
* RX1, RX2, RX3, RX4, RX5, RX6, RX7, RX8, RX9, RX10, RX11, RX12, RX13
* TX1, TX2, TX3, TX4, TX5, TX6, TX7, TX8, TX9, TX10, TX11, TX12, TX13
* TX14, TX15, TX16
*/
unsigned int rx_ch[TOMTOM_RX_MAX] = {144, 145, 146, 147, 148, 149, 150,
151, 152, 153, 154, 155, 156};
unsigned int tx_ch[TOMTOM_TX_MAX] = {128, 129, 130, 131, 132, 133,
134, 135, 136, 137, 138, 139,
140, 141, 142, 143};
pr_debug("%s: dev_name%s\n", __func__, dev_name(cpu_dai->dev));
rtd->pmdown_time = 0;
err = snd_soc_add_codec_controls(codec, msm_snd_controls,
ARRAY_SIZE(msm_snd_controls));
if (err < 0) {
pr_err("%s: add_codec_controls failed, err%d\n",
__func__, err);
return err;
}
snd_soc_dapm_new_controls(dapm, msm8939_dapm_widgets,
ARRAY_SIZE(msm8939_dapm_widgets));
snd_soc_dapm_enable_pin(dapm, "Lineout_1 amp");
snd_soc_dapm_enable_pin(dapm, "Lineout_3 amp");
snd_soc_dapm_enable_pin(dapm, "Lineout_2 amp");
snd_soc_dapm_enable_pin(dapm, "Lineout_4 amp");
snd_soc_dapm_ignore_suspend(dapm, "MADINPUT");
snd_soc_dapm_ignore_suspend(dapm, "MAD_CPE_INPUT");
snd_soc_dapm_ignore_suspend(dapm, "Handset Mic");
snd_soc_dapm_ignore_suspend(dapm, "Headset Mic");
snd_soc_dapm_ignore_suspend(dapm, "Secondary Mic");
snd_soc_dapm_ignore_suspend(dapm, "Digital Mic1");
snd_soc_dapm_ignore_suspend(dapm, "Digital Mic2");
snd_soc_dapm_ignore_suspend(dapm, "EAR");
snd_soc_dapm_ignore_suspend(dapm, "HEADPHONE");
snd_soc_dapm_ignore_suspend(dapm, "SPK_OUT");
snd_soc_dapm_ignore_suspend(dapm, "LINEOUT1");
snd_soc_dapm_ignore_suspend(dapm, "LINEOUT2");
snd_soc_dapm_ignore_suspend(dapm, "LINEOUT3");
snd_soc_dapm_ignore_suspend(dapm, "LINEOUT4");
snd_soc_dapm_ignore_suspend(dapm, "AMIC1");
snd_soc_dapm_ignore_suspend(dapm, "AMIC2");
snd_soc_dapm_ignore_suspend(dapm, "AMIC3");
snd_soc_dapm_ignore_suspend(dapm, "AMIC4");
snd_soc_dapm_ignore_suspend(dapm, "AMIC5");
snd_soc_dapm_ignore_suspend(dapm, "AMIC6");
snd_soc_dapm_ignore_suspend(dapm, "DMIC1");
snd_soc_dapm_ignore_suspend(dapm, "DMIC2");
snd_soc_dapm_ignore_suspend(dapm, "DMIC3");
snd_soc_dapm_ignore_suspend(dapm, "DMIC4");
snd_soc_dapm_ignore_suspend(dapm, "DMIC5");
snd_soc_dapm_ignore_suspend(dapm, "DMIC6");
snd_soc_dapm_ignore_suspend(dapm, "ANC EAR");
snd_soc_dapm_ignore_suspend(dapm, "ANC HEADPHONE");
snd_soc_dapm_sync(dapm);
snd_soc_dai_set_channel_map(codec_dai, ARRAY_SIZE(tx_ch),
tx_ch, ARRAY_SIZE(rx_ch), rx_ch);
err = msm_afe_set_config(codec);
if (err) {
pr_err("%s: Failed to set AFE config %d\n", __func__, err);
goto out;
}
config_data = tomtom_get_afe_config(codec,
AFE_CDC_CLIP_REGISTERS_CONFIG);
if (config_data) {
err = afe_set_config(AFE_CDC_CLIP_REGISTERS_CONFIG,
config_data, 0);
if (err) {
pr_err("%s: Failed to set clip registers %d\n",
__func__, err);
goto out;
}
}
config_data = tomtom_get_afe_config(codec, AFE_CLIP_BANK_SEL);
if (config_data) {
err = afe_set_config(AFE_CLIP_BANK_SEL, config_data, 0);
if (err) {
pr_err("%s: Failed to set AFE bank selection %d\n",
__func__, err);
goto out;
}
}
err = msm8939_gpio_set_mux_ctl();
if (err) {
pr_err("%s: Failed to set MUX CTL %d\n",
__func__, err);
return err;
}
adsp_state_notifier =
subsys_notif_register_notifier("modem",
&adsp_state_notifier_block);
if (!adsp_state_notifier) {
pr_err("%s: Failed to register adsp state notifier\n",
__func__);
err = -EFAULT;
goto out;
}
/* start mbhc */
wcd9xxx_mbhc_cfg.calibration = def_codec_mbhc_cal();
if (wcd9xxx_mbhc_cfg.calibration) {
/*
* mbhc inital calibration needs mclk to be enabled, so schedule
* headset detection for 4sec so that modem gets loaded and
* will be ready to accept mclk request command.
*/
pdata->codec = codec;
schedule_delayed_work(&pdata->hs_detect_dwork,
msecs_to_jiffies(HS_STARTWORK_TIMEOUT));
} else {
pr_err("%s: wcd9xxx_mbhc_cfg calibration is NULL\n", __func__);
err = -ENOMEM;
goto out;
}
tomtom_event_register(msm8939_codec_event_cb, rtd->codec);
tomtom_register_ext_clk_cb(msm_snd_enable_codec_ext_clk,
msm_snd_get_ext_clk_cnt,
rtd->codec);
return 0;
out:
return err;
}
static void codec_enable_qfuse(struct snd_soc_codec *codec)
{
if (codec == NULL ||
strcmp(codec->name, "tomtom_codec"))
return;
msm_snd_enable_codec_ext_clk(codec, 1, false);
tomtom_enable_qfuse_sensing(codec);
msm_snd_enable_codec_ext_clk(codec, 0, false);
}
static void hs_detect_work(struct work_struct *work)
{
struct delayed_work *dwork;
struct msm8939_asoc_mach_data *pdata;
int ret = 0;
dwork = to_delayed_work(work);
pdata = container_of(dwork, struct msm8939_asoc_mach_data,
hs_detect_dwork);
if (!pdata || !pdata->codec)
return;
pr_debug("%s: enter codec %s\n", __func__, pdata->codec->name);
ret = pdata->msm8939_codec_fn.mbhc_hs_detect(pdata->codec,
&wcd9xxx_mbhc_cfg);
if (ret < 0)
pr_err("%s: Failed to intialise mbhc %d\n", __func__, ret);
codec_enable_qfuse(pdata->codec);
/*
* Set pdata->codec back to NULL, to ensure codec pointer
* is not referenced further from this structure.
*/
pdata->codec = NULL;
pr_debug("%s: leave\n", __func__);
}
static int msm_audrx_init(struct snd_soc_pcm_runtime *rtd)
{
struct snd_soc_codec *codec = rtd->codec;
struct snd_soc_dapm_context *dapm = &codec->dapm;
struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
struct snd_soc_dai *codec_dai = rtd->codec_dai;
struct snd_soc_card *card = codec->card;
struct msm8939_asoc_mach_data *pdata = snd_soc_card_get_drvdata(card);
int ret = 0;
/*
* Tapan SLIMBUS configuration
* RX1, RX2, RX3, RX4, RX5, RX6, RX7, RX8, RX9, RX10, RX11, RX12, RX13
* TX1, TX2, TX3, TX4, TX5, TX6, TX7, TX8, TX9, TX10, TX11, TX12, TX13
* TX14, TX15, TX16
*/
unsigned int rx_ch[TAPAN_RX_MAX] = {144, 145, 146, 147, 148};
unsigned int tx_ch[TAPAN_TX_MAX] = {128, 129, 130, 131, 132};
pr_debug("%s(), dev_name%s\n", __func__, dev_name(cpu_dai->dev));
rtd->pmdown_time = 0;
snd_soc_add_codec_controls(codec, msm_snd_controls,
ARRAY_SIZE(msm_snd_controls));
snd_soc_dapm_new_controls(dapm, msm8x16_dapm_widgets,
ARRAY_SIZE(msm8x16_dapm_widgets));
snd_soc_dapm_ignore_suspend(dapm, "Handset Mic");
snd_soc_dapm_ignore_suspend(dapm, "Headset Mic");
snd_soc_dapm_ignore_suspend(dapm, "Secondary Mic");
snd_soc_dapm_ignore_suspend(dapm, "Digital Mic1");
snd_soc_dapm_ignore_suspend(dapm, "Digital Mic2");
snd_soc_dapm_ignore_suspend(dapm, "EAR");
snd_soc_dapm_ignore_suspend(dapm, "HEADPHONE");
snd_soc_dapm_ignore_suspend(dapm, "SPK_OUT");
snd_soc_dapm_ignore_suspend(dapm, "LINEOUT1");
snd_soc_dapm_ignore_suspend(dapm, "LINEOUT2");
snd_soc_dapm_ignore_suspend(dapm, "AMIC1");
snd_soc_dapm_ignore_suspend(dapm, "AMIC2");
snd_soc_dapm_ignore_suspend(dapm, "AMIC3");
snd_soc_dapm_ignore_suspend(dapm, "AMIC4");
snd_soc_dapm_ignore_suspend(dapm, "AMIC5");
snd_soc_dapm_ignore_suspend(dapm, "DMIC1");
snd_soc_dapm_ignore_suspend(dapm, "DMIC2");
snd_soc_dapm_ignore_suspend(dapm, "DMIC3");
snd_soc_dapm_ignore_suspend(dapm, "DMIC4");
snd_soc_dapm_ignore_suspend(dapm, "ANC EAR");
snd_soc_dapm_ignore_suspend(dapm, "ANC HEADPHONE");
snd_soc_dapm_sync(dapm);
snd_soc_dai_set_channel_map(codec_dai, ARRAY_SIZE(tx_ch),
tx_ch, ARRAY_SIZE(rx_ch), rx_ch);
ret = msm_afe_set_config(codec);
if (ret) {
pr_err("%s: Failed to set AFE config %d\n",
__func__, ret);
return ret;
}
ret = msm8939_gpio_set_mux_ctl();
if (ret) {
pr_err("%s: Failed to set MUX CTL %d\n",
__func__, ret);
return ret;
}
wcd9xxx_mbhc_cfg.calibration = def_codec_mbhc_cal();
if (wcd9xxx_mbhc_cfg.calibration) {
/*
* mbhc inital calibration needs mclk to be enabled, so schedule
* headset detection for 4sec so that modem gets loaded and
* will be ready to accept mclk request command.
*/
pdata->codec = codec;
schedule_delayed_work(&pdata->hs_detect_dwork,
msecs_to_jiffies(HS_STARTWORK_TIMEOUT));
} else {
ret = -ENOMEM;
}
adsp_state_notifier =
subsys_notif_register_notifier("modem",
&adsp_state_notifier_block);
if (!adsp_state_notifier) {
pr_err("%s: Failed to register adsp state notifier\n",
__func__);
ret = -EFAULT;
}
tapan_event_register(msm8939_codec_event_cb, rtd->codec);
return ret;
}
static int msm_snd_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;
struct snd_soc_dai_link *dai_link = rtd->dai_link;
int ret = 0;
u32 rx_ch[SLIM_MAX_RX_PORTS], tx_ch[SLIM_MAX_TX_PORTS];
u32 rx_ch_cnt = 0, tx_ch_cnt = 0;
u32 user_set_tx_ch = 0;
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
pr_debug("%s: rx_0_ch=%d\n", __func__, msm_slim_0_rx_ch);
ret = snd_soc_dai_get_channel_map(codec_dai,
&tx_ch_cnt, tx_ch, &rx_ch_cnt , rx_ch);
if (ret < 0) {
pr_err("%s: failed to get codec chan map, err:%d\n",
__func__, ret);
goto end;
}
ret = snd_soc_dai_set_channel_map(cpu_dai, 0, 0,
msm_slim_0_rx_ch, rx_ch);
if (ret < 0) {
pr_err("%s: failed to set cpu chan map, err:%d\n",
__func__, ret);
goto end;
}
} else {
pr_debug("%s: %s_tx_dai_id_%d_ch=%d\n", __func__,
codec_dai->name, codec_dai->id, user_set_tx_ch);
ret = snd_soc_dai_get_channel_map(codec_dai,
&tx_ch_cnt, tx_ch, &rx_ch_cnt , rx_ch);
if (ret < 0) {
pr_err("%s: failed to get codec chan map\n, err:%d\n",
__func__, ret);
goto end;
}
/* For <codec>_tx1 case */
if (dai_link->be_id == MSM_BACKEND_DAI_SLIMBUS_0_TX)
user_set_tx_ch = msm_slim_0_tx_ch;
/* For <codec>_tx2 case */
else if (dai_link->be_id == MSM_BACKEND_DAI_SLIMBUS_1_TX)
user_set_tx_ch = params_channels(params);
else if (dai_link->be_id == MSM_BACKEND_DAI_SLIMBUS_3_TX)
/* DAI 5 is used for external EC reference from codec.
* Since Rx is fed as reference for EC, the config of
* this DAI is based on that of the Rx path.
*/
user_set_tx_ch = msm_slim_0_rx_ch;
else
user_set_tx_ch = tx_ch_cnt;
pr_debug(
"%s: msm_slim_0_tx_ch(%d) user_set_tx_ch(%d) tx_ch_cnt(%d)\n",
__func__, msm_slim_0_tx_ch, user_set_tx_ch, tx_ch_cnt);
ret = snd_soc_dai_set_channel_map(cpu_dai,
user_set_tx_ch, tx_ch, 0 , 0);
if (ret < 0) {
pr_err("%s: failed to set cpu chan map, err:%d\n",
__func__, ret);
goto end;
}
}
end:
return ret;
}
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__);
param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
slim0_rx_bit_format);
rate->min = rate->max = slim0_rx_sample_rate;
channels->min = channels->max = msm_slim_0_rx_ch;
pr_debug("%s: format = %d, rate = %d, channels = %d\n",
__func__, params_format(params), params_rate(params),
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__);
param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
slim0_rx_bit_format);
rate->min = rate->max = 48000;
channels->min = channels->max = msm_slim_0_tx_ch;
return 0;
}
static int msm_slim_5_tx_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
struct snd_pcm_hw_params *params)
{
int rc;
void *config;
struct snd_soc_codec *codec = rtd->codec;
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);
struct snd_soc_card *card = codec->card;
struct msm8939_asoc_mach_data *pdata = snd_soc_card_get_drvdata(card);
pr_debug("%s enter\n", __func__);
rate->min = rate->max = 16000;
channels->min = channels->max = 1;
config = pdata->msm8939_codec_fn.get_afe_config_fn(codec,
AFE_SLIMBUS_SLAVE_PORT_CONFIG);
rc = afe_set_config(AFE_SLIMBUS_SLAVE_PORT_CONFIG, config,
SLIMBUS_5_TX);
if (rc) {
pr_err("%s: Failed to set slimbus slave port config %d\n",
__func__, rc);
return rc;
}
return 0;
}
static void msm_quat_mi2s_snd_shutdown(struct snd_pcm_substream *substream)
{
int ret = 0;
struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct snd_soc_card *card = rtd->card;
struct snd_soc_codec *codec = rtd->codec;
struct msm8939_asoc_mach_data *pdata = snd_soc_card_get_drvdata(card);
pr_debug("%s(): substream = %s stream = %d, ext_pa = %d\n", __func__,
substream->name, substream->stream, pdata->ext_pa);
if (((pdata->ext_pa & QUAT_MI2S_ID) == QUAT_MI2S_ID)) {
ret = ext_mi2s_clk_ctl(substream, false);
if (ret < 0)
pr_err("%s:clock disable failed\n", __func__);
if (atomic_read(&quat_mi2s_rsc_ref) > 0)
atomic_dec(&quat_mi2s_rsc_ref);
ret = msm_snd_enable_quat_mclk(codec, 0, true);
if (ret < 0)
pr_err("%s:failed to disable mclk\n", __func__);
}
}
static int conf_int_codec_mux_quat(struct msm8939_asoc_mach_data *pdata)
{
int ret = 0;
int val = 0;
void __iomem *vaddr = NULL;
/* configure the Primary, Sec and Tert mux for Mi2S interface
* slave select to invalid state, for machine mode this
* should move to HW, I do not like to do it here
*/
vaddr = ioremap(LPASS_CSR_GP_IO_MUX_SPKR_CTL , 4);
if (!vaddr) {
pr_err("%s ioremap failure for addr %x",
__func__, LPASS_CSR_GP_IO_MUX_SPKR_CTL);
return -ENOMEM;
}
/* enable sec MI2S interface to TLMM GPIO */
val = ioread32(vaddr);
val = val | 0x00000002;
pr_debug("%s: quat mux val = %x\n", __func__, val);
iowrite32(val, vaddr);
iounmap(vaddr);
vaddr = ioremap(LPASS_CSR_GP_IO_MUX_MIC_CTL , 4);
if (!vaddr) {
pr_err("%s ioremap failure for addr %x",
__func__, LPASS_CSR_GP_IO_MUX_MIC_CTL);
return -ENOMEM;
}
/* enable QUAT MI2S interface to TLMM GPIO */
val = ioread32(vaddr);
val = val | 0x00020002;
pr_debug("%s: QUAT mux configuration = %x\n", __func__, val);
iowrite32(val, vaddr);
iounmap(vaddr);
return ret;
}
static int msm_snd_enable_quat_mclk(struct snd_soc_codec *codec, int enable,
bool dapm)
{
int ret = 0;
struct snd_soc_card *card = codec->card;
struct msm8939_asoc_mach_data *pdata = snd_soc_card_get_drvdata(card);
pr_debug("%s: enable = %d clk_users = %d\n",
__func__, enable, clk_users);
pr_debug("clock enable\n");
mutex_lock(&pdata->cdc_mclk_mutex);
if (enable) {
clk_users++;
if (clk_users != 1)
goto exit;
else {
pdata->digital_cdc_clk.clk_val = 9600000;
ret = afe_set_digital_codec_core_clock(
AFE_PORT_ID_QUATERNARY_MI2S_RX,
&pdata->digital_cdc_clk);
if (ret < 0) {
pr_err("%s: failed to enable the MCLK\n",
__func__);
clk_users--;
goto exit;
}
quat_enable_mclk = true;
}
} else {
if (quat_enable_mclk) {
clk_users--;
if (!clk_users) {
quat_enable_mclk = false;
pdata->digital_cdc_clk.clk_val = 0;
ret = afe_set_digital_codec_core_clock(
AFE_PORT_ID_QUATERNARY_MI2S_RX,
&pdata->digital_cdc_clk);
if (ret < 0) {
pr_err("%s: failed to enable the MCLK\n",
__func__);
goto exit;
}
}
}
}
exit:
mutex_unlock(&pdata->cdc_mclk_mutex);
return ret;
}
static int msm_quat_mi2s_snd_startup(struct snd_pcm_substream *substream)
{
struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct snd_soc_card *card = rtd->card;
struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
struct snd_soc_codec *codec = rtd->codec;
struct msm8939_asoc_mach_data *pdata = snd_soc_card_get_drvdata(card);
int ret = 0;
pr_debug("%s(): substream = %s stream = %d\n", __func__,
substream->name, substream->stream);
if (((pdata->ext_pa & QUAT_MI2S_ID) == QUAT_MI2S_ID)) {
ret = conf_int_codec_mux_quat(pdata);
if (ret < 0) {
pr_err("%s: failed to conf internal codec mux\n",
__func__);
return ret;
}
ret = msm_snd_enable_quat_mclk(codec, 1, true);
if (ret < 0) {
pr_err("failed to enable mclk\n");
return ret;
}
ret = ext_mi2s_clk_ctl(substream, true);
if (ret < 0) {
pr_err("%s: failed to enable bit clock\n",
__func__);
goto err;
}
ret = pinctrl_select_state(pdata->pinctrl_info.pinctrl,
pdata->pinctrl_info.cdc_lines_act);
if (ret < 0) {
pr_err("%s: failed to select the gpio's state\n",
__func__);
goto err1;
}
} else {
pr_err("%s: error codec type\n", __func__);
}
if (atomic_inc_return(&quat_mi2s_rsc_ref) == 1) {
ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_CBS_CFS);
if (ret < 0)
pr_err("%s: set fmt cpu dai failed\n", __func__);
}
return ret;
err1:
ret = ext_mi2s_clk_ctl(substream, false);
if (ret < 0)
pr_err("%s:failed to disable sclk\n", __func__);
err:
ret = msm_snd_enable_quat_mclk(codec, 0, true);
if (ret < 0)
pr_err("%s:failed to disable mclk\n", __func__);
return ret;
}
static int msm_mi2s_snd_hw_params(struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params)
{
pr_debug("%s(): substream = %s stream = %d\n", __func__,
substream->name, substream->stream);
param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT, mi2s_rx_bit_format);
return 0;
}
static struct snd_soc_ops msm8x16_quat_mi2s_be_ops = {
.startup = msm_quat_mi2s_snd_startup,
.hw_params = msm_mi2s_snd_hw_params,
.shutdown = msm_quat_mi2s_snd_shutdown,
};
static struct snd_soc_ops slimbus_be_ops = {
.hw_params = msm_snd_hw_params,
};
static struct snd_soc_dai_link msm8x16_9306_dai[] = {
/* Backend DAI Links */
{
.name = LPASS_BE_SLIMBUS_0_RX,
.stream_name = "Slimbus Playback",
.cpu_dai_name = "msm-dai-q6-dev.16384",
.platform_name = "msm-pcm-routing",
.codec_name = "tapan_codec",
.codec_dai_name = "tapan_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,
.ignore_pmdown_time = 1, /* dai link has playback support */
.ignore_suspend = 1,
.ops = &slimbus_be_ops,
},
{
.name = LPASS_BE_SLIMBUS_0_TX,
.stream_name = "Slimbus Capture",
.cpu_dai_name = "msm-dai-q6-dev.16385",
.platform_name = "msm-pcm-routing",
.codec_name = "tapan_codec",
.codec_dai_name = "tapan_tx1",
.no_pcm = 1,
.be_id = MSM_BACKEND_DAI_SLIMBUS_0_TX,
.be_hw_params_fixup = msm_slim_0_tx_be_hw_params_fixup,
.ignore_suspend = 1,
.ops = &slimbus_be_ops,
},
{
.name = LPASS_BE_SLIMBUS_1_RX,
.stream_name = "Slimbus1 Playback",
.cpu_dai_name = "msm-dai-q6-dev.16386",
.platform_name = "msm-pcm-routing",
.codec_name = "tapan_codec",
.codec_dai_name = "tapan_rx1",
.no_pcm = 1,
.be_id = MSM_BACKEND_DAI_SLIMBUS_1_RX,
.be_hw_params_fixup = msm_slim_0_rx_be_hw_params_fixup,
.ops = &slimbus_be_ops,
/* dai link has playback support */
.ignore_pmdown_time = 1,
.ignore_suspend = 1,
},
{
.name = LPASS_BE_SLIMBUS_1_TX,
.stream_name = "Slimbus1 Capture",
.cpu_dai_name = "msm-dai-q6-dev.16387",
.platform_name = "msm-pcm-routing",
.codec_name = "tapan_codec",
.codec_dai_name = "tapan_tx1",
.no_pcm = 1,
.be_id = MSM_BACKEND_DAI_SLIMBUS_1_TX,
.be_hw_params_fixup = msm_slim_0_tx_be_hw_params_fixup,
.ops = &slimbus_be_ops,
.ignore_suspend = 1,
},
{
.name = LPASS_BE_SLIMBUS_3_RX,
.stream_name = "Slimbus3 Playback",
.cpu_dai_name = "msm-dai-q6-dev.16390",
.platform_name = "msm-pcm-routing",
.codec_name = "tapan_codec",
.codec_dai_name = "tapan_rx1",
.no_pcm = 1,
.be_id = MSM_BACKEND_DAI_SLIMBUS_3_RX,
.be_hw_params_fixup = msm_slim_0_rx_be_hw_params_fixup,
.ops = &slimbus_be_ops,
/* dai link has playback support */
.ignore_pmdown_time = 1,
.ignore_suspend = 1,
},
{
.name = LPASS_BE_SLIMBUS_3_TX,
.stream_name = "Slimbus3 Capture",
.cpu_dai_name = "msm-dai-q6-dev.16391",
.platform_name = "msm-pcm-routing",
.codec_name = "tapan_codec",
.codec_dai_name = "tapan_tx1",
.no_pcm = 1,
.be_id = MSM_BACKEND_DAI_SLIMBUS_3_TX,
.be_hw_params_fixup = msm_slim_0_tx_be_hw_params_fixup,
.ops = &slimbus_be_ops,
.ignore_suspend = 1,
},
{
.name = LPASS_BE_SLIMBUS_4_RX,
.stream_name = "Slimbus4 Playback",
.cpu_dai_name = "msm-dai-q6-dev.16392",
.platform_name = "msm-pcm-routing",
.codec_name = "tapan_codec",
.codec_dai_name = "tapan_rx1",
.no_pcm = 1,
.be_id = MSM_BACKEND_DAI_SLIMBUS_4_RX,
.be_hw_params_fixup = msm_slim_0_rx_be_hw_params_fixup,
.ops = &slimbus_be_ops,
/* dai link has playback support */
.ignore_pmdown_time = 1,
.ignore_suspend = 1,
},
{
.name = LPASS_BE_SLIMBUS_5_TX,
.stream_name = "Slimbus5 Capture",
.cpu_dai_name = "msm-dai-q6-dev.16395",
.platform_name = "msm-pcm-routing",
.codec_name = "tapan_codec",
.codec_dai_name = "tapan_tx1",
.no_pcm = 1,
.be_id = MSM_BACKEND_DAI_SLIMBUS_5_TX,
.be_hw_params_fixup = msm_slim_0_tx_be_hw_params_fixup,
.ops = &slimbus_be_ops,
.ignore_suspend = 1,
},
};
static struct snd_soc_dai_link msm8x16_9302_dai[] = {
/* Backend DAI Links */
{
.name = LPASS_BE_SLIMBUS_0_RX,
.stream_name = "Slimbus Playback",
.cpu_dai_name = "msm-dai-q6-dev.16384",
.platform_name = "msm-pcm-routing",
.codec_name = "tapan_codec",
.codec_dai_name = "tapan9302_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,
.ignore_pmdown_time = 1, /* dai link has playback support */
.ignore_suspend = 1,
.ops = &slimbus_be_ops,
},
{
.name = LPASS_BE_SLIMBUS_0_TX,
.stream_name = "Slimbus Capture",
.cpu_dai_name = "msm-dai-q6-dev.16385",
.platform_name = "msm-pcm-routing",
.codec_name = "tapan_codec",
.codec_dai_name = "tapan9302_tx1",
.no_pcm = 1,
.be_id = MSM_BACKEND_DAI_SLIMBUS_0_TX,
.be_hw_params_fixup = msm_slim_0_tx_be_hw_params_fixup,
.ignore_suspend = 1,
.ops = &slimbus_be_ops,
},
{
.name = LPASS_BE_SLIMBUS_1_RX,
.stream_name = "Slimbus1 Playback",
.cpu_dai_name = "msm-dai-q6-dev.16386",
.platform_name = "msm-pcm-routing",
.codec_name = "tapan_codec",
.codec_dai_name = "tapan9302_rx1",
.no_pcm = 1,
.be_id = MSM_BACKEND_DAI_SLIMBUS_1_RX,
.be_hw_params_fixup = msm_slim_0_rx_be_hw_params_fixup,
.ops = &slimbus_be_ops,
/* dai link has playback support */
.ignore_pmdown_time = 1,
.ignore_suspend = 1,
},
{
.name = LPASS_BE_SLIMBUS_1_TX,
.stream_name = "Slimbus1 Capture",
.cpu_dai_name = "msm-dai-q6-dev.16387",
.platform_name = "msm-pcm-routing",
.codec_name = "tapan_codec",
.codec_dai_name = "tapan9302_tx1",
.no_pcm = 1,
.be_id = MSM_BACKEND_DAI_SLIMBUS_1_TX,
.be_hw_params_fixup = msm_slim_0_tx_be_hw_params_fixup,
.ops = &slimbus_be_ops,
.ignore_suspend = 1,
},
{
.name = LPASS_BE_SLIMBUS_3_RX,
.stream_name = "Slimbus3 Playback",
.cpu_dai_name = "msm-dai-q6-dev.16390",
.platform_name = "msm-pcm-routing",
.codec_name = "tapan_codec",
.codec_dai_name = "tapan9302_rx1",
.no_pcm = 1,
.be_id = MSM_BACKEND_DAI_SLIMBUS_3_RX,
.be_hw_params_fixup = msm_slim_0_rx_be_hw_params_fixup,
.ops = &slimbus_be_ops,
/* dai link has playback support */
.ignore_pmdown_time = 1,
.ignore_suspend = 1,
},
{
.name = LPASS_BE_SLIMBUS_3_TX,
.stream_name = "Slimbus3 Capture",
.cpu_dai_name = "msm-dai-q6-dev.16391",
.platform_name = "msm-pcm-routing",
.codec_name = "tapan_codec",
.codec_dai_name = "tapan9302_tx1",
.no_pcm = 1,
.be_id = MSM_BACKEND_DAI_SLIMBUS_3_TX,
.be_hw_params_fixup = msm_slim_0_tx_be_hw_params_fixup,
.ops = &slimbus_be_ops,
.ignore_suspend = 1,
},
{
.name = LPASS_BE_SLIMBUS_4_RX,
.stream_name = "Slimbus4 Playback",
.cpu_dai_name = "msm-dai-q6-dev.16392",
.platform_name = "msm-pcm-routing",
.codec_name = "tapan_codec",
.codec_dai_name = "tapan9302_rx1",
.no_pcm = 1,
.be_id = MSM_BACKEND_DAI_SLIMBUS_4_RX,
.be_hw_params_fixup = msm_slim_0_rx_be_hw_params_fixup,
.ops = &slimbus_be_ops,
/* dai link has playback support */
.ignore_pmdown_time = 1,
.ignore_suspend = 1,
},
};
static struct snd_soc_dai_link msm8x16_9330_dai[] = {
/* Backend DAI Links */
{
.name = LPASS_BE_SLIMBUS_0_RX,
.stream_name = "Slimbus Playback",
.cpu_dai_name = "msm-dai-q6-dev.16384",
.platform_name = "msm-pcm-routing",
.codec_name = "tomtom_codec",
.codec_dai_name = "tomtom_rx1",
.no_pcm = 1,
.be_id = MSM_BACKEND_DAI_SLIMBUS_0_RX,
.init = &msm_audrx_init_tomtom,
.be_hw_params_fixup = msm_slim_0_rx_be_hw_params_fixup,
.ignore_pmdown_time = 1, /* dai link has playback support */
.ignore_suspend = 1,
.ops = &slimbus_be_ops,
},
{
.name = LPASS_BE_SLIMBUS_0_TX,
.stream_name = "Slimbus Capture",
.cpu_dai_name = "msm-dai-q6-dev.16385",
.platform_name = "msm-pcm-routing",
.codec_name = "tomtom_codec",
.codec_dai_name = "tomtom_tx1",
.no_pcm = 1,
.be_id = MSM_BACKEND_DAI_SLIMBUS_0_TX,
.be_hw_params_fixup = msm_slim_0_tx_be_hw_params_fixup,
.ignore_suspend = 1,
.ops = &slimbus_be_ops,
},
{
.name = LPASS_BE_SLIMBUS_1_RX,
.stream_name = "Slimbus1 Playback",
.cpu_dai_name = "msm-dai-q6-dev.16386",
.platform_name = "msm-pcm-routing",
.codec_name = "tomtom_codec",
.codec_dai_name = "tomtom_rx1",
.no_pcm = 1,
.be_id = MSM_BACKEND_DAI_SLIMBUS_1_RX,
.be_hw_params_fixup = msm_slim_0_rx_be_hw_params_fixup,
.ops = &slimbus_be_ops,
/* dai link has playback support */
.ignore_pmdown_time = 1,
.ignore_suspend = 1,
},
{
.name = LPASS_BE_SLIMBUS_1_TX,
.stream_name = "Slimbus1 Capture",
.cpu_dai_name = "msm-dai-q6-dev.16387",
.platform_name = "msm-pcm-routing",
.codec_name = "tomtom_codec",
.codec_dai_name = "tomtom_tx1",
.no_pcm = 1,
.be_id = MSM_BACKEND_DAI_SLIMBUS_1_TX,
.be_hw_params_fixup = msm_slim_0_tx_be_hw_params_fixup,
.ops = &slimbus_be_ops,
.ignore_suspend = 1,
},
{
.name = LPASS_BE_SLIMBUS_3_RX,
.stream_name = "Slimbus3 Playback",
.cpu_dai_name = "msm-dai-q6-dev.16390",
.platform_name = "msm-pcm-routing",
.codec_name = "tomtom_codec",
.codec_dai_name = "tomtom_rx1",
.no_pcm = 1,
.be_id = MSM_BACKEND_DAI_SLIMBUS_3_RX,
.be_hw_params_fixup = msm_slim_0_rx_be_hw_params_fixup,
.ops = &slimbus_be_ops,
/* dai link has playback support */
.ignore_pmdown_time = 1,
.ignore_suspend = 1,
},
{
.name = LPASS_BE_SLIMBUS_3_TX,
.stream_name = "Slimbus3 Capture",
.cpu_dai_name = "msm-dai-q6-dev.16391",
.platform_name = "msm-pcm-routing",
.codec_name = "tomtom_codec",
.codec_dai_name = "tomtom_tx1",
.no_pcm = 1,
.be_id = MSM_BACKEND_DAI_SLIMBUS_3_TX,
.be_hw_params_fixup = msm_slim_0_tx_be_hw_params_fixup,
.ops = &slimbus_be_ops,
.ignore_suspend = 1,
},
{
.name = LPASS_BE_SLIMBUS_4_RX,
.stream_name = "Slimbus4 Playback",
.cpu_dai_name = "msm-dai-q6-dev.16392",
.platform_name = "msm-pcm-routing",
.codec_name = "tomtom_codec",
.codec_dai_name = "tomtom_rx1",
.no_pcm = 1,
.be_id = MSM_BACKEND_DAI_SLIMBUS_4_RX,
.be_hw_params_fixup = msm_slim_0_rx_be_hw_params_fixup,
.ops = &slimbus_be_ops,
/* dai link has playback support */
.ignore_pmdown_time = 1,
.ignore_suspend = 1,
},
/* CPE LSM FE */
{
.name = "CPE Listen service",
.stream_name = "CPE Listen Audio Service",
.cpu_dai_name = "CPE_LSM_NOHOST",
.platform_name = "msm-cpe-lsm",
.trigger = {SND_SOC_DPCM_TRIGGER_POST,
SND_SOC_DPCM_TRIGGER_POST },
.no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
.ignore_suspend = 1,
.ignore_pmdown_time = 1,
.codec_dai_name = "tomtom_mad1",
.codec_name = "tomtom_codec",
},
/* MAD BE */
{
.name = LPASS_BE_SLIMBUS_5_TX,
.stream_name = "Slimbus5 Capture",
.cpu_dai_name = "msm-dai-q6-dev.16395",
.platform_name = "msm-pcm-routing",
.codec_name = "tomtom_codec",
.codec_dai_name = "tomtom_mad1",
.no_pcm = 1,
.async_ops = ASYNC_DPCM_SND_SOC_PREPARE,
.be_id = MSM_BACKEND_DAI_SLIMBUS_5_TX,
.be_hw_params_fixup = msm_slim_5_tx_be_hw_params_fixup,
.ignore_suspend = 1,
},
};
/* Digital audio interface glue - connects codec <---> CPU */
static struct snd_soc_dai_link msm8x16_dai[] = {
/* FrontEnd DAI Links */
{/* hw:x,0 */
.name = "MSM8X16 Media1",
.stream_name = "MultiMedia1",
.cpu_dai_name = "MultiMedia1",
.platform_name = "msm-pcm-dsp.0",
.dynamic = 1,
.trigger = {SND_SOC_DPCM_TRIGGER_POST,
SND_SOC_DPCM_TRIGGER_POST},
.codec_dai_name = "snd-soc-dummy-dai",
.codec_name = "snd-soc-dummy",
.ignore_suspend = 1,
/* this dainlink has playback support */
.ignore_pmdown_time = 1,
.be_id = MSM_FRONTEND_DAI_MULTIMEDIA1
},
{/* hw:x,1 */
.name = "MSM8X16 Media2",
.stream_name = "MultiMedia2",
.cpu_dai_name = "MultiMedia2",
.platform_name = "msm-pcm-dsp.0",
.dynamic = 1,
.codec_dai_name = "snd-soc-dummy-dai",
.codec_name = "snd-soc-dummy",
.trigger = {SND_SOC_DPCM_TRIGGER_POST,
SND_SOC_DPCM_TRIGGER_POST},
.ignore_suspend = 1,
/* this dainlink has playback support */
.ignore_pmdown_time = 1,
.be_id = MSM_FRONTEND_DAI_MULTIMEDIA2,
},
{/* hw:x,2 */
.name = "Circuit-Switch Voice",
.stream_name = "CS-Voice",
.cpu_dai_name = "CS-VOICE",
.platform_name = "msm-pcm-voice",
.dynamic = 1,
.codec_dai_name = "snd-soc-dummy-dai",
.codec_name = "snd-soc-dummy",
.trigger = {SND_SOC_DPCM_TRIGGER_POST,
SND_SOC_DPCM_TRIGGER_POST},
.no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
.ignore_suspend = 1,
/* this dainlink has playback support */
.ignore_pmdown_time = 1,
.be_id = MSM_FRONTEND_DAI_CS_VOICE,
},
{/* hw:x,3 */
.name = "MSM VoIP",
.stream_name = "VoIP",
.cpu_dai_name = "VoIP",
.platform_name = "msm-voip-dsp",
.dynamic = 1,
.trigger = {SND_SOC_DPCM_TRIGGER_POST,
SND_SOC_DPCM_TRIGGER_POST},
.codec_dai_name = "snd-soc-dummy-dai",
.codec_name = "snd-soc-dummy",
.ignore_suspend = 1,
/* this dainlink has playback support */
.ignore_pmdown_time = 1,
.be_id = MSM_FRONTEND_DAI_VOIP,
},
{/* hw:x,4 */
.name = "MSM8X16 LPA",
.stream_name = "LPA",
.cpu_dai_name = "MultiMedia3",
.platform_name = "msm-pcm-lpa",
.dynamic = 1,
.trigger = {SND_SOC_DPCM_TRIGGER_POST,
SND_SOC_DPCM_TRIGGER_POST},
.codec_dai_name = "snd-soc-dummy-dai",
.codec_name = "snd-soc-dummy",
.ignore_suspend = 1,
/* this dainlink has playback support */
.ignore_pmdown_time = 1,
.be_id = MSM_FRONTEND_DAI_MULTIMEDIA3,
},
/* Hostless PCM purpose */
{/* hw:x,5 */
.name = "SLIMBUS_0 Hostless",
.stream_name = "SLIMBUS_0 Hostless",
.cpu_dai_name = "SLIMBUS0_HOSTLESS",
.platform_name = "msm-pcm-hostless",
.dynamic = 1,
.trigger = {SND_SOC_DPCM_TRIGGER_POST,
SND_SOC_DPCM_TRIGGER_POST},
.no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
.ignore_suspend = 1,
.ignore_pmdown_time = 1,
/* This dainlink has MI2S support */
.codec_dai_name = "snd-soc-dummy-dai",
.codec_name = "snd-soc-dummy",
},
{/* hw:x,6 */
.name = "INT_FM Hostless",
.stream_name = "INT_FM Hostless",
.cpu_dai_name = "INT_FM_HOSTLESS",
.platform_name = "msm-pcm-hostless",
.dynamic = 1,
.trigger = {SND_SOC_DPCM_TRIGGER_POST,
SND_SOC_DPCM_TRIGGER_POST},
.no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
.ignore_suspend = 1,
/* this dainlink has playback support */
.ignore_pmdown_time = 1,
.codec_dai_name = "snd-soc-dummy-dai",
.codec_name = "snd-soc-dummy",
},
{/* hw:x,7 */
.name = "MSM AFE-PCM RX",
.stream_name = "AFE-PROXY RX",
.cpu_dai_name = "msm-dai-q6-dev.241",
.codec_name = "msm-stub-codec.1",
.codec_dai_name = "msm-stub-rx",
.platform_name = "msm-pcm-afe",
.ignore_suspend = 1,
/* this dainlink has playback support */
.ignore_pmdown_time = 1,
},
{/* hw:x,8 */
.name = "MSM AFE-PCM TX",
.stream_name = "AFE-PROXY TX",
.cpu_dai_name = "msm-dai-q6-dev.240",
.codec_name = "msm-stub-codec.1",
.codec_dai_name = "msm-stub-tx",
.platform_name = "msm-pcm-afe",
.ignore_suspend = 1,
},
{/* hw:x,9 */
.name = "MSM8X16 Compr",
.stream_name = "COMPR",
.cpu_dai_name = "MultiMedia4",
.platform_name = "msm-compress-dsp",
.dynamic = 1,
.trigger = {SND_SOC_DPCM_TRIGGER_POST,
SND_SOC_DPCM_TRIGGER_POST},
.codec_dai_name = "snd-soc-dummy-dai",
.codec_name = "snd-soc-dummy",
.ignore_suspend = 1,
.ignore_pmdown_time = 1,
/* this dainlink has playback support */
.be_id = MSM_FRONTEND_DAI_MULTIMEDIA4,
},
{/* hw:x,10 */
.name = "AUXPCM Hostless",
.stream_name = "AUXPCM Hostless",
.cpu_dai_name = "AUXPCM_HOSTLESS",
.platform_name = "msm-pcm-hostless",
.dynamic = 1,
.trigger = {SND_SOC_DPCM_TRIGGER_POST,
SND_SOC_DPCM_TRIGGER_POST},
.no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
.ignore_suspend = 1,
/* this dainlink has playback support */
.ignore_pmdown_time = 1,
.codec_dai_name = "snd-soc-dummy-dai",
.codec_name = "snd-soc-dummy",
},
{/* hw:x,11 */
.name = "SLIMBUS_1 Hostless",
.stream_name = "SLIMBUS_1 Hostless",
.cpu_dai_name = "SLIMBUS1_HOSTLESS",
.platform_name = "msm-pcm-hostless",
.dynamic = 1,
.trigger = {SND_SOC_DPCM_TRIGGER_POST,
SND_SOC_DPCM_TRIGGER_POST},
.no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
.ignore_suspend = 1,
.ignore_pmdown_time = 1, /* dai link has playback support */
.codec_dai_name = "snd-soc-dummy-dai",
.codec_name = "snd-soc-dummy",
},
{/* hw:x,12 */
.name = "MSM8x16 LowLatency",
.stream_name = "MultiMedia5",
.cpu_dai_name = "MultiMedia5",
.platform_name = "msm-pcm-dsp.1",
.dynamic = 1,
.codec_dai_name = "snd-soc-dummy-dai",
.codec_name = "snd-soc-dummy",
.trigger = {SND_SOC_DPCM_TRIGGER_POST,
SND_SOC_DPCM_TRIGGER_POST},
.ignore_suspend = 1,
/* this dainlink has playback support */
.ignore_pmdown_time = 1,
.be_id = MSM_FRONTEND_DAI_MULTIMEDIA5,
},
{/* hw:x,13 */
.name = "Voice2",
.stream_name = "Voice2",
.cpu_dai_name = "Voice2",
.platform_name = "msm-pcm-voice",
.dynamic = 1,
.trigger = {SND_SOC_DPCM_TRIGGER_POST,
SND_SOC_DPCM_TRIGGER_POST},
.no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
.ignore_suspend = 1,
/* this dainlink has playback support */
.ignore_pmdown_time = 1,
.codec_dai_name = "snd-soc-dummy-dai",
.codec_name = "snd-soc-dummy",
},
{/* hw:x,14 */
.name = "MSM8x16 Media9",
.stream_name = "MultiMedia9",
.cpu_dai_name = "MultiMedia9",
.platform_name = "msm-pcm-dsp.0",
.dynamic = 1,
.codec_dai_name = "snd-soc-dummy-dai",
.codec_name = "snd-soc-dummy",
.trigger = {SND_SOC_DPCM_TRIGGER_POST,
SND_SOC_DPCM_TRIGGER_POST},
.ignore_suspend = 1,
/* This dailink has playback support */
.ignore_pmdown_time = 1,
.be_id = MSM_FRONTEND_DAI_MULTIMEDIA9,
},
{ /* hw:x,15 */
.name = "VoLTE",
.stream_name = "VoLTE",
.cpu_dai_name = "VoLTE",
.platform_name = "msm-pcm-voice",
.dynamic = 1,
.trigger = {SND_SOC_DPCM_TRIGGER_POST,
SND_SOC_DPCM_TRIGGER_POST},
.no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
.ignore_suspend = 1,
/* this dainlink has playback support */
.ignore_pmdown_time = 1,
.codec_dai_name = "snd-soc-dummy-dai",
.codec_name = "snd-soc-dummy",
.be_id = MSM_FRONTEND_DAI_VOLTE,
},
{ /* hw:x,16 */
.name = "VoWLAN",
.stream_name = "VoWLAN",
.cpu_dai_name = "VoWLAN",
.platform_name = "msm-pcm-voice",
.dynamic = 1,
.trigger = {SND_SOC_DPCM_TRIGGER_POST,
SND_SOC_DPCM_TRIGGER_POST},
.no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
.ignore_suspend = 1,
.ignore_pmdown_time = 1,
.codec_dai_name = "snd-soc-dummy-dai",
.codec_name = "snd-soc-dummy",
.be_id = MSM_FRONTEND_DAI_VOWLAN,
},
{/* hw:x,17 */
.name = "INT_HFP_BT Hostless",
.stream_name = "INT_HFP_BT Hostless",
.cpu_dai_name = "INT_HFP_BT_HOSTLESS",
.platform_name = "msm-pcm-hostless",
.dynamic = 1,
.trigger = {SND_SOC_DPCM_TRIGGER_POST,
SND_SOC_DPCM_TRIGGER_POST},
.no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
.ignore_suspend = 1,
/* this dai link has playback support */
.ignore_pmdown_time = 1,
.codec_dai_name = "snd-soc-dummy-dai",
.codec_name = "snd-soc-dummy",
},
{/* hw:x,18 */
.name = "MSM8916 HFP TX",
.stream_name = "MultiMedia6",
.cpu_dai_name = "MultiMedia6",
.platform_name = "msm-pcm-loopback",
.dynamic = 1,
.codec_dai_name = "snd-soc-dummy-dai",
.codec_name = "snd-soc-dummy",
.trigger = {SND_SOC_DPCM_TRIGGER_POST,
SND_SOC_DPCM_TRIGGER_POST},
.ignore_suspend = 1,
.no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
/* this dai link has playback support */
.ignore_pmdown_time = 1,
.be_id = MSM_FRONTEND_DAI_MULTIMEDIA6,
},
/* LSM FE */
{/* hw:x,19 */
.name = "Listen 1 Audio Service",
.stream_name = "Listen 1 Audio Service",
.cpu_dai_name = "LSM1",
.platform_name = "msm-lsm-client",
.dynamic = 1,
.trigger = {SND_SOC_DPCM_TRIGGER_POST,
SND_SOC_DPCM_TRIGGER_POST },
.no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
.ignore_suspend = 1,
.ignore_pmdown_time = 1,
.codec_dai_name = "snd-soc-dummy-dai",
.codec_name = "snd-soc-dummy",
.be_id = MSM_FRONTEND_DAI_LSM1,
},
{/* hw:x,20 */
.name = "Listen 2 Audio Service",
.stream_name = "Listen 2 Audio Service",
.cpu_dai_name = "LSM2",
.platform_name = "msm-lsm-client",
.dynamic = 1,
.trigger = {SND_SOC_DPCM_TRIGGER_POST,
SND_SOC_DPCM_TRIGGER_POST },
.no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
.ignore_suspend = 1,
.ignore_pmdown_time = 1,
.codec_dai_name = "snd-soc-dummy-dai",
.codec_name = "snd-soc-dummy",
.be_id = MSM_FRONTEND_DAI_LSM2,
},
{/* hw:x,21 */
.name = "Listen 3 Audio Service",
.stream_name = "Listen 3 Audio Service",
.cpu_dai_name = "LSM3",
.platform_name = "msm-lsm-client",
.dynamic = 1,
.trigger = {SND_SOC_DPCM_TRIGGER_POST,
SND_SOC_DPCM_TRIGGER_POST },
.no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
.ignore_suspend = 1,
.ignore_pmdown_time = 1,
.codec_dai_name = "snd-soc-dummy-dai",
.codec_name = "snd-soc-dummy",
.be_id = MSM_FRONTEND_DAI_LSM3,
},
{/* hw:x,22 */
.name = "Listen 4 Audio Service",
.stream_name = "Listen 4 Audio Service",
.cpu_dai_name = "LSM4",
.platform_name = "msm-lsm-client",
.dynamic = 1,
.trigger = {SND_SOC_DPCM_TRIGGER_POST,
SND_SOC_DPCM_TRIGGER_POST },
.no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
.ignore_suspend = 1,
.ignore_pmdown_time = 1,
.codec_dai_name = "snd-soc-dummy-dai",
.codec_name = "snd-soc-dummy",
.be_id = MSM_FRONTEND_DAI_LSM4,
},
{/* hw:x,23 */
.name = "Listen 5 Audio Service",
.stream_name = "Listen 5 Audio Service",
.cpu_dai_name = "LSM5",
.platform_name = "msm-lsm-client",
.dynamic = 1,
.trigger = {SND_SOC_DPCM_TRIGGER_POST,
SND_SOC_DPCM_TRIGGER_POST },
.no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
.ignore_suspend = 1,
.ignore_pmdown_time = 1,
.codec_dai_name = "snd-soc-dummy-dai",
.codec_name = "snd-soc-dummy",
.be_id = MSM_FRONTEND_DAI_LSM5,
},
{/* hw:x,24 */
.name = "MSM8916 ULL",
.stream_name = "MultiMedia7",
.cpu_dai_name = "MultiMedia7",
.platform_name = "msm-pcm-dsp.1",
.dynamic = 1,
.codec_dai_name = "snd-soc-dummy-dai",
.codec_name = "snd-soc-dummy",
.trigger = {SND_SOC_DPCM_TRIGGER_POST,
SND_SOC_DPCM_TRIGGER_POST},
.ignore_suspend = 1,
/* this dainlink has playback support */
.ignore_pmdown_time = 1,
.be_id = MSM_FRONTEND_DAI_MULTIMEDIA7,
},
{/* hw:x,25 */
.name = "SLIMBUS_3 Hostless",
.stream_name = "SLIMBUS_3 Hostless",
.cpu_dai_name = "SLIMBUS3_HOSTLESS",
.platform_name = "msm-pcm-hostless",
.dynamic = 1,
.trigger = {SND_SOC_DPCM_TRIGGER_POST,
SND_SOC_DPCM_TRIGGER_POST},
.no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
.ignore_suspend = 1,
.ignore_pmdown_time = 1, /* dai link has playback support */
.codec_dai_name = "snd-soc-dummy-dai",
.codec_name = "snd-soc-dummy",
},
{/* hw:x,26 */
.name = "SLIMBUS_4 Hostless",
.stream_name = "SLIMBUS_4 Hostless",
.cpu_dai_name = "SLIMBUS4_HOSTLESS",
.platform_name = "msm-pcm-hostless",
.dynamic = 1,
.trigger = {SND_SOC_DPCM_TRIGGER_POST,
SND_SOC_DPCM_TRIGGER_POST},
.no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
.ignore_suspend = 1,
.ignore_pmdown_time = 1, /* dai link has playback support */
.codec_dai_name = "snd-soc-dummy-dai",
.codec_name = "snd-soc-dummy",
},
{ /* hw:x,27 */
.name = "QUAT_MI2S Hostless",
.stream_name = "QUAT_MI2S Hostless",
.cpu_dai_name = "QUAT_MI2S_RX_HOSTLESS",
.platform_name = "msm-pcm-hostless",
.dynamic = 1,
.trigger = {SND_SOC_DPCM_TRIGGER_POST,
SND_SOC_DPCM_TRIGGER_POST},
.no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
.ignore_suspend = 1,
/* this dainlink has playback support */
.ignore_pmdown_time = 1,
.codec_dai_name = "snd-soc-dummy-dai",
.codec_name = "snd-soc-dummy",
},
{ /* hw:x, 28 */
.name = "QCHAT",
.stream_name = "QCHAT",
.cpu_dai_name = "QCHAT",
.platform_name = "msm-pcm-voice",
.dynamic = 1,
.trigger = {SND_SOC_DPCM_TRIGGER_POST,
SND_SOC_DPCM_TRIGGER_POST},
.no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
.ignore_suspend = 1,
/* this dainlink has playback support */
.ignore_pmdown_time = 1,
.codec_dai_name = "snd-soc-dummy-dai",
.codec_name = "snd-soc-dummy",
.be_id = MSM_FRONTEND_DAI_QCHAT,
},
{
.name = LPASS_BE_QUAT_MI2S_RX,
.stream_name = "Quaternary MI2S Playback",
.cpu_dai_name = "msm-dai-q6-mi2s.3",
.platform_name = "msm-pcm-routing",
.codec_dai_name = "snd-soc-dummy-dai",
.codec_name = "snd-soc-dummy",
.no_pcm = 1,
.be_id = MSM_BACKEND_DAI_QUATERNARY_MI2S_RX,
.be_hw_params_fixup = msm_be_hw_params_fixup,
.ops = &msm8x16_quat_mi2s_be_ops,
.ignore_pmdown_time = 1, /* dai link has playback support */
.ignore_suspend = 1,
},
{
.name = LPASS_BE_QUAT_MI2S_TX,
.stream_name = "Quaternary MI2S Capture",
.cpu_dai_name = "msm-dai-q6-mi2s.3",
.platform_name = "msm-pcm-routing",
.codec_dai_name = "snd-soc-dummy-dai",
.codec_name = "snd-soc-dummy",
.no_pcm = 1,
.be_id = MSM_BACKEND_DAI_QUATERNARY_MI2S_TX,
.be_hw_params_fixup = msm_be_hw_params_fixup,
.ops = &msm8x16_quat_mi2s_be_ops,
.ignore_suspend = 1,
},
/* Backend I2S DAI Links */
{
.name = LPASS_BE_INT_BT_SCO_RX,
.stream_name = "Internal BT-SCO Playback",
.cpu_dai_name = "msm-dai-q6-dev.12288",
.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_BT_SCO_RX,
.be_hw_params_fixup = msm_btsco_be_hw_params_fixup,
/* this dainlink has playback support */
.ignore_pmdown_time = 1,
.ignore_suspend = 1,
},
{
.name = LPASS_BE_INT_BT_SCO_TX,
.stream_name = "Internal BT-SCO Capture",
.cpu_dai_name = "msm-dai-q6-dev.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,
.ignore_suspend = 1,
},
{
.name = LPASS_BE_INT_FM_RX,
.stream_name = "Internal FM Playback",
.cpu_dai_name = "msm-dai-q6-dev.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,
/* this dainlink has playback support */
.ignore_pmdown_time = 1,
.ignore_suspend = 1,
},
{
.name = LPASS_BE_INT_FM_TX,
.stream_name = "Internal FM Capture",
.cpu_dai_name = "msm-dai-q6-dev.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,
.ignore_suspend = 1,
},
{
.name = LPASS_BE_AFE_PCM_RX,
.stream_name = "AFE Playback",
.cpu_dai_name = "msm-dai-q6-dev.224",
.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_AFE_PCM_RX,
.be_hw_params_fixup = msm_proxy_rx_be_hw_params_fixup,
/* this dainlink has playback support */
.ignore_pmdown_time = 1,
.ignore_suspend = 1,
},
{
.name = LPASS_BE_AFE_PCM_TX,
.stream_name = "AFE Capture",
.cpu_dai_name = "msm-dai-q6-dev.225",
.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_AFE_PCM_TX,
.be_hw_params_fixup = msm_proxy_tx_be_hw_params_fixup,
.ignore_suspend = 1,
},
/* Incall Record Uplink BACK END DAI Link */
{
.name = LPASS_BE_INCALL_RECORD_TX,
.stream_name = "Voice Uplink Capture",
.cpu_dai_name = "msm-dai-q6-dev.32772",
.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_INCALL_RECORD_TX,
.be_hw_params_fixup = msm_be_hw_params_fixup,
.ignore_suspend = 1,
},
/* Incall Record Downlink BACK END DAI Link */
{
.name = LPASS_BE_INCALL_RECORD_RX,
.stream_name = "Voice Downlink Capture",
.cpu_dai_name = "msm-dai-q6-dev.32771",
.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_INCALL_RECORD_RX,
.be_hw_params_fixup = msm_be_hw_params_fixup,
.ignore_suspend = 1,
},
/* Incall Music BACK END DAI Link */
{
.name = LPASS_BE_VOICE_PLAYBACK_TX,
.stream_name = "Voice Farend Playback",
.cpu_dai_name = "msm-dai-q6-dev.32773",
.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_VOICE_PLAYBACK_TX,
.be_hw_params_fixup = msm_be_hw_params_fixup,
.ignore_suspend = 1,
},
/* Incall Music 2 BACK END DAI Link */
{
.name = LPASS_BE_VOICE2_PLAYBACK_TX,
.stream_name = "Voice2 Farend Playback",
.cpu_dai_name = "msm-dai-q6-dev.32770",
.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_VOICE2_PLAYBACK_TX,
.be_hw_params_fixup = msm_be_hw_params_fixup,
.ignore_suspend = 1,
},
};
static struct snd_soc_dai_link msm8x16_9306_dai_links[
ARRAY_SIZE(msm8x16_dai) +
ARRAY_SIZE(msm8x16_9306_dai)];
static struct snd_soc_dai_link msm8x16_9302_dai_links[
ARRAY_SIZE(msm8x16_dai) +
ARRAY_SIZE(msm8x16_9302_dai)];
static struct snd_soc_dai_link msm8x16_9330_dai_links[
ARRAY_SIZE(msm8x16_dai) +
ARRAY_SIZE(msm8x16_9330_dai)];
enum codecs {
TAPAN_CODEC,
TAPAN_9302_CODEC,
TOMTOM_CODEC,
MAX_CODECS,
};
static struct snd_soc_card snd_soc_card_msm[MAX_CODECS];
static struct snd_soc_card snd_card_msm;
static bool msm8939_swap_gnd_mic(struct snd_soc_codec *codec)
{
struct snd_soc_card *card = codec->card;
struct msm8939_asoc_mach_data *pdata = NULL;
int value = 0;
pdata = snd_soc_card_get_drvdata(card);
if (!gpio_is_valid(pdata->us_euro_gpio)) {
pr_err("%s: Invalid gpio: %d", __func__, pdata->us_euro_gpio);
return false;
}
value = gpio_get_value_cansleep(pdata->us_euro_gpio);
pr_debug("%s: swap select switch %d to %d\n", __func__, value, !value);
gpio_set_value_cansleep(pdata->us_euro_gpio, !value);
return true;
}
static int cdc_slim_get_pinctrl(struct platform_device *pdev,
struct msm8939_asoc_mach_data *pdata)
{
struct pinctrl *pinctrl;
int ret;
pinctrl = devm_pinctrl_get(&pdev->dev);
if (IS_ERR(pinctrl)) {
pr_err("%s: Unable to get pinctrl handle\n", __func__);
return -EINVAL;
}
pdata->pinctrl_info.pinctrl = pinctrl;
if (!(pdata->ext_pa & QUAT_MI2S_ID)) {
/* get all the states handles from Device Tree*/
pdata->pinctrl_info.cdc_slim_sus =
pinctrl_lookup_state(pinctrl,
"cdc_slim_lines_sus");
if (IS_ERR(pdata->pinctrl_info.cdc_slim_sus)) {
pr_err("%s: Unable to get pinctrl suspend state handle\n",
__func__);
return -EINVAL;
}
pdata->pinctrl_info.cdc_slim_act = pinctrl_lookup_state(pinctrl,
"cdc_slim_lines_act");
if (IS_ERR(pdata->pinctrl_info.cdc_slim_act)) {
pr_err("%s: Unable to get pinctrl active state handle\n",
__func__);
return -EINVAL;
}
/* Reset the CDC PDM TLMM pins to a default state */
ret = pinctrl_select_state(pdata->pinctrl_info.pinctrl,
pdata->pinctrl_info.cdc_slim_act);
if (ret != 0) {
pr_err("%s: Failed to disable the TLMM pins\n",
__func__);
return -EIO;
}
} else {
pr_debug("QUAT pinctrl\n");
pdata->pinctrl_info.cdc_lines_sus =
pinctrl_lookup_state(pinctrl,
"cdc_lines_quat_ext_sus");
if (IS_ERR(pdata->pinctrl_info.cdc_lines_sus)) {
pr_err("%s: Unable to get pinctrl disable state\n",
__func__);
return -EINVAL;
}
pdata->pinctrl_info.cdc_lines_act =
pinctrl_lookup_state(pinctrl,
"cdc_lines_quat_ext_act");
if (IS_ERR(pdata->pinctrl_info.cdc_lines_act)) {
pr_err("%s: Unable to get pinctrl disable state\n",
__func__);
return -EINVAL;
}
ret = pinctrl_select_state(
pdata->pinctrl_info.pinctrl,
pdata->pinctrl_info.cdc_lines_act);
if (ret != 0) {
pr_err("%s: Failed to disable the TLMM pins\n",
__func__);
return -EIO;
}
}
return 0;
}
static int msm8939_populate_dai_link_component_of_node(
struct snd_soc_card *card)
{
int i, index, ret = 0;
struct device *cdev = card->dev;
struct snd_soc_dai_link *dai_link = card->dai_link;
struct device_node *phandle;
if (!cdev) {
pr_err("%s: Sound card device memory NULL\n", __func__);
return -ENODEV;
}
for (i = 0; i < card->num_links; i++) {
if (dai_link[i].platform_of_node && dai_link[i].cpu_of_node)
continue;
/* populate platform_of_node for snd card dai links */
if (dai_link[i].platform_name &&
!dai_link[i].platform_of_node) {
index = of_property_match_string(cdev->of_node,
"asoc-platform-names",
dai_link[i].platform_name);
if (index < 0) {
pr_debug("%s: No match found for platform name: %s\n",
__func__, dai_link[i].platform_name);
ret = index;
goto cpu_dai;
}
phandle = of_parse_phandle(cdev->of_node,
"asoc-platform",
index);
if (!phandle) {
pr_err("%s: retrieving phandle for platform %s, index %d failed\n",
__func__, dai_link[i].platform_name,
index);
ret = -ENODEV;
goto err;
}
dai_link[i].platform_of_node = phandle;
dai_link[i].platform_name = NULL;
}
cpu_dai:
/* populate cpu_of_node for snd card dai links */
if (dai_link[i].cpu_dai_name && !dai_link[i].cpu_of_node) {
index = of_property_match_string(cdev->of_node,
"asoc-cpu-names",
dai_link[i].cpu_dai_name);
if (index < 0) {
pr_debug("cpu-names not found index = %d\n", i);
goto codec_dai;
}
phandle = of_parse_phandle(cdev->of_node, "asoc-cpu",
index);
if (!phandle) {
pr_err("%s: retrieving phandle for cpu dai %s failed\n",
__func__, dai_link[i].cpu_dai_name);
ret = -ENODEV;
goto err;
}
dai_link[i].cpu_of_node = phandle;
dai_link[i].cpu_dai_name = NULL;
}
codec_dai:
/* populate codec_of_node for snd card dai links */
if (dai_link[i].codec_name && !dai_link[i].codec_of_node) {
index = of_property_match_string(cdev->of_node,
"asoc-codec-names",
dai_link[i].codec_name);
if (index < 0)
continue;
phandle = of_parse_phandle(cdev->of_node, "asoc-codec",
index);
if (!phandle) {
pr_err("%s: retrieving phandle for codec dai %s failed\n",
__func__, dai_link[i].codec_name);
ret = -ENODEV;
goto err;
}
dai_link[i].codec_of_node = phandle;
dai_link[i].codec_name = NULL;
}
}
err:
return ret;
}
static int msm8939_asoc_machine_probe(struct platform_device *pdev)
{
struct snd_soc_card *card = &snd_card_msm;
struct msm8939_asoc_mach_data *pdata = NULL;
const char *ext_pa = "qcom,msm-ext-pa";
const char *ext_pa_str = NULL;
int num_strings = 0;
int ret, i;
pdata = devm_kzalloc(&pdev->dev,
sizeof(struct msm8939_asoc_mach_data), GFP_KERNEL);
if (!pdata) {
dev_err(&pdev->dev, "Can't allocate msm8939_asoc_mach_data\n");
return -ENOMEM;
}
pdev->id = 0;
spdev = pdev;
card->dev = &pdev->dev;
INIT_DELAYED_WORK(&pdata->hs_detect_dwork, hs_detect_work);
mutex_init(&pdata->cdc_mclk_mutex);
atomic_set(&quat_mi2s_rsc_ref, 0);
ret = snd_soc_of_parse_card_name(card, "qcom,model");
if (ret) {
dev_err(&pdev->dev, "parse card name failed, err:%d\n",
ret);
goto err;
}
if (!strcmp(card->name, "msm8939-tapan-snd-card")) {
snd_soc_card_msm[TAPAN_CODEC].name = card->name;
card = &snd_soc_card_msm[TAPAN_CODEC];
memcpy(msm8x16_9306_dai_links, msm8x16_dai,
sizeof(msm8x16_dai));
memcpy(msm8x16_9306_dai_links + ARRAY_SIZE(msm8x16_dai),
msm8x16_9306_dai, sizeof(msm8x16_9306_dai));
card->dai_link = msm8x16_9306_dai_links;
card->num_links = ARRAY_SIZE(msm8x16_9306_dai_links);
pdata->msm8939_codec_fn.mclk_enable_fn = tapan_mclk_enable;
pdata->msm8939_codec_fn.get_afe_config_fn =
tapan_get_afe_config;
pdata->msm8939_codec_fn.mbhc_hs_detect = tapan_hs_detect;
} else if (!strcmp(card->name, "msm8939-tapan9302-snd-card")) {
snd_soc_card_msm[TAPAN_9302_CODEC].name = card->name;
card = &snd_soc_card_msm[TAPAN_9302_CODEC];
memcpy(msm8x16_9302_dai_links, msm8x16_dai,
sizeof(msm8x16_dai));
memcpy(msm8x16_9302_dai_links + ARRAY_SIZE(msm8x16_dai),
msm8x16_9302_dai, sizeof(msm8x16_9302_dai));
card->dai_link = msm8x16_9302_dai_links;
card->num_links = ARRAY_SIZE(msm8x16_9302_dai_links);
pdata->msm8939_codec_fn.mclk_enable_fn = tapan_mclk_enable;
pdata->msm8939_codec_fn.get_afe_config_fn =
tapan_get_afe_config;
pdata->msm8939_codec_fn.mbhc_hs_detect = tapan_hs_detect;
} else if (!strcmp(card->name, "msm8939-tomtom9330-snd-card")) {
snd_soc_card_msm[TOMTOM_CODEC].name = card->name;
card = &snd_soc_card_msm[TOMTOM_CODEC];
memcpy(msm8x16_9330_dai_links, msm8x16_dai,
sizeof(msm8x16_dai));
memcpy(msm8x16_9330_dai_links + ARRAY_SIZE(msm8x16_dai),
msm8x16_9330_dai, sizeof(msm8x16_9330_dai));
card->dai_link = msm8x16_9330_dai_links;
card->num_links = ARRAY_SIZE(msm8x16_9330_dai_links);
pdata->msm8939_codec_fn.mclk_enable_fn = tomtom_mclk_enable;
pdata->msm8939_codec_fn.get_afe_config_fn =
tomtom_get_afe_config;
pdata->msm8939_codec_fn.mbhc_hs_detect = tomtom_hs_detect;
}
card->dev = &pdev->dev;
platform_set_drvdata(pdev, card);
snd_soc_card_set_drvdata(card, pdata);
wcd9xxx_mbhc_cfg.gpio_level_insert = of_property_read_bool(
pdev->dev.of_node,
"qcom,headset-jack-type-NC");
ret = snd_soc_of_parse_audio_routing(card,
"qcom,audio-routing");
if (ret)
goto err;
/* initialize the mclk */
pdata->digital_cdc_clk.i2s_cfg_minor_version =
AFE_API_VERSION_I2S_CONFIG;
pdata->digital_cdc_clk.clk_val = 9600000;
pdata->digital_cdc_clk.clk_root = 5;
pdata->digital_cdc_clk.reserved = 0;
ret = msm8939_populate_dai_link_component_of_node(card);
if (ret) {
ret = -EPROBE_DEFER;
goto err;
}
ret = snd_soc_register_card(card);
if (ret) {
dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n",
ret);
goto err;
}
num_strings = of_property_count_strings(pdev->dev.of_node,
ext_pa);
if (num_strings < 0) {
dev_err(&pdev->dev,
"%s: missing %s in dt node or length is incorrect\n",
__func__, ext_pa);
pdata->ext_pa = 0;
}
for (i = 0; i < num_strings; i++) {
of_property_read_string_index(pdev->dev.of_node,
ext_pa, i, &ext_pa_str);
if (!strcmp(ext_pa_str, "primary"))
pdata->ext_pa = (pdata->ext_pa | PRI_MI2S_ID);
else if (!strcmp(ext_pa_str, "secondary"))
pdata->ext_pa = (pdata->ext_pa | SEC_MI2S_ID);
else if (!strcmp(ext_pa_str, "tertiary"))
pdata->ext_pa = (pdata->ext_pa | TER_MI2S_ID);
else if (!strcmp(ext_pa_str, "quaternary"))
pdata->ext_pa = (pdata->ext_pa | QUAT_MI2S_ID);
}
/* Populate external codec TLMM configs */
ret = cdc_slim_get_pinctrl(pdev, pdata);
if (ret < 0) {
pr_err("failed to get the pdm gpios\n");
goto err;
}
/* Parse US-Euro gpio info from DT. Report no error if us-euro
* entry is not found in DT file as some targets do not support
* US-Euro detection
*/
pdata->us_euro_gpio = of_get_named_gpio(pdev->dev.of_node,
"qcom,cdc-us-euro-gpios", 0);
if (pdata->us_euro_gpio < 0) {
dev_err(&pdev->dev, "property %s not detected in node %s",
"qcom,us-euro-gpios",
pdev->dev.of_node->full_name);
} else {
dev_dbg(&pdev->dev, "%s detected %d",
"qcom,us-euro-gpios", pdata->us_euro_gpio);
wcd9xxx_mbhc_cfg.swap_gnd_mic = msm8939_swap_gnd_mic;
}
return 0;
err:
cancel_delayed_work_sync(&pdata->hs_detect_dwork);
mutex_destroy(&pdata->cdc_mclk_mutex);
devm_kfree(&pdev->dev, pdata);
return ret;
}
static int msm8939_asoc_machine_remove(struct platform_device *pdev)
{
struct snd_soc_card *card = platform_get_drvdata(pdev);
struct msm8939_asoc_mach_data *pdata = snd_soc_card_get_drvdata(card);
snd_soc_unregister_card(card);
mutex_destroy(&pdata->cdc_mclk_mutex);
return 0;
}
static const struct of_device_id msm8939_asoc_machine_of_match[] = {
{ .compatible = "qcom,msm8939-audio-codec", },
{},
};
static struct platform_driver msm8939_asoc_machine_driver = {
.driver = {
.name = DRV_NAME,
.owner = THIS_MODULE,
.pm = &snd_soc_pm_ops,
.of_match_table = msm8939_asoc_machine_of_match,
},
.probe = msm8939_asoc_machine_probe,
.remove = msm8939_asoc_machine_remove,
};
module_platform_driver(msm8939_asoc_machine_driver);
MODULE_DESCRIPTION("ALSA SoC msm");
MODULE_LICENSE("GPL v2");
MODULE_ALIAS("platform:" DRV_NAME);
MODULE_DEVICE_TABLE(of, msm8939_asoc_machine_of_match);