asoc: codecs: rt5639/40: Fix false Headset detection
Manoj Gangwal [Fri, 30 Mar 2012 11:04:00 +0000 (16:04 +0530)]
1. Use rt5639/40 internal clk source during jack insert detection.
2. Add delay to 100ms.

Bug 955019

Signed-off-by: Manoj Gangwal <mgangwal@nvidia.com>
Reviewed-on: http://git-master/r/93510
Reviewed-by: Chandler Zhang <chazhang@nvidia.com>
Reviewed-by: Scott Peterson <speterson@nvidia.com>
(cherry picked from commit 4c07fc1b10ac8abbbf167952071e47aa6179a635)

Change-Id: I4021232674f5432392dc013ddc76c3bf08b44ed0
Reviewed-on: http://git-master/r/95874
Reviewed-by: Automatic_Commit_Validation_User
Tested-by: Manoj Gangwal <mgangwal@nvidia.com>
Reviewed-by: Scott Peterson <speterson@nvidia.com>

sound/soc/codecs/rt5639.c
sound/soc/codecs/rt5640.c

index e7fa471..0fd74a4 100644 (file)
@@ -421,8 +421,18 @@ static int rt5639_readable_register(
 int rt5639_headset_detect(struct snd_soc_codec *codec, int jack_insert)
 {
        int jack_type;
+       int sclk_src;
 
        if (jack_insert) {
+               if (SND_SOC_BIAS_OFF == codec->dapm.bias_level) {
+                       snd_soc_write(codec, RT5639_PWR_ANLG1, 0x2004);
+                       snd_soc_write(codec, RT5639_MICBIAS, 0x3830);
+                       snd_soc_write(codec, RT5639_DUMMY1 , 0x3701);
+               }
+               sclk_src = snd_soc_read(codec, RT5639_GLB_CLK) &
+                       RT5639_SCLK_SRC_MASK;
+               snd_soc_update_bits(codec, RT5639_GLB_CLK,
+                       RT5639_SCLK_SRC_MASK, 0x3 << RT5639_SCLK_SRC_SFT);
                snd_soc_update_bits(codec, RT5639_PWR_ANLG1,
                        RT5639_PWR_LDO2, RT5639_PWR_LDO2);
                snd_soc_update_bits(codec, RT5639_PWR_ANLG2,
@@ -434,13 +444,15 @@ int rt5639_headset_detect(struct snd_soc_codec *codec, int jack_insert)
                        RT5639_PWR_MB_PU | RT5639_PWR_CLK25M_PU);
                snd_soc_update_bits(codec, RT5639_DUMMY1,
                        0x1, 0x1);
-               msleep(50);
+               msleep(100);
                if (snd_soc_read(codec, RT5639_IRQ_CTRL2) & 0x8)
                        jack_type = RT5639_HEADPHO_DET;
                else
                        jack_type = RT5639_HEADSET_DET;
                snd_soc_update_bits(codec, RT5639_IRQ_CTRL2,
                        RT5639_MB1_OC_CLR, 0);
+               snd_soc_update_bits(codec, RT5639_GLB_CLK,
+                       RT5639_SCLK_SRC_MASK, sclk_src);
        } else {
                snd_soc_update_bits(codec, RT5639_MICBIAS,
                        RT5639_MIC1_OVCD_MASK,
index 62a13fb..2abfac1 100644 (file)
@@ -422,8 +422,18 @@ static int rt5640_readable_register(
 int rt5640_headset_detect(struct snd_soc_codec *codec, int jack_insert)
 {
        int jack_type;
+       int sclk_src;
 
        if (jack_insert) {
+               if (SND_SOC_BIAS_OFF == codec->dapm.bias_level) {
+                       snd_soc_write(codec, RT5640_PWR_ANLG1, 0x2004);
+                       snd_soc_write(codec, RT5640_MICBIAS, 0x3830);
+                       snd_soc_write(codec, RT5640_DUMMY1 , 0x3701);
+               }
+               sclk_src = snd_soc_read(codec, RT5640_GLB_CLK) &
+                       RT5640_SCLK_SRC_MASK;
+               snd_soc_update_bits(codec, RT5640_GLB_CLK,
+                       RT5640_SCLK_SRC_MASK, 0x3 << RT5640_SCLK_SRC_SFT);
                snd_soc_update_bits(codec, RT5640_PWR_ANLG1,
                        RT5640_PWR_LDO2, RT5640_PWR_LDO2);
                snd_soc_update_bits(codec, RT5640_PWR_ANLG2,
@@ -435,13 +445,15 @@ int rt5640_headset_detect(struct snd_soc_codec *codec, int jack_insert)
                        RT5640_PWR_MB_PU | RT5640_PWR_CLK25M_PU);
                snd_soc_update_bits(codec, RT5640_DUMMY1,
                        0x1, 0x1);
-               msleep(50);
+               msleep(100);
                if (snd_soc_read(codec, RT5640_IRQ_CTRL2) & 0x8)
                        jack_type = RT5640_HEADPHO_DET;
                else
                        jack_type = RT5640_HEADSET_DET;
                snd_soc_update_bits(codec, RT5640_IRQ_CTRL2,
                        RT5640_MB1_OC_CLR, 0);
+               snd_soc_update_bits(codec, RT5640_GLB_CLK,
+                       RT5640_SCLK_SRC_MASK, sclk_src);
        } else {
                snd_soc_update_bits(codec, RT5640_MICBIAS,
                        RT5640_MIC1_OVCD_MASK,