RK3399|[RK3399][Android7.1] 调试笔记 --- 解决开关按键时产生的Pop声

Platform: RK3399
OS: Android 7.1
Kernel: v4.4.83
背景: 按键音在打开和关闭的时候,会有pop声。
原因: 【RK3399|[RK3399][Android7.1] 调试笔记 --- 解决开关按键时产生的Pop声】audio codec后面有个功放,功放一直打开着,当codec打开和关闭的时候,会有噪声带进到功放中。
解决方法: 注:GPIO4_D4是用来控制功放的开关。

diff --git a/arch/arm64/boot/dts/rockchip/rk3399-ecovacs.dts b/arch/arm64/boot/dts/rockchip/rk3399-ecovacs.dts index 80b31d9..486254b 100644 --- a/arch/arm64/boot/dts/rockchip/rk3399-ecovacs.dts +++ b/arch/arm64/boot/dts/rockchip/rk3399-ecovacs.dts @@ -651,8 +651,9 @@ realtek,in1-differential; pinctrl-names = "default"; pinctrl-0 = <&rt5640_hpcon &i2s_8ch_mclk>; -hp-con-gpio = <&gpio4 21 GPIO_ACTIVE_HIGH>; -//hp-det-gpio = <&gpio4 28 GPIO_ACTIVE_LOW>; +//Kris, 181101, Fix pop sound issue. +//GPIO4_D4 +spk-ctl-gpio = <&gpio4 28 GPIO_ACTIVE_LOW>; io-channels = <&saradc 4>; hp-det-adc-value = https://www.it610.com/article/<500>; status = "okay"; diff --git a/include/sound/rt5640.h b/include/sound/rt5640.h index e3c84b9..747aed1 100644 --- a/include/sound/rt5640.h +++ b/include/sound/rt5640.h @@ -22,6 +22,9 @@ struct rt5640_platform_data { bool dmic2_data_pin; /* 0 = IN1N; 1 = GPIO4 */ int ldo1_en; /* GPIO for LDO1_EN */ + +//Kris, 181101, Fix pop sound issue. +int spk_ctl_gpio; }; #endif diff --git a/sound/soc/codecs/rt5640.c b/sound/soc/codecs/rt5640.c index 5f37d75..ee9d1ba 100644 --- a/sound/soc/codecs/rt5640.c +++ b/sound/soc/codecs/rt5640.c @@ -1800,6 +1800,22 @@ static int rt5640_hw_params(struct snd_pcm_substream *substream, return 0; } + +/*Kris, 181101, Fix pop sound issue.{*/ +static int rt5640_digital_mute(struct snd_soc_dai *dai, int mute) +{ +struct snd_soc_codec *codec = dai->codec; +struct rt5640_priv *rt5640 = snd_soc_codec_get_drvdata(codec); + +if(mute){ +gpio_direction_output(rt5640->pdata.spk_ctl_gpio, 0); +} else { +gpio_direction_output(rt5640->pdata.spk_ctl_gpio, 1); +} +return 0; +} +/*Kris, 181101, Fix pop sound issue.}*/ + static int rt5640_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt) { struct snd_soc_codec *codec = dai->codec; @@ -2158,6 +2174,8 @@ static int rt5640_resume(struct snd_soc_codec *codec) static const struct snd_soc_dai_ops rt5640_aif_dai_ops = { .hw_params = rt5640_hw_params, +//Kris, 181101, Fix pop sound issue. + .digital_mute = rt5640_digital_mute, .set_fmt = rt5640_set_dai_fmt, .set_sysclk = rt5640_set_dai_sysclk, .set_pll = rt5640_set_dai_pll, @@ -2272,6 +2290,12 @@ static int rt5640_parse_dt(struct rt5640_priv *rt5640, struct device_node *np) rt5640->pdata.ldo1_en = of_get_named_gpio(np, "realtek,ldo1-en-gpios", 0); + + /*Kris, 181101, Fix pop sound issue.{*/ + rt5640->pdata.spk_ctl_gpio = of_get_named_gpio(np, +"spk-ctl-gpio", 0); + /*Kris, 181101, Fix pop sound issue.}*/ + /* * LDO1_EN is optional (it may be statically tied on the board). * -ENOENT means that the property doesn't exist, i.e. there is no @@ -2337,6 +2361,19 @@ static int rt5640_i2c_probe(struct i2c_client *i2c, msleep(400); } + /*Kris, 181101, Fix pop sound issue.{*/ + if (gpio_is_valid(rt5640->pdata.spk_ctl_gpio)) { +ret = devm_gpio_request_one(&i2c->dev, rt5640->pdata.spk_ctl_gpio, +GPIOF_OUT_INIT_LOW, +"rt5640_spk_ctl"); +if (ret < 0) { +dev_err(&i2c->dev, "Failed to request rt5640 spk_ctl_gpio %d: %d\n", +rt5640->pdata.spk_ctl_gpio, ret); +return ret; +} + } + /*Kris, 181101, Fix pop sound issue.}*/ + ret = regmap_read(rt5640->regmap, RT5640_VENDOR_ID2, &val); if (ret) return -EPROBE_DEFER;

    推荐阅读