Skip to contentSkip to conversation

ASoC: wm8960: Use physical width for bclk

RFC PATCH In review Daniel Baluta 4 participants 5 messages Mar 14, 2017 – Mar 15, 2017

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 ASoC: wm8960: Use physical width for bclk

bclk is derived from sysclk with the help of bclk_divs. Anyhow, for S20_3LE format there is no bclk_divs that could be used to derive an exact bclk.

We can fix this by using storage size instead the exact number of bits of the sample when computing bclk.

With this approach we can play S20_3LE encoded files at the cost of some unused BCLK cycles for S20_3LE and S24_LE.

---
 sound/soc/codecs/wm8960.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
sound/soc/codecs/wm8960.c +2 -1
index e1429e3..18ca5fc 100644
@@ -722,7 +722,8 @@ static int wm8960_hw_params(struct snd_pcm_substream *substream,
 	bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
 	int i;
 
-	wm8960->bclk = snd_soc_params_to_bclk(params);
+	wm8960->bclk = params_physical_width(params) *
+		params_channels(params) * params_rate(params);
 	if (params_channels(params) == 1)
 		wm8960->bclk *= 2;
 
Signature · 1 line
2.7.4
#1 lore raw
Quoted 20 lines · Daniel Baluta

bclk is derived from sysclk with the help of bclk_divs. Anyhow, for S20_3LE format there is no bclk_divs that could be used to derive an exact bclk.

We can fix this by using storage size instead the exact number of bits of the sample when computing bclk.

With this approach we can play S20_3LE encoded files at the cost of some unused BCLK cycles for S20_3LE and S24_LE.

---
 sound/soc/codecs/wm8960.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
sound/soc/codecs/wm8960.c +0 -0
index e1429e3..18ca5fc 100644

sound/soc/codecs/wm8960.c static int wm8960_hw_params(struct snd_pcm_substream *substream, · line 728

Quoted 8 lines
sound/soc/codecs/wm8960.c +2 -1
@@ -722,7 +722,8 @@ static int wm8960_hw_params(struct snd_pcm_substream *substream,
 	bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
 	int i;
 
-	wm8960->bclk = snd_soc_params_to_bclk(params);
+	wm8960->bclk = params_physical_width(params) *
+		params_channels(params) * params_rate(params);
 	if (params_channels(params) == 1)
 		wm8960->bclk *= 2;

Would quite like to see Mark's thoughts on this. Feels a bit to me (although I am not certain) like we are solving the problem in the wrong place, isn't this really setting the desired BCLK and then in wm8960_configure_clocking we should set the lowest BCLK we can that is greater than or equal to the desired.

Thanks,
Charles

#2 lore raw
Quoted 28 lines · Charles Keepax
Quoted 27 lines · Daniel Baluta

bclk is derived from sysclk with the help of bclk_divs. Anyhow, for S20_3LE format there is no bclk_divs that could be used to derive an exact bclk.

We can fix this by using storage size instead the exact number of bits of the sample when computing bclk.

With this approach we can play S20_3LE encoded files at the cost of some unused BCLK cycles for S20_3LE and S24_LE.

---
 sound/soc/codecs/wm8960.c | 3 ++-

 1 file changed, 2 insertions(+), 1 deletion(-)
sound/soc/codecs/wm8960.c +0 -0
index e1429e3..18ca5fc 100644
@@ -722,7 +722,8 @@ static int wm8960_hw_params(struct
 snd_pcm_substream *substream,
  	bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
  	int i;

sound/soc/codecs/wm8960.c +1 -1
-	wm8960->bclk = snd_soc_params_to_bclk(params);
+	wm8960->bclk = params_physical_width(params) *
Quoted 8 lines
Quoted 3 lines
sound/soc/codecs/wm8960.c +1 -0
+		params_channels(params) * params_rate(params);

  if (params_channels(params) == 1)
  wm8960->bclk *= 2;

Would quite like to see Mark's thoughts on this. Feels a bit to me (although I am not certain) like we are solving the problem in the wrong place, isn't this really setting the desired BCLK and then in wm8960_configure_clocking we should set the lowest BCLK we can that is greater than or equal to the desired.

Is there any standard way of doing this in ASoC? Couldn't find any example where the bitclk is relaxed to lowest value greater than the desired one.

I have prepared some patches with this approach, you can look at them here:

http://pastebin.com/0xW0E82N - some refactoring of sysclk search
http://pastebin.com/QRt1UT7Q - relax bitclk value

Daniel.
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

maintainer
#3 lore raw
In reply to Charles Keepax
Quoted 13 lines · Charles Keepax

sound/soc/codecs/wm8960.c static int wm8960_hw_params(struct snd_pcm_substream *substream, · line 728

Quoted 5 lines · Daniel Baluta
sound/soc/codecs/wm8960.c +2 -1
-	wm8960->bclk = snd_soc_params_to_bclk(params);
+	wm8960->bclk = params_physical_width(params) *
+		params_channels(params) * params_rate(params);
 	if (params_channels(params) == 1)
 		wm8960->bclk *= 2;

Would quite like to see Mark's thoughts on this. Feels a bit to me (although I am not certain) like we are solving the problem in the wrong place, isn't this really setting the desired BCLK and then in wm8960_configure_clocking we should set the lowest BCLK we can that is greater than or equal to the desired.

Exactly, this is the wrong fix in the wrong place - if this is something we want to do we should be doing it in the shared functions so all CODECs get the same behaviour but really I think Charles' suggestion makes more sense.

#4 lore raw
Quoted 15 lines · Mark Brown
Quoted 8 lines · Charles Keepax

sound/soc/codecs/wm8960.c static int wm8960_hw_params(struct snd_pcm_substream *substream, · line 728

Quoted 5 lines · Daniel Baluta
sound/soc/codecs/wm8960.c +2 -1
-   wm8960->bclk = snd_soc_params_to_bclk(params);
+   wm8960->bclk = params_physical_width(params) *
+           params_channels(params) * params_rate(params);
    if (params_channels(params) == 1)
            wm8960->bclk *= 2;
Quoted 5 lines

Would quite like to see Mark's thoughts on this. Feels a bit to me (although I am not certain) like we are solving the problem in the wrong place, isn't this really setting the desired BCLK and then in wm8960_configure_clocking we should set the lowest BCLK we can that is greater than or equal to the desired.

Quoted 4 lines

Exactly, this is the wrong fix in the wrong place - if this is something we want to do we should be doing it in the shared functions so all CODECs get the same behaviour but really I think Charles' suggestion makes more sense.

I see your point. Thanks a lot for feedback.

I already have an implementation for Charles' suggestion.
Will send the patches asap.

thanks,
Daniel.