alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ASoC: wm8962: Relax bit clock divider searching
@ 2021-03-03 11:21 Shengjiu Wang
  2021-03-05 12:43 ` Daniel Baluta
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Shengjiu Wang @ 2021-03-03 11:21 UTC (permalink / raw)
  To: lgirdwood, broonie, perex, tiwai, shengjiu.wang, ckeepax,
	kuninori.morimoto.gx, peter.ujfalusi, gustavoars,
	pierre-louis.bossart, patches, alsa-devel, linux-kernel

With S20_3LE format case, the sysclk = rate * 384,
the bclk = rate * 20 * 2, there is no proper bclk divider
for 384 / 40, because current condition needs exact match.
So driver fails to configure the clocking:

wm8962 3-001a: Unsupported BCLK ratio 9

Fix this by relaxing bitclk divider searching, so that when
no exact value can be derived from sysclk pick the closest
value greater than expected bitclk.

Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com>
---
 sound/soc/codecs/wm8962.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/sound/soc/codecs/wm8962.c b/sound/soc/codecs/wm8962.c
index ce4666a74793..f5cd22450190 100644
--- a/sound/soc/codecs/wm8962.c
+++ b/sound/soc/codecs/wm8962.c
@@ -2403,6 +2403,7 @@ static const int sysclk_rates[] = {
 static void wm8962_configure_bclk(struct snd_soc_component *component)
 {
 	struct wm8962_priv *wm8962 = snd_soc_component_get_drvdata(component);
+	int best, min_diff, diff;
 	int dspclk, i;
 	int clocking2 = 0;
 	int clocking4 = 0;
@@ -2473,23 +2474,23 @@ static void wm8962_configure_bclk(struct snd_soc_component *component)
 
 	dev_dbg(component->dev, "DSPCLK is %dHz, BCLK %d\n", dspclk, wm8962->bclk);
 
-	/* We're expecting an exact match */
+	/* Search a proper bclk, not exact match. */
+	best = 0;
+	min_diff = INT_MAX;
 	for (i = 0; i < ARRAY_SIZE(bclk_divs); i++) {
 		if (bclk_divs[i] < 0)
 			continue;
 
-		if (dspclk / bclk_divs[i] == wm8962->bclk) {
-			dev_dbg(component->dev, "Selected BCLK_DIV %d for %dHz\n",
-				bclk_divs[i], wm8962->bclk);
-			clocking2 |= i;
+		diff = (dspclk / bclk_divs[i]) - wm8962->bclk;
+		if (diff < 0) /* Table is sorted */
 			break;
+		if (diff < min_diff) {
+			best = i;
+			min_diff = diff;
 		}
 	}
-	if (i == ARRAY_SIZE(bclk_divs)) {
-		dev_err(component->dev, "Unsupported BCLK ratio %d\n",
-			dspclk / wm8962->bclk);
-		return;
-	}
+	wm8962->bclk = dspclk / bclk_divs[best];
+	clocking2 |= best;
 
 	aif2 |= wm8962->bclk / wm8962->lrclk;
 	dev_dbg(component->dev, "Selected LRCLK divisor %d for %dHz\n",
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] ASoC: wm8962: Relax bit clock divider searching
  2021-03-03 11:21 [PATCH] ASoC: wm8962: Relax bit clock divider searching Shengjiu Wang
@ 2021-03-05 12:43 ` Daniel Baluta
  2021-03-07 17:29 ` Charles Keepax
  2021-03-16 17:59 ` Mark Brown
  2 siblings, 0 replies; 4+ messages in thread
From: Daniel Baluta @ 2021-03-05 12:43 UTC (permalink / raw)
  To: Shengjiu Wang
  Cc: Pierre-Louis Bossart, Linux-ALSA, gustavoars, ckeepax,
	Kuninori Morimoto, patches, Takashi Iwai, Liam Girdwood,
	Peter Ujfalusi, Mark Brown, Linux Kernel Mailing List

On Fri, Mar 5, 2021 at 1:15 AM Shengjiu Wang <shengjiu.wang@nxp.com> wrote:
>
> With S20_3LE format case, the sysclk = rate * 384,
> the bclk = rate * 20 * 2, there is no proper bclk divider
> for 384 / 40, because current condition needs exact match.
> So driver fails to configure the clocking:
>
> wm8962 3-001a: Unsupported BCLK ratio 9
>
> Fix this by relaxing bitclk divider searching, so that when
> no exact value can be derived from sysclk pick the closest
> value greater than expected bitclk.
>
> Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com>

