Skip to content

Commit 6757922

Browse files
zhangjunrkhuangtao
authored andcommitted
ASoC: es8316: add interface for rk_headset
Change-Id: I62f7e78ca4003f6ab90c943a187babd274acc1de Signed-off-by: zhangjun <zhangjun@rock-chips.com>
1 parent 19d1433 commit 6757922

File tree

1 file changed

+35
-5
lines changed

1 file changed

+35
-5
lines changed

sound/soc/codecs/es8316.c

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
#define GPIO_HIGH 1
4141
#define es8316_DEF_VOL 0x1e
4242

43+
static struct snd_soc_codec *es8316_codec;
44+
4345
static const struct reg_default es8316_reg_defaults[] = {
4446
{0x00, 0x03}, {0x01, 0x03}, {0x02, 0x00}, {0x03, 0x20},
4547
{0x04, 0x11}, {0x05, 0x00}, {0x06, 0x11}, {0x07, 0x00},
@@ -742,7 +744,8 @@ static void es8316_pcm_shutdown(struct snd_pcm_substream *substream,
742744
}
743745

744746
if (--es8316->pwr_count == 0) {
745-
snd_soc_write(codec, ES8316_SYS_PDN_REG0D, 0x3F);
747+
if (!es8316->hp_inserted)
748+
snd_soc_write(codec, ES8316_SYS_PDN_REG0D, 0x3F);
746749
snd_soc_write(codec, ES8316_CLKMGR_CLKSW_REG01, 0xF3);
747750
}
748751
}
@@ -837,7 +840,8 @@ static int es8316_set_bias_level(struct snd_soc_codec *codec,
837840
snd_soc_write(codec, ES8316_HPMIX_PDN_REG15, 0x33);
838841
snd_soc_write(codec, ES8316_HPMIX_VOL_REG16, 0x00);
839842
snd_soc_write(codec, ES8316_ADC_PDN_LINSEL_REG22, 0xC0);
840-
snd_soc_write(codec, ES8316_SYS_PDN_REG0D, 0x3F);
843+
if (!es8316->hp_inserted)
844+
snd_soc_write(codec, ES8316_SYS_PDN_REG0D, 0x3F);
841845
snd_soc_write(codec, ES8316_SYS_LP1_REG0E, 0x3F);
842846
snd_soc_write(codec, ES8316_SYS_LP2_REG0F, 0x1F);
843847
snd_soc_write(codec, ES8316_RESET_REG00, 0x00);
@@ -952,6 +956,7 @@ static int es8316_suspend(struct snd_soc_codec *codec)
952956

953957
static int es8316_resume(struct snd_soc_codec *codec)
954958
{
959+
struct es8316_priv *es8316 = snd_soc_codec_get_drvdata(codec);
955960
int ret;
956961

957962
es8316_reset(codec); /* UPDATED BY DAVID,15-3-5 */
@@ -970,7 +975,8 @@ static int es8316_resume(struct snd_soc_codec *codec)
970975
snd_soc_write(codec, ES8316_HPMIX_SWITCH_REG14, 0x00);
971976
snd_soc_write(codec, ES8316_HPMIX_PDN_REG15, 0x33);
972977
snd_soc_write(codec, ES8316_HPMIX_VOL_REG16, 0x00);
973-
snd_soc_write(codec, ES8316_SYS_PDN_REG0D, 0x3F);
978+
if (!es8316->hp_inserted)
979+
snd_soc_write(codec, ES8316_SYS_PDN_REG0D, 0x3F);
974980
snd_soc_write(codec, ES8316_SYS_LP1_REG0E, 0xFF);
975981
snd_soc_write(codec, ES8316_SYS_LP2_REG0F, 0xFF);
976982
snd_soc_write(codec, ES8316_CLKMGR_CLKSW_REG01, 0xF3);
@@ -989,6 +995,29 @@ static irqreturn_t es8316_irq_handler(int irq, void *data)
989995
return IRQ_HANDLED;
990996
}
991997

998+
/*
999+
* Call from rk_headset_irq_hook_adc.c
1000+
*
1001+
* Enable micbias for HOOK detection and disable external Amplifier
1002+
* when jack insertion.
1003+
*/
1004+
int es8316_headset_detect(int jack_insert)
1005+
{
1006+
struct es8316_priv *es8316 = snd_soc_codec_get_drvdata(es8316_codec);
1007+
1008+
es8316->hp_inserted = jack_insert;
1009+
1010+
/*enable micbias and disable PA*/
1011+
if (jack_insert) {
1012+
snd_soc_update_bits(es8316_codec,
1013+
ES8316_SYS_PDN_REG0D, 0x3f, 0);
1014+
es8316_enable_spk(es8316, false);
1015+
}
1016+
1017+
return 0;
1018+
}
1019+
EXPORT_SYMBOL(es8316_headset_detect);
1020+
9921021
static void hp_work(struct work_struct *work)
9931022
{
9941023
struct es8316_priv *es8316;
@@ -1008,7 +1037,6 @@ static void hp_work(struct work_struct *work)
10081037
}
10091038
}
10101039

1011-
static struct snd_soc_codec *es8316_codec;
10121040
static int es8316_probe(struct snd_soc_codec *codec)
10131041
{
10141042
struct es8316_priv *es8316 = snd_soc_codec_get_drvdata(codec);
@@ -1042,7 +1070,9 @@ static int es8316_probe(struct snd_soc_codec *codec)
10421070
snd_soc_write(codec, ES8316_HPMIX_SWITCH_REG14, 0x00);
10431071
snd_soc_write(codec, ES8316_HPMIX_PDN_REG15, 0x33);
10441072
snd_soc_write(codec, ES8316_HPMIX_VOL_REG16, 0x00);
1045-
snd_soc_write(codec, ES8316_SYS_PDN_REG0D, 0x3F);
1073+
if (!es8316->hp_inserted)
1074+
snd_soc_write(codec, ES8316_SYS_PDN_REG0D,
1075+
0x3F);
10461076
snd_soc_write(codec, ES8316_SYS_LP1_REG0E, 0xFF);
10471077
snd_soc_write(codec, ES8316_SYS_LP2_REG0F, 0xFF);
10481078
snd_soc_write(codec, ES8316_CLKMGR_CLKSW_REG01, 0xF3);

0 commit comments

Comments
 (0)