Skip to content

Commit cff3921

Browse files
committed
Fix: ac101 noise import by PLL frequncy deviation
1 parent 0d30a15 commit cff3921

File tree

2 files changed

+42
-26
lines changed

2 files changed

+42
-26
lines changed

ac101.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -442,8 +442,9 @@ struct kv_map {
442442
};
443443

444444
/*
445-
* Note : pll code from original tdm/i2s driver.
446-
* freq_out = freq_in * N/(m*(2k+1)) , k=1,N=N_i+N_f,N_f=factor*0.2;
445+
* Note : pll code from original tdm/i2s driver.
446+
* freq_out = freq_in * N/(M*(2k+1)) , k=1,N=N_i+N_f,N_f=factor*0.2;
447+
* N_i[0,1023], N_f_factor[0,7], m[1,64]=REG_VAL[1-63,0]
447448
*/
448449
static const struct pll_div codec_pll_div[] = {
449450
{128000, 22579200, 1, 529, 1},
@@ -463,7 +464,7 @@ static const struct pll_div codec_pll_div[] = {
463464
{6000000, 24576000, 25, 307, 1},
464465
{13000000, 24576000, 42, 238, 1},
465466
{19200000, 24576000, 25, 96, 0},
466-
{24000000, 24576000, 39, 119, 4},/*((119 + 4 * 0.2) * 24000000) / (39 * (2 * 1 + 1)) */
467+
{24000000, 24576000, 25, 76, 4},/* accurate */
467468
{11289600, 22579200, 1, 6, 0},
468469
{12288000, 24576000, 1, 6, 0},
469470
};
@@ -536,8 +537,10 @@ int ac101_aif_mute(struct snd_soc_dai *codec_dai, int mute)
536537
ac101_headphone_event(codec, SND_SOC_DAPM_PRE_PMD);
537538
late_enable_dac(codec, SND_SOC_DAPM_POST_PMD);
538539

540+
#if _MASTER_MULTI_CODEC != _MASTER_AC101
539541
ac10x->aif1_clken = 1;
540542
ac101_aif1clk(codec, SND_SOC_DAPM_POST_PMD);
543+
#endif
541544
}
542545
return 0;
543546
}
@@ -604,6 +607,7 @@ static int ac101_set_pll(struct snd_soc_dai *codec_dai, int pll_id, int source,
604607
}
605608
}
606609
/*config pll m*/
610+
if (m == 64) m = 0;
607611
ac101_update_bits(codec, PLL_CTRL1, (0x3f<<PLL_POSTDIV_M), (m<<PLL_POSTDIV_M));
608612
/*config pll n*/
609613
ac101_update_bits(codec, PLL_CTRL2, (0x3ff<<PLL_PREDIV_NI), (n_i<<PLL_PREDIV_NI));
@@ -702,6 +706,8 @@ int ac101_hw_params(struct snd_pcm_substream *substream,
702706
}
703707
}
704708
ac101_update_bits(codec, AIF_CLK_CTRL, (0xf<<AIF1_BCLK_DIV), i<<AIF1_BCLK_DIV);
709+
} else {
710+
ac101_set_pll(codec_dai, AC101_MCLK1, 0, ac10x->sysclk, freq_out);
705711
}
706712