Reviewed-by: Daniel Baluta <daniel.baluta@nxp.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] ASoC: wm8962: Relax bit clock divider searching
  2021-03-03 11:21 [PATCH] ASoC: wm8962: Relax bit clock divider searching Shengjiu Wang
  2021-03-05 12:43 ` Daniel Baluta
@ 2021-03-07 17:29 ` Charles Keepax
  2021-03-16 17:59 ` Mark Brown
  2 siblings, 0 replies; 4+ messages in thread
From: Charles Keepax @ 2021-03-07 17:29 UTC (permalink / raw)
  To: Shengjiu Wang
  Cc: pierre-louis.bossart, alsa-devel, gustavoars,
	kuninori.morimoto.gx, patches, tiwai, lgirdwood, peter.ujfalusi,
	broonie, linux-kernel

On Wed, Mar 03, 2021 at 07:21:28PM +0800, Shengjiu Wang wrote:
> With S20_3LE format case, the sysclk = rate * 384,
> the bclk = rate * 20 * 2, there is no proper bclk divider
> for 384 / 40, because current condition needs exact match.
> So driver fails to configure the clocking:
> 
> wm8962 3-001a: Unsupported BCLK ratio 9
> 
> Fix this by relaxing bitclk divider searching, so that when
> no exact value can be derived from sysclk pick the closest
> value greater than expected bitclk.
> 
> Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com>
> ---
>  sound/soc/codecs/wm8962.c | 21 +++++++++++----------
>  1 file changed, 11 insertions(+), 10 deletions(-)
> 
> diff --git a/sound/soc/codecs/wm8962.c b/sound/soc/codecs/wm8962.c
> index ce4666a74793..f5cd22450190 100644
> --- a/sound/soc/codecs/wm8962.c
> +++ b/sound/soc/codecs/wm8962.c
> @@ -2403,6 +2403,7 @@ static const int sysclk_rates[] = {
>  static void wm8962_configure_bclk(struct snd_soc_component *component)
>  {
>  	struct wm8962_priv *wm8962 = snd_soc_component_get_drvdata(component);
> +	int best, min_diff, diff;
>  	int dspclk, i;
>  	int clocking2 = 0;
>  	int clocking4 = 0;
> @@ -2473,23 +2474,23 @@ static void wm8962_configure_bclk(struct snd_soc_component *component)
>  
>  	dev_dbg(component->dev, "DSPCLK is %dHz, BCLK %d\n", dspclk, wm8962->bclk);
>  

Very minor nit but it would probably be nice to have some
equivalent debug statement that prints out the actual BCLK we end
up with. There are a couple of statements printing the requested
speed, but nothing that will output what the driver actually
applies after this change.

Otherwise I think the change looks good.

Thanks,
Charles

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] ASoC: wm8962: Relax bit clock divider searching
  2021-03-03 11:21 [PATCH] ASoC: wm8962: Relax bit clock divider searching Shengjiu Wang
  2021-03-05 12:43 ` Daniel Baluta
  2021-03-07 17:29 ` Charles Keepax
@ 2021-03-16 17:59 ` Mark Brown
  2 siblings, 0 replies; 4+ messages in thread
From: Mark Brown @ 2021-03-16 17:59 UTC (permalink / raw)
  To: ckeepax, kuninori.morimoto.gx, linux-kernel, patches,
	peter.ujfalusi, perex, Shengjiu Wang, tiwai, lgirdwood,
	gustavoars, alsa-devel, pierre-louis.bossart
  Cc: Mark Brown

On Wed, 3 Mar 2021 19:21:28 +0800, Shengjiu Wang wrote:
> With S20_3LE format case, the sysclk = rate * 384,
> the bclk = rate * 20 * 2, there is no proper bclk divider
> for 384 / 40, because current condition needs exact match.
> So driver fails to configure the clocking:
> 
> wm8962 3-001a: Unsupported BCLK ratio 9
> 
> [...]

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[1/1] ASoC: wm8962: Relax bit clock divider searching
      commit: aa4890f673f9d54d3cb0ea156acfe41958ea7f08

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-03-16 18:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-03 11:21 [PATCH] ASoC: wm8962: Relax bit clock divider searching Shengjiu Wang
2021-03-05 12:43 ` Daniel Baluta
2021-03-07 17:29 ` Charles Keepax
2021-03-16 17:59 ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).