ASoC: es8316: add interface for rk_headset
authorzhangjun <zhangjun@rock-chips.com>
Sun, 9 Oct 2016 06:41:45 +0000 (14:41 +0800)
committerHuang, Tao <huangtao@rock-chips.com>
Tue, 11 Oct 2016 02:20:32 +0000 (10:20 +0800)
Change-Id: I62f7e78ca4003f6ab90c943a187babd274acc1de
Signed-off-by: zhangjun <zhangjun@rock-chips.com>
sound/soc/codecs/es8316.c

index e5656347cc638e6bf379fb76887c9a8f14508866..06d39fc9e6b995ddc6e8bb750b021398e2a9e8d4 100644 (file)
@@ -40,6 +40,8 @@
 #define GPIO_HIGH 1
 #define es8316_DEF_VOL                 0x1e
 
+static struct snd_soc_codec *es8316_codec;
+
 static const struct reg_default es8316_reg_defaults[] = {
        {0x00, 0x03}, {0x01, 0x03}, {0x02, 0x00}, {0x03, 0x20},
        {0x04, 0x11}, {0x05, 0x00}, {0x06, 0x11}, {0x07, 0x00},
@@ -742,7 +744,8 @@ static void es8316_pcm_shutdown(struct snd_pcm_substream *substream,
        }
 
        if (--es8316->pwr_count == 0) {
-               snd_soc_write(codec, ES8316_SYS_PDN_REG0D, 0x3F);
+               if (!es8316->hp_inserted)
+                       snd_soc_write(codec, ES8316_SYS_PDN_REG0D, 0x3F);
                snd_soc_write(codec, ES8316_CLKMGR_CLKSW_REG01, 0xF3);
        }
 }
@@ -837,7 +840,8 @@ static int es8316_set_bias_level(struct snd_soc_codec *codec,
                snd_soc_write(codec, ES8316_HPMIX_PDN_REG15, 0x33);
                snd_soc_write(codec, ES8316_HPMIX_VOL_REG16, 0x00);
                snd_soc_write(codec, ES8316_ADC_PDN_LINSEL_REG22, 0xC0);
-               snd_soc_write(codec, ES8316_SYS_PDN_REG0D, 0x3F);
+               if (!es8316->hp_inserted)
+                       snd_soc_write(codec, ES8316_SYS_PDN_REG0D, 0x3F);
                snd_soc_write(codec, ES8316_SYS_LP1_REG0E, 0x3F);
                snd_soc_write(codec, ES8316_SYS_LP2_REG0F, 0x1F);
                snd_soc_write(codec, ES8316_RESET_REG00, 0x00);
@@ -952,6 +956,7 @@ static int es8316_suspend(struct snd_soc_codec *codec)
 
 static int es8316_resume(struct snd_soc_codec *codec)
 {
+       struct es8316_priv *es8316 = snd_soc_codec_get_drvdata(codec);
        int ret;
 
        es8316_reset(codec); /* UPDATED BY DAVID,15-3-5 */
@@ -970,7 +975,8 @@ static int es8316_resume(struct snd_soc_codec *codec)
                snd_soc_write(codec, ES8316_HPMIX_SWITCH_REG14, 0x00);
                snd_soc_write(codec, ES8316_HPMIX_PDN_REG15, 0x33);
                snd_soc_write(codec, ES8316_HPMIX_VOL_REG16, 0x00);
-               snd_soc_write(codec, ES8316_SYS_PDN_REG0D, 0x3F);
+               if (!es8316->hp_inserted)
+                       snd_soc_write(codec, ES8316_SYS_PDN_REG0D, 0x3F);
                snd_soc_write(codec, ES8316_SYS_LP1_REG0E, 0xFF);
                snd_soc_write(codec, ES8316_SYS_LP2_REG0F, 0xFF);
                snd_soc_write(codec, ES8316_CLKMGR_CLKSW_REG01, 0xF3);
@@ -989,6 +995,29 @@ static irqreturn_t es8316_irq_handler(int irq, void *data)
        return IRQ_HANDLED;
 }
 
+/*
+ * Call from rk_headset_irq_hook_adc.c
+ *
+ * Enable micbias for HOOK detection and disable external Amplifier
+ * when jack insertion.
+ */
+int es8316_headset_detect(int jack_insert)
+{
+       struct es8316_priv *es8316 = snd_soc_codec_get_drvdata(es8316_codec);
+
+       es8316->hp_inserted = jack_insert;
+
+       /*enable micbias and disable PA*/
+       if (jack_insert) {
+               snd_soc_update_bits(es8316_codec,
+                                   ES8316_SYS_PDN_REG0D, 0x3f, 0);
+               es8316_enable_spk(es8316, false);
+       }
+
+       return 0;
+}
+EXPORT_SYMBOL(es8316_headset_detect);
+
 static void hp_work(struct work_struct *work)
 {
        struct es8316_priv *es8316;
@@ -1008,7 +1037,6 @@ static void hp_work(struct work_struct *work)
        }
 }
 
-static struct snd_soc_codec *es8316_codec;
 static int es8316_probe(struct snd_soc_codec *codec)
 {
        struct es8316_priv *es8316 = snd_soc_codec_get_drvdata(codec);
@@ -1042,7 +1070,9 @@ static int es8316_probe(struct snd_soc_codec *codec)
                        snd_soc_write(codec, ES8316_HPMIX_SWITCH_REG14, 0x00);
                        snd_soc_write(codec, ES8316_HPMIX_PDN_REG15, 0x33);
                        snd_soc_write(codec, ES8316_HPMIX_VOL_REG16, 0x00);
-                       snd_soc_write(codec, ES8316_SYS_PDN_REG0D, 0x3F);
+                       if (!es8316->hp_inserted)
+                               snd_soc_write(codec, ES8316_SYS_PDN_REG0D,
+                                             0x3F);
                        snd_soc_write(codec, ES8316_SYS_LP1_REG0E, 0xFF);
                        snd_soc_write(codec, ES8316_SYS_LP2_REG0F, 0xFF);
                        snd_soc_write(codec, ES8316_CLKMGR_CLKSW_REG01, 0xF3);