707713
AC101_DBG("rate: %d , channels: %d , samp_res: %d",
@@ -766,6 +772,10 @@ int ac101_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
766772
case SND_SOC_DAIFMT_DSP_A: /* L reg_val msb after FRM LRC */
767773
reg_val |= (0x3<<AIF1_DATA_FMT);
768774
break;
775+
case SND_SOC_DAIFMT_DSP_B:
776+
/* TODO: data offset set to 0 */
777+
reg_val |= (0x3<<AIF1_DATA_FMT);
778+
break;
769779
default:
770780
pr_err("%s, line:%d\n", __func__, __LINE__);
771781
return -EINVAL;
@@ -814,6 +824,9 @@ static int ac101_set_clock(int y_start_n_stop) {
814824
if (y_start_n_stop) {
815825
/* enable global clock */
816826
ac101_aif1clk(static_ac10x->codec, SND_SOC_DAPM_PRE_PMU);
827+
} else {
828+
static_ac10x->aif1_clken = 1;
829+
ac101_aif1clk(static_ac10x->codec, SND_SOC_DAPM_POST_PMD);
817830
}
818831
return 0;
819832
}

ac108.c

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ static const struct pll_div ac108_pll_div_list[] = {
104104
{ 16000000, 24576000, 12, 0, 400, 9, 1 },
105105
{ 19200000, 24576000, 15, 0, 410, 9, 1 },
106106
{ 19680000, 24576000, 15, 0, 400, 9, 1 },
107-
{ 24000000, 24576000, 9, 0, 205, 9, 1 },
107+
{ 24000000, 24576000, 4, 0, 128,24, 0 }, //accurate
108108

109109
{ 400000, 22579200, 0, 0, 566, 4, 1 },
110110
{ 512000, 22579200, 0, 0, 880, 9, 1 },
@@ -122,7 +122,7 @@ static const struct pll_div ac108_pll_div_list[] = {
122122
{ 16000000, 22579200, 11, 0, 340, 9, 1 },
123123
{ 19200000, 22579200, 13, 0, 330, 9, 1 },
124124
{ 19680000, 22579200, 14, 0, 345, 9, 1 },
125-
{ 24000000, 22579200, 16, 0, 320, 9, 1 },
125+
{ 24000000, 22579200, 24, 0, 588,24, 0 }, // accurate
126126

127127
{ 12288000, 24576000, 9, 0, 400, 9, 1 }, //24576000/2
128128
{ 11289600, 22579200, 9, 0, 400, 9, 1 }, //22579200/2
@@ -216,12 +216,11 @@ static int snd_ac108_get_volsw(struct snd_kcontrol *kcontrol,
216216
if ((ret = ac10x_read(mc->reg, &val, ac10x->i2cmap[chip])) < 0)
217217
return ret;
218218

219-
val = (val >> mc->shift) & mask;
220-
ucontrol->value.integer.value[0] = val - mc->min;
219+
val = ((val >> mc->shift) & mask) - mc->min;
221220
if (invert) {
222-
ucontrol->value.integer.value[0] =
223-
mc->max - ucontrol->value.integer.value[0];
221+
val = mc->max - val;
224222
}
223+
ucontrol->value.integer.value[0] = val;
225224
return 0;
226225
}
227226

@@ -532,7 +531,7 @@ static int ac108_configure_clocking(struct ac10x_priv *ac10x, unsigned int rate)
532531
ac108_multi_chips_update_bits(PLL_CTRL4, 0xff << PLL_LOOPDIV_LSB, (unsigned char)ac108_pll_div.n << PLL_LOOPDIV_LSB, ac10x);
533532
ac108_multi_chips_update_bits(PLL_CTRL3, 0x03 << PLL_LOOPDIV_MSB, (ac108_pll_div.n >> 8) << PLL_LOOPDIV_MSB, ac10x);
534533
ac108_multi_chips_update_bits(PLL_CTRL2, 0x1f << PLL_PREDIV1 | 0x01 << PLL_PREDIV2,
535-
ac108_pll_div.m1 << PLL_PREDIV1 | ac108_pll_div.m2 << PLL_PREDIV2, ac10x);
534+
ac108_pll_div.m1 << PLL_PREDIV1 | ac108_pll_div.m2 << PLL_PREDIV2, ac10x);
536535

537536
/*0x18: PLL clk lock enable*/
538537
ac108_multi_chips_update_bits(PLL_LOCK_CTRL, 0x1 << PLL_LOCK_EN, 0x1 << PLL_LOCK_EN, ac10x);
@@ -545,7 +544,7 @@ static int ac108_configure_clocking(struct ac10x_priv *ac10x, unsigned int rate)
545544
* pll,enable sysclk
546545
*/
547546
ac108_multi_chips_update_bits(SYSCLK_CTRL, 0x01 << PLLCLK_EN | 0x03 << PLLCLK_SRC | 0x01 << SYSCLK_SRC | 0x01 << SYSCLK_EN,
548-
0x01 << PLLCLK_EN | 0x00 << PLLCLK_SRC | 0x01 << SYSCLK_SRC | 0x01 << SYSCLK_EN, ac10x);
547+
0x01 << PLLCLK_EN | 0x00 << PLLCLK_SRC | 0x01 << SYSCLK_SRC | 0x01 << SYSCLK_EN, ac10x);
549548
ac10x->mclk = ac108_pll_div.freq_out;
550549
}
551550
if (ac10x->clk_id == SYSCLK_SRC_MCLK) {
@@ -725,9 +724,12 @@ static int ac108_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_h
725724
}
726725

727726
} else {
727+
unsigned div;
728+
728729
/*TDM mode or normal mode*/
729-
ac108_multi_chips_write(I2S_LRCK_CTRL2, ac108_samp_res[samp_res].real_val * channels - 1, ac10x);
730-
ac108_multi_chips_update_bits(I2S_LRCK_CTRL1, 0x03 << 0, 0x00, ac10x);
730+
div = ac108_samp_res[samp_res].real_val * channels - 1;
731+
ac108_multi_chips_write(I2S_LRCK_CTRL2, (div & 0xFF), ac10x);
732+
ac108_multi_chips_update_bits(I2S_LRCK_CTRL1, 0x03 << 0, (div >> 8) << 0, ac10x);
731733
}
732734

