Skip to content

Commit

Permalink
ASoC: sun4i-i2s: Don't use the oversample to calculate BCLK
Browse files Browse the repository at this point in the history
The BCLK divider should be calculated using the parameters that actually
make the BCLK rate: the number of channels, the sampling rate and the
sample width.

We've been using the oversample_rate previously because in the former SoCs,
the BCLK's parent is MCLK, which in turn is being used to generate the
oversample rate, so we end up with something like this:

oversample = mclk_rate / sampling_rate
bclk_div = oversample / word_size / channels

So, bclk_div = mclk_rate / sampling_rate / word_size / channels.

And this is actually better, since the oversampling ratio only plays a role
because the MCLK is its parent, not because of what BCLK is supposed to be.

Furthermore, that assumption of MCLK being the parent has been broken on
newer SoCs, so let's use the proper formula, and have the parent rate as an
argument.

Fixes: 7d29938 ("ASoC: sun4i-i2s: Add support for H3")
Fixes: 21faaea ("ASoC: sun4i-i2s: Add support for A83T")
Fixes: 66ecce3 ("ASoC: sun4i-i2s: Add compatibility with A64 codec I2S")
Signed-off-by: Maxime Ripard <maxime.ripard@bootlin.com>
Link: https://lore.kernel.org/r/c3595e3a9788c2ef2dcc30aa3c8c4953bb5cc249.1566242458.git-series.maxime.ripard@bootlin.com
Signed-off-by: Mark Brown <broonie@kernel.org>
  • Loading branch information
mripard authored and broonie committed Aug 20, 2019
1 parent a49d24e commit 7df8f9a
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions sound/soc/sunxi/sun4i-i2s.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,11 @@ static const struct sun4i_i2s_clk_div sun4i_i2s_mclk_div[] = {
};

static int sun4i_i2s_get_bclk_div(struct sun4i_i2s *i2s,
unsigned int oversample_rate,
unsigned long parent_rate,
unsigned int sampling_rate,
unsigned int word_size)
{
int div = oversample_rate / word_size / 2;
int div = parent_rate / sampling_rate / word_size / 2;
int i;

for (i = 0; i < ARRAY_SIZE(sun4i_i2s_bclk_div); i++) {
Expand Down Expand Up @@ -315,8 +316,8 @@ static int sun4i_i2s_set_clk_rate(struct snd_soc_dai *dai,
return -EINVAL;
}

bclk_div = sun4i_i2s_get_bclk_div(i2s, oversample_rate,
word_size);
bclk_div = sun4i_i2s_get_bclk_div(i2s, i2s->mclk_freq,
rate, word_size);
if (bclk_div < 0) {
dev_err(dai->dev, "Unsupported BCLK divider: %d\n", bclk_div);
return -EINVAL;
Expand Down

0 comments on commit 7df8f9a

Please sign in to comment.