ASoC:  msm/apq: Remove the dependency of AUX PCM TX to AUX PCM RX.

AUX PCM interface is a bi-direction interface which RX and TX paths
share the clock and sync word. In current design, it is assumed
when TX path is activated, RX path was enabled beforehand. So the
AUX PCM clock and GPIO pin configuration is only tied to AUX PCM RX
path.  There is use case that only AUX PCM TX path is activated by
application so the AUX PCM clock and GPIOs are never configured
in this case which causes recording from AUX PCM TX failed to
capture any audio sample.

The solution is to update the clock and GPIO pin configuration to
both RX and TX path and then use an atomic reference counter to
prevent them configured twice.

CRs-Fixed: 397095
Signed-off-by: Kuirong Wang <kuirongw@codeaurora.org>
(cherry picked from commit ae395b024194bf6ae633a67dd1c2a5b3c7f1e019)

Conflicts:

	sound/soc/msm/msm8974.c

Change-Id: If7f044de3cc4819e61fe66cd865755dceb5c45eb
Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>
(cherry picked from commit eba5065dc6a84da68e5d9bcf6cb1934324698fec)

Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>
diff --git a/sound/soc/msm/msm8930.c b/sound/soc/msm/msm8930.c
index a577b6a..5b57824 100644
--- a/sound/soc/msm/msm8930.c
+++ b/sound/soc/msm/msm8930.c
@@ -65,6 +65,7 @@
 
 static struct snd_soc_jack hs_jack;
 static struct snd_soc_jack button_jack;
+static atomic_t auxpcm_rsc_ref;
 
 static int msm8930_enable_codec_ext_clk(
 		struct snd_soc_codec *codec, int enable,
@@ -825,8 +826,10 @@
 {
 	int ret = 0;
 
-	pr_debug("%s(): substream = %s\n", __func__, substream->name);
-	ret = msm8930_aux_pcm_get_gpios();
+	pr_debug("%s(): substream = %s, auxpcm_rsc_ref counter = %d\n",
+		__func__, substream->name, atomic_read(&auxpcm_rsc_ref));
+	if (atomic_inc_return(&auxpcm_rsc_ref) == 1)
+		ret = msm8930_aux_pcm_get_gpios();
 	if (ret < 0) {
 		pr_err("%s: Aux PCM GPIO request failed\n", __func__);
 		return -EINVAL;
@@ -837,8 +840,10 @@
 
 static void msm8930_auxpcm_shutdown(struct snd_pcm_substream *substream)
 {
-	pr_debug("%s(): substream = %s\n", __func__, substream->name);
-	msm8930_aux_pcm_free_gpios();
+	pr_debug("%s(): substream = %s, auxpcm_rsc_ref counter = %d\n",
+		__func__, substream->name, atomic_read(&auxpcm_rsc_ref));
+	if (atomic_dec_return(&auxpcm_rsc_ref) == 0)
+		msm8930_aux_pcm_free_gpios();
 }
 
 static void msm8930_shutdown(struct snd_pcm_substream *substream)
@@ -1194,6 +1199,7 @@
 		.no_pcm = 1,
 		.be_id = MSM_BACKEND_DAI_AUXPCM_TX,
 		.be_hw_params_fixup = msm8930_auxpcm_be_params_fixup,
+		.ops = &msm8930_auxpcm_be_ops,
 	},
 	/* Incall Music BACK END DAI Link */
 	{
@@ -1301,6 +1307,7 @@
 	} else
 		msm8930_headset_gpios_configured = 1;
 
+	atomic_set(&auxpcm_rsc_ref, 0);
 	return ret;
 
 }