ASoC: codecs: Force enable micbias standalone

Code to enable micbias standalone irrespective
of wcd enable or disable.

Change-Id: If2052fc690e5e1110ebdbf6f9c6dbafc3bc8c493
Signed-off-by: Soumya Managoli <quic_c_smanag@quicinc.com>
This commit is contained in:
Soumya Managoli 2022-04-13 12:01:53 +05:30
parent 3fc201fdf1
commit 21433bb50c
2 changed files with 100 additions and 0 deletions

View File

@ -1,6 +1,7 @@
/* SPDX-License-Identifier: GPL-2.0-only */
/*
* Copyright (c) 2018-2020, The Linux Foundation. All rights reserved.
* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
*/
#ifndef _WCD938X_INTERNAL_H
@ -110,6 +111,7 @@ struct wcd938x_priv {
/* wcd to swr dmic notification */
bool notify_swr_dmic;
struct blocking_notifier_head notifier;
int micb_enabled[WCD938X_MAX_MICBIAS];
};
struct wcd938x_micbias_setting {

View File

@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (c) 2018-2020, The Linux Foundation. All rights reserved.
* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
*/
#include <linux/module.h>
@ -2919,6 +2920,95 @@ static int wcd938x_bcs_put(struct snd_kcontrol *kcontrol,
return 0;
}
/*
* wcd938x_codec_enable_standalone_micbias - enable micbias standalone
* @component: pointer to component instance
* @micb_num: number of micbias to be enabled
* @enable: true to enable micbias or false to disable
*
* This function is used to enable micbias (1, 2, 3 or 4) during
* standalone independent of whether TX use-case is running or not
*
* Return: error code in case of failure or 0 for success
*/
int wcd938x_codec_enable_standalone_micbias(struct snd_soc_component *component,
int micb_num,
bool enable)
{
const char * const micb_names[] = {
DAPM_MICBIAS1_STANDALONE, DAPM_MICBIAS2_STANDALONE,
DAPM_MICBIAS3_STANDALONE, DAPM_MICBIAS4_STANDALONE
};
int micb_index = micb_num - 1;
int rc;
struct snd_soc_dapm_context *dapm =
snd_soc_component_get_dapm(component);
if ((micb_index < 0) || (micb_index > WCD938X_MAX_MICBIAS - 1)) {
dev_err(component->dev, "%s: Invalid micbias index, micb_ind:%d\n",
__func__, micb_index);
return -EINVAL;
}
if (enable)
rc = snd_soc_dapm_force_enable_pin(
dapm,
micb_names[micb_index]);
else
rc = snd_soc_dapm_disable_pin(
dapm,
micb_names[micb_index]);
if (!rc)
snd_soc_dapm_sync(dapm);
else
dev_err(component->dev, "%s: micbias%d force %s pin failed\n",
__func__, micb_num, (enable ? "enable" : "disable"));
return rc;
}
EXPORT_SYMBOL(wcd938x_codec_enable_standalone_micbias);
static int wcd938x_get_micbias(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
{
struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
int micb_num = ((struct soc_multi_mixer_control *)
kcontrol->private_value)->shift;
ucontrol->value.integer.value[0] = wcd938x->micb_enabled[micb_num - 1];
return 0;
}
static int wcd938x_set_micbias(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
{
struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
int micb_num = ((struct soc_multi_mixer_control *)
kcontrol->private_value)->shift;
int value = ucontrol->value.integer.value[0];
bool enable;
int ret;
if ((micb_num != MIC_BIAS_1) && (micb_num != MIC_BIAS_2) &&
(micb_num != MIC_BIAS_3) && (micb_num != MIC_BIAS_4))
return -EINVAL;
enable = !!value;
ret = wcd938x_codec_enable_standalone_micbias(component, micb_num,
enable);
if (ret) {
dev_err(component->dev, "%s: Failed to enable standalone micb:%d\n",
__func__, micb_num);
return ret;
}
wcd938x->micb_enabled[micb_num - 1] = enable;
return ret;
}
static const char * const tx_mode_mux_text_wcd9380[] = {
"ADC_INVALID", "ADC_HIFI", "ADC_LO_HIF", "ADC_NORMAL", "ADC_LP",
};
@ -3045,6 +3135,14 @@ static const struct snd_kcontrol_new wcd938x_snd_controls[] = {
wcd938x_tx_master_ch_get, wcd938x_tx_master_ch_put),
SOC_ENUM_EXT("DMIC7 ChMap", tx_master_ch_enum,
wcd938x_tx_master_ch_get, wcd938x_tx_master_ch_put),
SOC_SINGLE_EXT("MIC BIAS1 Standalone", SND_SOC_NOPM, MIC_BIAS_1, 1, 0,
wcd938x_get_micbias, wcd938x_set_micbias),
SOC_SINGLE_EXT("MIC BIAS2 Standalone", SND_SOC_NOPM, MIC_BIAS_2, 1, 0,
wcd938x_get_micbias, wcd938x_set_micbias),
SOC_SINGLE_EXT("MIC BIAS3 Standalone", SND_SOC_NOPM, MIC_BIAS_3, 1, 0,
wcd938x_get_micbias, wcd938x_set_micbias),
SOC_SINGLE_EXT("MIC BIAS4 Standalone", SND_SOC_NOPM, MIC_BIAS_4, 1, 0,
wcd938x_get_micbias, wcd938x_set_micbias),
};
static const struct snd_kcontrol_new adc1_switch[] = {