From 8a4518db73ec92bbe9e0b66ee4975a1e2ffb51f5 Mon Sep 17 00:00:00 2001
From: Prabhu Annabathula <prabhu.annabathula@motorola.com>
Date: Wed, 20 Aug 2014 13:26:30 -0500
Subject: [PATCH] ASoC TFA9890: swap gain and ec ref channels on right IC

Left IC configured to send  gain signal on right channel
and ec ref on left channel. Right IC  configured to send
gain signal on left channel and ec ref on right channel.

Change-Id: I35f49f1b7a37f682ceb1839ef0cb2b9807a85490
Signed-off-by: Prabhu Annabathula <prabhu.annabathula@motorola.com>
---
 sound/soc/codecs/tfa9890-core.h |  3 ++-
 sound/soc/codecs/tfa9890.c      | 23 ++++++++++++++++-------
 2 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/sound/soc/codecs/tfa9890-core.h b/sound/soc/codecs/tfa9890-core.h
index 6df2a1d729b3..1cca6bd2ce4f 100644
--- a/sound/soc/codecs/tfa9890-core.h
+++ b/sound/soc/codecs/tfa9890-core.h
@@ -161,7 +161,8 @@
 #define TFA9890_DOLS_GAIN		(0x1)
 /* route gain info on datao pin on right channel */
 #define TFA9890_DORS_GAIN		(0x1 << 3)
-
+/* select gain input channel for stereo config */
+#define TFA9890_GAIN_IN			(0x1 << 5)
 
 
 /* Mute States */
diff --git a/sound/soc/codecs/tfa9890.c b/sound/soc/codecs/tfa9890.c
index 501d50fec59f..add13e2804b5 100644
--- a/sound/soc/codecs/tfa9890.c
+++ b/sound/soc/codecs/tfa9890.c
@@ -1695,22 +1695,31 @@ static int tfa9890_probe(struct snd_soc_codec *codec)
 	if (stereo_mode) {
 		val = snd_soc_read(codec, TFA9890_I2S_CTL_REG);
 		pr_info("%s : val 0x%x\n", tfa9890->tfa_dev, val);
-		/* select right/left channel input for I2S */
+		/* select right/left channel input for I2S and Gain*/
 		if (!strncmp(tfa9890->tfa_dev, "left", 4)) {
 			val = val & (~TFA9890_I2S_CHS12);
 			val = val | TFA9890_I2S_LEFT_IN;
+			snd_soc_write(codec, TFA9890_I2S_CTL_REG, val);
+
+			/* set datao right channel to send gain info */
+			val = snd_soc_read(codec, TFA9890_SYS_CTL2_REG);
+			val = val & (~TFA9890_DORS_DATAO);
+			val = val | TFA9890_DORS_GAIN;
+			snd_soc_write(codec, TFA9890_SYS_CTL2_REG, val);
 			left_codec = codec;
 		} else if (!strncmp(tfa9890->tfa_dev, "right", 5)) {
 			val = val & (~TFA9890_I2S_CHS12);
 			val = val | TFA9890_I2S_RIGHT_IN;
+			val = val | TFA9890_GAIN_IN;
+			snd_soc_write(codec, TFA9890_I2S_CTL_REG, val);
+
+			/* set datao left channel to send gain info */
+			val = snd_soc_read(codec, TFA9890_SYS_CTL2_REG);
+			val = val & (~TFA9890_DOLS_DATAO);
+			val = val | TFA9890_DOLS_GAIN;
+			snd_soc_write(codec, TFA9890_SYS_CTL2_REG, val);
 			right_codec = codec;
 		}
-		snd_soc_write(codec, TFA9890_I2S_CTL_REG, val);
-		/* set datao right channel to send gain info */
-		val = snd_soc_read(codec, TFA9890_SYS_CTL2_REG);
-		val = val & (~TFA9890_DORS_DATAO);
-		val = val | TFA9890_DORS_GAIN;
-		snd_soc_write(codec, TFA9890_SYS_CTL2_REG, val);
 	}
 	snd_soc_dapm_new_widgets(&codec->dapm);
 	snd_soc_dapm_sync(&codec->dapm);
-- 
GitLab