Skip to content

Commit ac4b320

Browse files
Romain Perierrkhuangtao
authored andcommitted
UPSTREAM: ASoC: es8328: Let device auto detect ratios in slave mode
In master mode, SCLK and LRCLK signals are generated by the CODEC when any of the ADC/DAC are enabled. SCLK is derived from MCLK via a programmable division set by BLK_DIV, LRCLK is derived from MCLK via another programmable division set by ADCFsRatio/DACFsRatio. In slave mode, SCLK and LRCLK signals are received as inputs and supplied externally. LRCLK and SCLK must be synchronously derived from MCLK with specific rates. The device can auto detect MCLK/LRCLK ratio according to a predefined table. LRCLK/SCLK ratio is usually 64 (SCLK = 64 * LRCLK) This commits adds support to let to device auto detect and decide which ratio to use. The mclkdiv2 and BCLK_DIV ratio and put to zero. Signed-off-by: Romain Perier <romain.perier@collabora.com> Signed-off-by: Mark Brown <broonie@kernel.org> (cherry picked from commit ae884ae) Change-Id: I195d5c3fc9f8b3032c5f0a1c767da696de22fb9b Signed-off-by: Chris Zhong <zyw@rock-chips.com>
1 parent 912f574 commit ac4b320

1 file changed

Lines changed: 25 additions & 14 deletions

File tree

sound/soc/codecs/es8328.c

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ struct es8328_priv {
9191
int mclkdiv2;
9292
const struct snd_pcm_hw_constraint_list *sysclk_constraints;
9393
const int *mclk_ratios;
94+
bool master;
9495
struct regulator_bulk_data supplies[ES8328_SUPPLY_NUM];
9596
};
9697

@@ -469,7 +470,7 @@ static int es8328_startup(struct snd_pcm_substream *substream,
469470
struct snd_soc_codec *codec = dai->codec;
470471
struct es8328_priv *es8328 = snd_soc_codec_get_drvdata(codec);
471472

472-
if (es8328->sysclk_constraints)
473+
if (es8328->master && es8328->sysclk_constraints)
473474
snd_pcm_hw_constraint_list(substream->runtime, 0,
474475
SNDRV_PCM_HW_PARAM_RATE,
475476
es8328->sysclk_constraints);
@@ -488,27 +489,34 @@ static int es8328_hw_params(struct snd_pcm_substream *substream,
488489
int wl;
489490
int ratio;
490491

491-
if (!es8328->sysclk_constraints) {
492-
dev_err(codec->dev, "No MCLK configured\n");
493-
return -EINVAL;
494-
}
495-
496492
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
497493
reg = ES8328_DACCONTROL2;
498494
else
499495
reg = ES8328_ADCCONTROL5;
500496

501-
for (i = 0; i < es8328->sysclk_constraints->count; i++)
502-
if (es8328->sysclk_constraints->list[i] == params_rate(params))
503-
break;
497+
if (es8328->master) {
498+
if (!es8328->sysclk_constraints) {
499+
dev_err(codec->dev, "No MCLK configured\n");
500+
return -EINVAL;
501+
}
504502

505-
if (i == es8328->sysclk_constraints->count) {
506-
dev_err(codec->dev, "LRCLK %d unsupported with current clock\n",
507-
params_rate(params));
508-
return -EINVAL;
503+
for (i = 0; i < es8328->sysclk_constraints->count; i++)
504+
if (es8328->sysclk_constraints->list[i] ==
505+
params_rate(params))
506+
break;
507+
508+
if (i == es8328->sysclk_constraints->count) {
509+
dev_err(codec->dev,
510+
"LRCLK %d unsupported with current clock\n",
511+
params_rate(params));
512+
return -EINVAL;
513+
}
514+
ratio = es8328->mclk_ratios[i];
515+
} else {
516+
ratio = 0;
517+
es8328->mclkdiv2 = 0;
509518
}
510519

511-
ratio = es8328->mclk_ratios[i];
512520
snd_soc_update_bits(codec, ES8328_MASTERMODE,
513521
ES8328_MASTERMODE_MCLKDIV2,
514522
es8328->mclkdiv2 ? ES8328_MASTERMODE_MCLKDIV2 : 0);
@@ -586,6 +594,7 @@ static int es8328_set_dai_fmt(struct snd_soc_dai *codec_dai,
586594
unsigned int fmt)
587595
{
588596
struct snd_soc_codec *codec = codec_dai->codec;
597+
struct es8328_priv *es8328 = snd_soc_codec_get_drvdata(codec);
589598
u8 dac_mode = 0;
590599
u8 adc_mode = 0;
591600

@@ -595,11 +604,13 @@ static int es8328_set_dai_fmt(struct snd_soc_dai *codec_dai,
595604
snd_soc_update_bits(codec, ES8328_MASTERMODE,
596605
ES8328_MASTERMODE_MSC,
597606
ES8328_MASTERMODE_MSC);
607+
es8328->master = true;
598608
break;
599609
case SND_SOC_DAIFMT_CBS_CFS:
600610
/* Slave serial port mode */
601611
snd_soc_update_bits(codec, ES8328_MASTERMODE,
602612
ES8328_MASTERMODE_MSC, 0);
613+
es8328->master = false;
603614
break;
604615
default:
605616
return -EINVAL;

0 commit comments

Comments
 (0)