From 508dbdca12b3f959e674e0d41f28d850d78d1903 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E9=99=88=E9=87=91=E6=B3=89?= Date: Thu, 27 Mar 2014 16:17:54 +0800 Subject: [PATCH] Audio: add lock for machine driver, add micbias setting for rk616 codec --- sound/soc/codecs/rk616_codec.c | 49 ++++++++++++++++++++++++++-------- sound/soc/rockchip/rk_rk3026.c | 4 +++ sound/soc/rockchip/rk_rk3190.c | 4 +++ sound/soc/rockchip/rk_rk616.c | 4 +++ sound/soc/rockchip/rk_rt3261.c | 4 +++ sound/soc/rockchip/rk_rt5640.c | 4 +++ 6 files changed, 58 insertions(+), 11 deletions(-) diff --git a/sound/soc/codecs/rk616_codec.c b/sound/soc/codecs/rk616_codec.c index 97253c7e6231..bde655b2fad1 100755 --- a/sound/soc/codecs/rk616_codec.c +++ b/sound/soc/codecs/rk616_codec.c @@ -1398,6 +1398,12 @@ static int rk616_capture_path_put(struct snd_kcontrol *kcontrol, case MIC_OFF: if (pre_path != MIC_OFF) rk616_codec_power_down(RK616_CODEC_CAPTURE); + + if (rk616->hpmic_from_mic2in) + snd_soc_update_bits(codec, RK616_MICBIAS_CTL, + RK616_MICBIAS1_PWRD | RK616_MICBIAS1_V_MASK, + RK616_MICBIAS1_PWRD); + break; case Main_Mic: if (pre_path == MIC_OFF) @@ -1409,6 +1415,9 @@ static int rk616_capture_path_put(struct snd_kcontrol *kcontrol, if (rk616->hpmic_from_mic2in) { snd_soc_write(codec, 0x848, 0x06); //MIXINL power up and unmute, MININL from MICMUX, MICMUX from BST_L snd_soc_write(codec, 0x840, 0x69); //BST_L power up, unmute, and Single-Ended(bit 6), volume 0-20dB(bit 5) + snd_soc_update_bits(codec, RK616_MICBIAS_CTL, + RK616_MICBIAS1_PWRD | RK616_MICBIAS1_V_MASK, + RK616_MICBIAS1_V_1_7); } rk616_set_gpio(RK616_CODEC_SET_MIC, GPIO_HIGH); break; @@ -1422,6 +1431,9 @@ static int rk616_capture_path_put(struct snd_kcontrol *kcontrol, if (rk616->hpmic_from_mic2in) { snd_soc_write(codec, 0x848, 0x26); //MIXINL power up and unmute, MININL from MICMUX, MICMUX from BST_R snd_soc_write(codec, 0x840, 0x96); //BST_R power up, unmute, and Single-Ended(bit 2), volume 0-20dB(bit 1) + snd_soc_update_bits(codec, RK616_MICBIAS_CTL, + RK616_MICBIAS1_PWRD | RK616_MICBIAS1_V_MASK, + RK616_MICBIAS1_PWRD); } rk616_set_gpio(RK616_CODEC_SET_MIC, GPIO_LOW); break; @@ -1628,10 +1640,6 @@ static int rk616_voip_path_put(struct snd_kcontrol *kcontrol, switch (rk616->voip_path) { case OFF: - if (rk616->playback_path == OFF) - rk616_codec_power_down(RK616_CODEC_PLAYBACK); - if (rk616->capture_path == OFF) - rk616_codec_power_down(RK616_CODEC_CAPTURE); break; case RCV: case SPK_PATH: @@ -2628,9 +2636,20 @@ static int rk616_suspend(struct snd_soc_codec *codec) static int rk616_resume(struct snd_soc_codec *codec) { + struct rk616_codec_priv *rk616 = rk616_priv; + + if (!rk616) { + printk("%s : rk616 priv is NULL!\n", __func__); + return -EINVAL; + } + if (rk616_for_mid) { - snd_soc_write(codec, RK616_MICBIAS_CTL, - RK616_MICBIAS2_PWRD | RK616_MICBIAS1_V_1_7); + if (rk616->hpmic_from_mic2in) + snd_soc_write(codec, RK616_MICBIAS_CTL, + RK616_MICBIAS1_PWRD | RK616_MICBIAS2_V_1_7); + else + snd_soc_write(codec, RK616_MICBIAS_CTL, + RK616_MICBIAS2_PWRD | RK616_MICBIAS1_V_1_7); } else { rk616_set_bias_level(codec, SND_SOC_BIAS_STANDBY); } @@ -2719,8 +2738,12 @@ static int rk616_probe(struct snd_soc_codec *codec) if (rk616_for_mid) { snd_soc_add_codec_controls(codec, rk616_snd_path_controls, ARRAY_SIZE(rk616_snd_path_controls)); - snd_soc_write(codec, RK616_MICBIAS_CTL, - RK616_MICBIAS2_PWRD | RK616_MICBIAS1_V_1_7); + if (rk616->hpmic_from_mic2in) + snd_soc_write(codec, RK616_MICBIAS_CTL, + RK616_MICBIAS1_PWRD | RK616_MICBIAS2_V_1_7); + else + snd_soc_write(codec, RK616_MICBIAS_CTL, + RK616_MICBIAS2_PWRD | RK616_MICBIAS1_V_1_7); } else { codec->dapm.bias_level = SND_SOC_BIAS_OFF; rk616_set_bias_level(codec, SND_SOC_BIAS_STANDBY); @@ -2969,9 +2992,11 @@ static int rk616_platform_remove(struct platform_device *pdev) { snd_soc_unregister_codec(&pdev->dev); - if (rk616_priv) + if (rk616_priv) { kfree(rk616_priv); - rk616_priv = NULL; + rk616_priv = NULL; + } + rk616_mfd = NULL; return 0; @@ -2999,8 +3024,10 @@ void rk616_platform_shutdown(struct platform_device *pdev) mdelay(10); snd_soc_write(codec, RK616_RESET, 0x3); - if (rk616) + if (rk616) { kfree(rk616); + rk616_priv = NULL; + } } static struct platform_driver rk616_codec_driver = { diff --git a/sound/soc/rockchip/rk_rk3026.c b/sound/soc/rockchip/rk_rk3026.c index 7b0654c99457..47065b879156 100644 --- a/sound/soc/rockchip/rk_rk3026.c +++ b/sound/soc/rockchip/rk_rk3026.c @@ -78,11 +78,15 @@ static int rk3026_init(struct snd_soc_pcm_runtime *rtd) /* Set up specific audio path audio_mapnects */ snd_soc_dapm_add_routes(dapm, rk_audio_map, ARRAY_SIZE(rk_audio_map)); + mutex_lock(&dapm->card->dapm_mutex); + snd_soc_dapm_enable_pin(dapm, "Mic Jack"); snd_soc_dapm_enable_pin(dapm, "Headset Jack"); snd_soc_dapm_enable_pin(dapm, "Ext Spk"); snd_soc_dapm_enable_pin(dapm, "Headphone Jack"); + mutex_unlock(&dapm->card->dapm_mutex); + snd_soc_dapm_sync(dapm); return 0; diff --git a/sound/soc/rockchip/rk_rk3190.c b/sound/soc/rockchip/rk_rk3190.c index 2945a27ed80b..a83b4cb27f75 100755 --- a/sound/soc/rockchip/rk_rk3190.c +++ b/sound/soc/rockchip/rk_rk3190.c @@ -77,11 +77,15 @@ static int rk3190_init(struct snd_soc_pcm_runtime *rtd) /* Set up specific audio path audio_mapnects */ snd_soc_dapm_add_routes(dapm, rk_audio_map, ARRAY_SIZE(rk_audio_map)); + mutex_lock(&dapm->card->dapm_mutex); + snd_soc_dapm_enable_pin(dapm, "Mic Jack"); snd_soc_dapm_enable_pin(dapm, "Headset Jack"); snd_soc_dapm_enable_pin(dapm, "Ext Spk"); snd_soc_dapm_enable_pin(dapm, "Headphone Jack"); + mutex_unlock(&dapm->card->dapm_mutex); + snd_soc_dapm_sync(dapm); #endif return 0; diff --git a/sound/soc/rockchip/rk_rk616.c b/sound/soc/rockchip/rk_rk616.c index b852d7f15335..ef6b58af07d5 100755 --- a/sound/soc/rockchip/rk_rk616.c +++ b/sound/soc/rockchip/rk_rk616.c @@ -108,11 +108,15 @@ static int rk616_init(struct snd_soc_pcm_runtime *rtd) /* Set up specific audio path audio_mapnects */ snd_soc_dapm_add_routes(dapm, rk_audio_map, ARRAY_SIZE(rk_audio_map)); + mutex_lock(&dapm->card->dapm_mutex); + snd_soc_dapm_enable_pin(dapm, "Mic Jack"); snd_soc_dapm_enable_pin(dapm, "Headset Jack"); snd_soc_dapm_enable_pin(dapm, "Ext Spk"); snd_soc_dapm_enable_pin(dapm, "Headphone Jack"); + mutex_unlock(&dapm->card->dapm_mutex); + snd_soc_dapm_sync(dapm); return 0; diff --git a/sound/soc/rockchip/rk_rt3261.c b/sound/soc/rockchip/rk_rt3261.c index 2fc52b17fb0f..91959d96601b 100644 --- a/sound/soc/rockchip/rk_rt3261.c +++ b/sound/soc/rockchip/rk_rt3261.c @@ -206,11 +206,15 @@ static int rockchip_rt3261_init(struct snd_soc_pcm_runtime *rtd) /* Set up specific audio path audio_mapnects */ snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map)); + mutex_lock(&dapm->card->dapm_mutex); + snd_soc_dapm_enable_pin(dapm, "Mic Jack"); snd_soc_dapm_enable_pin(dapm, "Headset Jack"); snd_soc_dapm_enable_pin(dapm, "Ext Spk"); snd_soc_dapm_enable_pin(dapm, "Headphone Jack"); + mutex_unlock(&dapm->card->dapm_mutex); + snd_soc_dapm_sync(dapm); return 0; diff --git a/sound/soc/rockchip/rk_rt5640.c b/sound/soc/rockchip/rk_rt5640.c index dd0a620b48ad..f7a1d3dcb0c2 100755 --- a/sound/soc/rockchip/rk_rt5640.c +++ b/sound/soc/rockchip/rk_rt5640.c @@ -206,11 +206,15 @@ static int rk29_rt5640_init(struct snd_soc_pcm_runtime *rtd) /* Set up specific audio path audio_mapnects */ snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map)); + mutex_lock(&dapm->card->dapm_mutex); + snd_soc_dapm_enable_pin(dapm, "Mic Jack"); snd_soc_dapm_enable_pin(dapm, "Headset Jack"); snd_soc_dapm_enable_pin(dapm, "Ext Spk"); snd_soc_dapm_enable_pin(dapm, "Headphone Jack"); + mutex_unlock(&dapm->card->dapm_mutex); + snd_soc_dapm_sync(dapm); return 0; -- 2.34.1