Skip to content

Commit 2c1b0dd

Browse files
acgzxrkhuangtao
authored andcommitted
ASoC: rockchip: rk817-codec: Fix the 8/16kHz noise dues to incorret configurations
The APLL_CFG3/DDAC_SR_LMT0/DTOP_DIGEN_CLKE should be correct with different sample rates and clock. Change-Id: I766879750e640ef8ab31c2ab6776fe96ac65e063 Signed-off-by: Xing Zheng <zhengxing@rock-chips.com>
1 parent ca4eb25 commit 2c1b0dd

2 files changed

Lines changed: 58 additions & 7 deletions

File tree

sound/soc/codecs/rk817_codec.c

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -267,13 +267,10 @@ static int rk817_reset(struct snd_soc_codec *codec)
267267
static struct rk817_reg_val_typ playback_power_up_list[] = {
268268
{RK817_CODEC_AREF_RTCFG1, 0x40},
269269
{RK817_CODEC_DDAC_POPD_DACST, 0x02},
270-
{RK817_CODEC_DDAC_SR_LMT0, 0x02},
271-
/* {RK817_CODEC_DTOP_DIGEN_CLKE, 0x0f}, */
272270
/* APLL */
273271
{RK817_CODEC_APLL_CFG0, 0x04},
274272
{RK817_CODEC_APLL_CFG1, 0x58},
275273
{RK817_CODEC_APLL_CFG2, 0x2d},
276-
{RK817_CODEC_APLL_CFG3, 0x0c},
277274
{RK817_CODEC_APLL_CFG4, 0xa5},
278275
{RK817_CODEC_APLL_CFG5, 0x00},
279276

@@ -307,13 +304,11 @@ static struct rk817_reg_val_typ playback_power_down_list[] = {
307304

308305
static struct rk817_reg_val_typ capture_power_up_list[] = {
309306
{RK817_CODEC_AREF_RTCFG1, 0x40},
310-
{RK817_CODEC_DDAC_SR_LMT0, 0x02},
311307
{RK817_CODEC_DADC_SR_ACL0, 0x02},
312308
/* {RK817_CODEC_DTOP_DIGEN_CLKE, 0xff}, */
313309
{RK817_CODEC_APLL_CFG0, 0x04},
314310
{RK817_CODEC_APLL_CFG1, 0x58},
315311
{RK817_CODEC_APLL_CFG2, 0x2d},
316-
{RK817_CODEC_APLL_CFG3, 0x0c},
317312
{RK817_CODEC_APLL_CFG4, 0xa5},
318313
{RK817_CODEC_APLL_CFG5, 0x00},
319314

@@ -749,10 +744,56 @@ static int rk817_hw_params(struct snd_pcm_substream *substream,
749744
struct snd_soc_codec *codec = rtd->codec;
750745
struct rk817_codec_priv *rk817 = snd_soc_codec_get_drvdata(codec);
751746
unsigned int rate = params_rate(params);
747+
unsigned char apll_cfg3_val;
748+
unsigned char dtop_digen_sr_lmt0;
749+
unsigned char dtop_digen_clke;
752750

753751
DBG("%s : MCLK = %dHz, sample rate = %dHz\n",
754752
__func__, rk817->stereo_sysclk, rate);
755753

754+
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
755+
dtop_digen_clke = DAC_DIG_CLK_EN;
756+
else
757+
dtop_digen_clke = ADC_DIG_CLK_EN;
758+
759+
switch (rate) {
760+
case 8000:
761+
apll_cfg3_val = 0x03;
762+
dtop_digen_sr_lmt0 = 0x00;
763+
break;
764+
case 16000:
765+
apll_cfg3_val = 0x06;
766+
dtop_digen_sr_lmt0 = 0x01;
767+
break;
768+
case 96000:
769+
apll_cfg3_val = 0x18;
770+
dtop_digen_sr_lmt0 = 0x03;
771+
break;
772+
case 32000:
773+
case 44100:
774+
case 48000:
775+
apll_cfg3_val = 0x0c;
776+
dtop_digen_sr_lmt0 = 0x02;
777+
break;
778+
default:
779+
pr_err("Unsupported rate: %d\n", rate);
780+
return -EINVAL;
781+
}
782+
783+
/**
784+
* Note that: If you use the ALSA hooks plugin, entering hw_params()
785+
* is before playback/capture_path_put, therefore, we need to configure
786+
* APLL_CFG3/DTOP_DIGEN_CLKE/DDAC_SR_LMT0 for different sample rates.
787+
*/
788+
snd_soc_write(codec, RK817_CODEC_APLL_CFG3, apll_cfg3_val);
789+
/* The 0x00 contains ADC_DIG_CLK_DIS and DAC_DIG_CLK_DIS */
790+
snd_soc_update_bits(codec, RK817_CODEC_DTOP_DIGEN_CLKE,
791+
dtop_digen_clke, 0x00);
792+
snd_soc_update_bits(codec, RK817_CODEC_DDAC_SR_LMT0,
793+
DACSRT_MASK, dtop_digen_sr_lmt0);
794+
snd_soc_update_bits(codec, RK817_CODEC_DTOP_DIGEN_CLKE,
795+
dtop_digen_clke, dtop_digen_clke);
796+
756797
switch (params_format(params)) {
757798
case SNDRV_PCM_FORMAT_S16_LE:
758799
snd_soc_write(codec, RK817_CODEC_DI2S_RXCR2, VDW_RX_16BITS);
@@ -776,12 +817,19 @@ static int rk817_digital_mute(struct snd_soc_dai *dai, int mute)
776817
struct rk817_codec_priv *rk817 = snd_soc_codec_get_drvdata(codec);
777818

778819
DBG("%s %d\n", __func__, mute);
779-
if (mute)
820+
if (mute) {
780821
snd_soc_update_bits(codec, RK817_CODEC_DDAC_MUTE_MIXCTL,
781822
DACMT_ENABLE, DACMT_ENABLE);
782-
else
823+
/* Reset DAC DTOP_DIGEN_CLKE for playback stopped */
824+
snd_soc_update_bits(codec, RK817_CODEC_DTOP_DIGEN_CLKE,
825+
DAC_DIG_CLK_EN, DAC_DIG_CLK_DIS);
826+
snd_soc_update_bits(codec, RK817_CODEC_DTOP_DIGEN_CLKE,
827+
DAC_DIG_CLK_EN, DAC_DIG_CLK_EN);
828+
}
829+
else {
783830
snd_soc_update_bits(codec, RK817_CODEC_DDAC_MUTE_MIXCTL,
784831
DACMT_ENABLE, DACMT_DISABLE);
832+
}
785833

786834
if (mute) {
787835
rk817_codec_ctl_gpio(rk817, CODEC_SET_SPK, 0);

sound/soc/codecs/rk817_codec.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@
104104
#define RK817_I2S_MODE_MST (0x1 << 0)
105105
#define RK817_I2S_MODE_SLV (0x0 << 0)
106106

107+
/* RK817_CODEC_DDAC_SR_LMT0 */
108+
#define DACSRT_MASK (0x7 << 0)
109+
107110
/* RK817_CODEC_DDAC_MUTE_MIXCTL */
108111
#define DACMT_ENABLE (0x1 << 0)
109112
#define DACMT_DISABLE (0x0 << 0)

0 commit comments

Comments
 (0)