733735
/**
@@ -819,7 +821,7 @@ static int ac108_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) {
819821
* 0x30:chip is master mode ,BCLK & LRCK output
820822
*/
821823
ac108_multi_chips_update_bits(I2S_CTRL, 0x03 << LRCK_IOEN | 0x03 << SDO1_EN | 0x1 << TXEN | 0x1 << GEN,
822-
0x00 << LRCK_IOEN | 0x03 << SDO1_EN | 0x1 << TXEN | 0x1 << GEN, ac10x);
824+
0x00 << LRCK_IOEN | 0x03 << SDO1_EN | 0x1 << TXEN | 0x1 << GEN, ac10x);
823825
/* multi_chips: only one chip set as Master, and the others also need to set as Slave */
824826
ac10x_update_bits(I2S_CTRL, 0x3 << LRCK_IOEN, 0x2 << LRCK_IOEN, ac10x->i2cmap[_MASTER_INDEX]);
825827
break;
@@ -869,11 +871,10 @@ static int ac108_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) {
869871
tx_offset = 0;
870872
break;
871873
default:
872-
ac10x->i2s_mode = LEFT_JUSTIFIED_FORMAT;
873-
tx_offset = 1;
874-
return -EINVAL;
875874
pr_err("AC108 I2S format config error:%u\n\n", fmt & SND_SOC_DAIFMT_FORMAT_MASK);
875+
return -EINVAL;
876876
}
877+
877878
/*AC108 config BCLK&LRCK polarity*/
878879
switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
879880
case SND_SOC_DAIFMT_NB_NF:
@@ -912,7 +913,7 @@ static int ac108_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) {
912913

913914
/**
914915
*0x31: 0: normal mode, negative edge drive and positive edge sample
915-
1: invert mode, positive edge drive and negative edge sample
916+
1: invert mode, positive edge drive and negative edge sample
916917
*/
917918
ac108_multi_chips_update_bits(I2S_BCLK_CTRL, 0x01 << BCLK_POLARITY, brck_polarity << BCLK_POLARITY, ac10x);
918919
/**
@@ -957,6 +958,7 @@ static int ac108_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) {
957958
/*
958959
* due to miss channels order in cpu_dai, we meed defer the clock starting.
959960
*/
961+
#if _MASTER_MULTI_CODEC == _MASTER_AC108
960962
static int ac108_set_clock(int y_start_n_stop) {
961963
u8 r;
962964

@@ -983,6 +985,7 @@ static int ac108_set_clock(int y_start_n_stop) {
983985

984986
return 0;
985987
}
988+
#endif
986989

987990
static int ac108_trigger(struct snd_pcm_substream *substream, int cmd,
988991
struct snd_soc_dai *dai)
@@ -1001,18 +1004,18 @@ static int ac108_trigger(struct snd_pcm_substream *substream, int cmd,
10011004
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
10021005
/* disable global clock if lrck disabled */
10031006
ac10x_read(I2S_CTRL, &r, ac10x->i2cmap[_MASTER_INDEX]);
1004-
if ((r & (0x01 << LRCK_IOEN)) == 0) {
1007+
if ((r & (0x02 << LRCK_IOEN)) && (r & (0x01 << LRCK_IOEN)) == 0) {
10051008
/* disable global clock */
10061009
ac108_multi_chips_update_bits(I2S_CTRL, 0x1 << TXEN | 0x1 << GEN, 0x1 << TXEN | 0x0 << GEN, ac10x);
1010+
}
10071011

1008-
/*0x21: Module clock enable<I2S, ADC digital, MIC offset Calibration, ADC analog>*/
1009-
ac108_multi_chips_write(MOD_CLK_EN, 1 << I2S | 1 << ADC_DIGITAL | 1 << MIC_OFFSET_CALIBRATION | 1 << ADC_ANALOG, ac10x);
1012+
/*0x21: Module clock enable<I2S, ADC digital, MIC offset Calibration, ADC analog>*/
1013+
ac108_multi_chips_write(MOD_CLK_EN, 1 << I2S | 1 << ADC_DIGITAL | 1 << MIC_OFFSET_CALIBRATION | 1 << ADC_ANALOG, ac10x);
10101014

1011-
/*0x22: Module reset de-asserted<I2S, ADC digital, MIC offset Calibration, ADC analog>*/
1012-
ac108_multi_chips_write(MOD_RST_CTRL, 1 << I2S | 1 << ADC_DIGITAL | 1 << MIC_OFFSET_CALIBRATION | 1 << ADC_ANALOG, ac10x);
1015+
/*0x22: Module reset de-asserted<I2S, ADC digital, MIC offset Calibration, ADC analog>*/
1016+
ac108_multi_chips_write(MOD_RST_CTRL, 1 << I2S | 1 << ADC_DIGITAL | 1 << MIC_OFFSET_CALIBRATION | 1 << ADC_ANALOG, ac10x);
10131017

1014-
/* delayed clock starting, move to simple_card_trigger() */
1015-
}
1018+
/* delayed clock starting, move to simple_card_trigger() */
10161019
break;
10171020
case SNDRV_PCM_TRIGGER_STOP:
10181021
case SNDRV_PCM_TRIGGER_SUSPEND:
@@ -1342,7 +1345,7 @@ static int ac108_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *i
13421345
if (of_property_read_u32(np, "tdm-chips-count", &val)) val = 1;
13431346
ac10x->tdm_chips_cnt = val;
13441347

1345-
pr_err(" i2c_id number : %d\n", index);
1348+
pr_err(" ac10x i2c_id number: %d\n", index);
13461349
pr_err(" ac10x data protocol: %d\n", ac10x->data_protocol);
13471350

13481351
ac10x->i2c[index] = i2c;

0 commit comments

Comments
 (0)