Revert "ASoC: msm8960: Use DAPM_PRE and POST for MCLK"
This reverts commit 7687dc0741be36ed1537180e9ac716724dd704b9.
Signed-off-by: Sriranjan Srikantam <cssrika@codeaurora.org>
diff --git a/sound/soc/codecs/wcd9310.c b/sound/soc/codecs/wcd9310.c
index 4b25005..40ea0d4 100644
--- a/sound/soc/codecs/wcd9310.c
+++ b/sound/soc/codecs/wcd9310.c
@@ -49,13 +49,14 @@
struct tabla_priv {
struct snd_soc_codec *codec;
+ u32 ref_cnt;
u32 adc_count;
+ u32 rx_count;
u32 cfilt1_cnt;
u32 cfilt2_cnt;
u32 cfilt3_cnt;
- u32 rx_bias_count;
+
enum tabla_bandgap_type bandgap_type;
- bool mclk_enabled;
bool clock_active;
bool config_mode_active;
bool mbhc_polling_active;
@@ -987,42 +988,6 @@
return 0;
}
-
-static void tabla_enable_rx_bias(struct snd_soc_codec *codec, u32 enable)
-{
- struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
-
- if (enable) {
- tabla->rx_bias_count++;
- if (tabla->rx_bias_count == 1)
- snd_soc_update_bits(codec, TABLA_A_RX_COM_BIAS,
- 0x80, 0x80);
- } else {
- tabla->rx_bias_count--;
- if (!tabla->rx_bias_count)
- snd_soc_update_bits(codec, TABLA_A_RX_COM_BIAS,
- 0x80, 0x00);
- }
-}
-
-static int tabla_codec_enable_rx_bias(struct snd_soc_dapm_widget *w,
- struct snd_kcontrol *kcontrol, int event)
-{
- struct snd_soc_codec *codec = w->codec;
-
- pr_debug("%s %d\n", __func__, event);
-
- switch (event) {
- case SND_SOC_DAPM_PRE_PMU:
- tabla_enable_rx_bias(codec, 1);
- break;
- case SND_SOC_DAPM_POST_PMD:
- tabla_enable_rx_bias(codec, 0);
- break;
- }
- return 0;
-}
-
static const struct snd_soc_dapm_widget tabla_dapm_widgets[] = {
/*RX stuff */
SND_SOC_DAPM_OUTPUT("EAR"),
@@ -1132,10 +1097,6 @@
tabla_codec_enable_charge_pump, SND_SOC_DAPM_POST_PMU |
SND_SOC_DAPM_PRE_PMD),
- SND_SOC_DAPM_SUPPLY("RX_BIAS", SND_SOC_NOPM, 0, 0,
- tabla_codec_enable_rx_bias, SND_SOC_DAPM_PRE_PMU |
- SND_SOC_DAPM_POST_PMD),
-
/* TX */
SND_SOC_DAPM_SUPPLY("CDC_CONN", TABLA_A_CDC_CLK_OTHR_CTL, 2, 0, NULL,
@@ -1384,15 +1345,6 @@
{"LINEOUT4 DAC", "Switch", "RX4 MIX1"},
{"LINEOUT5 DAC", "Switch", "RX7 MIX1"},
- {"DAC1", NULL, "RX_BIAS"},
- {"HPHL DAC", NULL, "RX_BIAS"},
- {"HPHR DAC", NULL, "RX_BIAS"},
- {"LINEOUT1 DAC", NULL, "RX_BIAS"},
- {"LINEOUT2 DAC", NULL, "RX_BIAS"},
- {"LINEOUT3 DAC", NULL, "RX_BIAS"},
- {"LINEOUT4 DAC", NULL, "RX_BIAS"},
- {"LINEOUT5 DAC", NULL, "RX_BIAS"},
-
{"RX1 MIX1", NULL, "RX1 MIX1 INP1"},
{"RX1 MIX1", NULL, "RX1 MIX1 INP2"},
{"RX2 MIX1", NULL, "RX2 MIX1 INP1"},
@@ -1700,58 +1652,72 @@
static int tabla_startup(struct snd_pcm_substream *substream,
struct snd_soc_dai *dai)
{
- pr_debug("%s() substream = %s\n", __func__, substream->name);
+ struct snd_soc_codec *codec = dai->codec;
+ struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
+ int ret = 0;
- return 0;
+ pr_debug("%s()\n", __func__);
+
+ if (!codec) {
+ pr_err("Error, no codec found\n");
+ return -EINVAL;
+ }
+ tabla->ref_cnt++;
+
+ if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
+ tabla->rx_count++;
+ if (tabla->rx_count == 1)
+ snd_soc_update_bits(codec, TABLA_A_RX_COM_BIAS, 0x80,
+ 0x80);
+ }
+
+ if (tabla->mbhc_polling_active && (tabla->ref_cnt == 1)) {
+ tabla_codec_pause_hs_polling(codec);
+ tabla_codec_enable_bandgap(codec, TABLA_BANDGAP_AUDIO_MODE);
+ tabla_codec_enable_clock_block(codec, 0);
+ tabla_codec_calibrate_hs_polling(codec);
+ tabla_codec_start_hs_polling(codec);
+ }
+
+ return ret;
}
static void tabla_shutdown(struct snd_pcm_substream *substream,
struct snd_soc_dai *dai)
{
- pr_debug("%s() substream = %s\n", __func__, substream->name);
-}
-
-
-int tabla_mclk_enable(struct snd_soc_codec *codec, int mclk_enable)
-{
+ struct snd_soc_codec *codec = dai->codec;
struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
- pr_debug("%s() mclk_enable = %u\n", __func__, mclk_enable);
+ pr_debug("%s()\n", __func__);
- if (mclk_enable) {
- tabla->mclk_enabled = true;
+ if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
+ /* Disable LDO */
+ } else {
+ tabla->rx_count--;
+ if (!tabla->rx_count)
+ snd_soc_update_bits(codec, TABLA_A_RX_COM_BIAS, 0x80,
+ 0x00);
+ }
- if (tabla->mbhc_polling_active && (tabla->mclk_enabled)) {
+ if (!tabla->ref_cnt) {
+ pr_err("Error, trying to shutdown codec when already down\n");
+ return;
+ }
+ tabla->ref_cnt--;
+
+ if (tabla->mbhc_polling_active) {
+ if (!tabla->ref_cnt) {
tabla_codec_pause_hs_polling(codec);
tabla_codec_enable_bandgap(codec,
- TABLA_BANDGAP_AUDIO_MODE);
- tabla_codec_enable_clock_block(codec, 0);
+ TABLA_BANDGAP_MBHC_MODE);
+ snd_soc_update_bits(codec, TABLA_A_RX_COM_BIAS, 0x80,
+ 0x80);
+ tabla_codec_enable_clock_block(codec, 1);
tabla_codec_calibrate_hs_polling(codec);
tabla_codec_start_hs_polling(codec);
}
- } else {
-
- if (!tabla->mclk_enabled) {
- pr_err("Error, MCLK already diabled\n");
- return -EINVAL;
- }
- tabla->mclk_enabled = false;
-
- if (tabla->mbhc_polling_active) {
- if (!tabla->mclk_enabled) {
- tabla_codec_pause_hs_polling(codec);
- tabla_codec_enable_bandgap(codec,
- TABLA_BANDGAP_MBHC_MODE);
- tabla_enable_rx_bias(codec, 1);
- tabla_codec_enable_clock_block(codec, 1);
- tabla_codec_calibrate_hs_polling(codec);
- tabla_codec_start_hs_polling(codec);
- }
- snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1,
- 0x05, 0x01);
- }
+ snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x05, 0x01);
}
- return 0;
}
static int tabla_digital_mute(struct snd_soc_dai *codec_dai, int mute)
@@ -1977,9 +1943,9 @@
tabla->mbhc_polling_active = true;
- if (!tabla->mclk_enabled) {
+ if (!tabla->ref_cnt) {
tabla_codec_enable_bandgap(codec, TABLA_BANDGAP_MBHC_MODE);
- tabla_enable_rx_bias(codec, 1);
+ snd_soc_update_bits(codec, TABLA_A_RX_COM_BIAS, 0x80, 0x80);
tabla_codec_enable_clock_block(codec, 1);
}
@@ -2242,7 +2208,7 @@
struct tabla_mbhc_calibration *calibration = tabla->calibration;
int micbias_mbhc_reg;
- if (!tabla->mclk_enabled && !tabla->mbhc_polling_active)
+ if (!tabla->ref_cnt && !tabla->mbhc_polling_active)
tabla_codec_enable_config_mode(codec, 1);
snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x2, 0x2);
@@ -2270,7 +2236,7 @@
calibration->shutdown_plug_removal);
snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0xA, 0x8);
- if (!tabla->mclk_enabled && !tabla->mbhc_polling_active)
+ if (!tabla->ref_cnt && !tabla->mbhc_polling_active)
tabla_codec_enable_config_mode(codec, 0);
snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x00);
@@ -2282,7 +2248,7 @@
tabla_codec_shutdown_hs_removal_detect(codec);
- if (!tabla->mclk_enabled) {
+ if (!tabla->ref_cnt) {
snd_soc_update_bits(codec, TABLA_A_TX_COM_BIAS, 0xE0, 0x00);
tabla_codec_enable_bandgap(codec, TABLA_BANDGAP_AUDIO_MODE);
tabla_codec_enable_clock_block(codec, 0);
@@ -2686,7 +2652,7 @@
snd_soc_codec_set_drvdata(codec, tabla);
- tabla->mclk_enabled = false;
+ tabla->ref_cnt = 0;
tabla->bandgap_type = TABLA_BANDGAP_OFF;
tabla->clock_active = false;
tabla->config_mode_active = false;