ASoC: wm8741: Varios enhancements
Subsystems (3)
cover ASoC: wm8741: Varios enhancements
This patch series contains the following 3 patches for the WM8741 codec driver.
1) Adds digital mute callback.
2) Sets oversampling rate mode (OSR), required for sampling rates > 48kHz.
3) Sets MCLK/LRCLK sampling rate ratio (SR), avoids relying on auto-detection.
Sergej Sawazki (3):
ASoC: wm8741: Add digital mute callback
ASoC: wm8741: Set OSR mode in hw_params()
ASoC: wm8741: Set SR mode in hw_params()
sound/soc/codecs/wm8741.c | 49 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 41 insertions(+), 8 deletions(-)
Signature · 1 line
2.7.4
PATCH 1/3 ASoC: wm8741: Add digital mute callback
--- sound/soc/codecs/wm8741.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
sound/soc/codecs/wm8741.c +12 -0
@@ -351,6 +351,17 @@ static int wm8741_set_dai_fmt(struct snd_soc_dai *codec_dai,return 0 ; } +int wm8741_mute (struct snd_soc_dai *codec_dai,int mute) +{ +struct snd_soc_codec *codec = codec_dai->codec; + +dev_dbg (codec->dev,"%s: mute = %d\n" , __func__, mute); + +snd_soc_update_bits (codec,WM8741_VOLUME_CONTROL , +WM8741_SOFT_MASK , !!mute <<WM8741_SOFT_SHIFT ); +return 0 ; +} +#define WM8741_RATES (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \ SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | \ SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_176400 | \
@@ -364,6 +375,7 @@ static const struct snd_soc_dai_ops wm8741_dai_ops = { .hw_params = wm8741_hw_params, .set_sysclk = wm8741_set_dai_sysclk, .set_fmt = wm8741_set_dai_fmt, + .digital_mute = wm8741_mute, };static struct snd_soc_dai_driver wm8741_dai = {
Signature · 1 line
2.7.4
Re: [PATCH 1/3] ASoC: wm8741: Add digital mute callback
Quoted 10 lines · Sergej Sawazki
Signed-off-by Sergej Sawazki <[email protected]>--- sound/soc/codecs/wm8741.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)sound/soc/codecs/wm8741.c +0
-0
sound/soc/codecs/wm8741.c static int wm8741_set_dai_fmt(struct snd_soc_dai *codec_dai, · line 358
Quoted 8 lines
sound/soc/codecs/wm8741.c +5
-0@@ -351,6 +351,17 @@ static int wm8741_set_dai_fmt(struct snd_soc_dai *codec_dai,return 0 ; } +int wm8741_mute (struct snd_soc_dai *codec_dai,int mute) +{ +struct snd_soc_codec *codec = codec_dai->codec; + +dev_dbg (codec->dev,"%s: mute = %d\n" , __func__, mute);
Its not really normal style to use __func__ in this sort of print, just make it descriptive of what it does. Although I would also say you could just drop it as well if you fancied it is a little verbose even for debug output.
Otherwise this patch looks ok to me.
Thanks,
Charles
Re: [PATCH 1/3] ASoC: wm8741: Add digital mute callback
Thanks Charles,
agreed about the __func__. But, I would like to keep the debug message, in order to be consistent with the other callbacks. They all print debug messages.
Would it be ok for you?
Regards,
Sergej
Am 05.09.2017 um 15:33 schrieb Charles Keepax:
Quoted 30 lines · Sergej Sawazki
Quoted 10 lines
Signed-off-by Sergej Sawazki <[email protected]>--- sound/soc/codecs/wm8741.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)sound/soc/codecs/wm8741.c +0
-0sound/soc/codecs/wm8741.c static int wm8741_set_dai_fmt(struct snd_soc_dai *codec_dai, · line 358
Quoted 8 lines
sound/soc/codecs/wm8741.c +5
-0@@ -351,6 +351,17 @@ static int wm8741_set_dai_fmt(struct snd_soc_dai *codec_dai,return 0 ; } +int wm8741_mute (struct snd_soc_dai *codec_dai,int mute) +{ +struct snd_soc_codec *codec = codec_dai->codec; + +dev_dbg (codec->dev,"%s: mute = %d\n" , __func__, mute);Its not really normal style to use
__func__in this sort of print, just make it descriptive of what it does. Although I would also say you could just drop it as well if you fancied it is a little verbose even for debug output.Otherwise this patch looks ok to me.
Thanks,
Charles
Re: [PATCH 1/3] ASoC: wm8741: Add digital mute callback
Quoted 8 lines · Sergej Sawazki
Thanks Charles,
agreed about the
__func__. But, I would like to keep the debug message, in order to be consistent with the other callbacks. They all print debug messages.Would it be ok for you?
I am ok with leaving the print, if we update the message.
Thanks,
Charles
PATCH 2/3 ASoC: wm8741: Set OSR mode in hw_params()
In reply to Sergej SawazkiFor correct operation of the digital filtering and other processing on the WM8741, the user must ensure the correct value of OSR[1:0] is set at all times.[1] Hence, depending the selected sampling rate, set the OSR (over- sampling rate) mode in hw_params().
References:
[1] https://d3uzseaevmutz1.cloudfront.net/pubs/proDatasheet/WM8741_v4.3.pdf "WM8741 Data Sheet"
--- sound/soc/codecs/wm8741.c | 8 ++++++++ 1 file changed, 8 insertions(+)
sound/soc/codecs/wm8741.c +8 -0
@@ -197,6 +197,7 @@ static int wm8741_hw_params(struct snd_pcm_substream *substream,struct snd_soc_codec *codec = dai->codec;struct wm8741_priv *wm8741 =snd_soc_codec_get_drvdata (codec);u16 iface =snd_soc_read (codec,WM8741_FORMAT_CONTROL ) &0x1FC ; +u16 mode =snd_soc_read (codec,WM8741_MODE_CONTROL_1 ) &0x183 ;int i;/* The set of sample rates that can be supported depends on the
@@ -220,6 +221,12 @@ static int wm8741_hw_params(struct snd_pcm_substream *substream,return -EINVAL ; } +/* oversampling rate */ +if (params_rate (params) >96000 ) + mode |=0x0040 ; +else if (params_rate (params) >48000 ) + mode |=0x0020 ; +/* bit size */ switch (params_width (params)) {case 16 :
@@ -243,6 +250,7 @@ static int wm8741_hw_params(struct snd_pcm_substream *substream, params_width(params), params_rate(params));snd_soc_write (codec,WM8741_FORMAT_CONTROL , iface); +snd_soc_write (codec,WM8741_MODE_CONTROL_1 , mode);return 0 ; }
Signature · 1 line
2.7.4
Re: [PATCH 2/3] ASoC: wm8741: Set OSR mode in hw_params()
sound/soc/codecs/wm8741.c static int wm8741_hw_params(struct snd_pcm_substream *substream, · line 228
Quoted 5 lines · Sergej Sawazki
sound/soc/codecs/wm8741.c +5
-0+/* oversampling rate */ +if (params_rate (params) >96000 ) + mode |=0x0040 ; +else if (params_rate (params) >48000 ) + mode |=0x0020 ;
Should this not have a case for <= 48k as well? To reset the mode if it was set on a previous playback.
sound/soc/codecs/wm8741.c static int wm8741_hw_params(struct snd_pcm_substream *substream, · line 253
Quoted 9 lines
sound/soc/codecs/wm8741.c +2
-0+/* bit size */ switch (params_width (params)) {case 16 :@@ -243,6 +250,7 @@ static int wm8741_hw_params(struct snd_pcm_substream *substream, params_width(params), params_rate(params));snd_soc_write (codec,WM8741_FORMAT_CONTROL , iface); +snd_soc_write (codec,WM8741_MODE_CONTROL_1 , mode);
Better to use an update_bits rather than basically open-code it with read and then this write.
Thanks,
Charles
Re: [PATCH 2/3] ASoC: wm8741: Set OSR mode in hw_params()
Am 05.09.2017 um 18:12 schrieb Charles Keepax:
Quoted 10 lines · Sergej Sawazki
sound/soc/codecs/wm8741.c static int wm8741_hw_params(struct snd_pcm_substream *substream, · line 228
Quoted 5 lines
sound/soc/codecs/wm8741.c +5
-0+/* oversampling rate */ +if (params_rate (params) >96000 ) + mode |=0x0040 ; +else if (params_rate (params) >48000 ) + mode |=0x0020 ;Should this not have a case for <= 48k as well? To reset the mode if it was set on a previous playback.
It is reset in here:
u16 mode = snd_soc_read(codec, WM8741_MODE_CONTROL_1) & 0x183;
For <= 48k we simply leave it 0. I though about an empty else statement, but it is kind of strange, too.
Quoted 7 lines
Quoted 7 lines
sound/soc/codecs/wm8741.c +1
-0+/* bit size */ switch (params_width (params)) {case 16 :@@ -243,6 +250,7 @@ static int wm8741_hw_params(struct snd_pcm_substream *substream, params_width(params), params_rate(params));
Quoted 6 lines
sound/soc/codecs/wm8741.c static int wm8741_hw_params(struct snd_pcm_substream *substream, · line 253
Quoted 2 lines
sound/soc/codecs/wm8741.c +1
-0snd_soc_write (codec,WM8741_FORMAT_CONTROL , iface); +snd_soc_write (codec,WM8741_MODE_CONTROL_1 , mode);Better to use an
update_bitsrather than basically open-code it with read and then this write.
I have used write() and not update_bits() here to be consistent with the way the WM8741_FORMAT_CONTROL register is written. If we change it to update_bits(), we should refactor the WM8741_FORMAT_CONTROL write to use update_bits() too, right?
Thanks,
Sergej
Re: [PATCH 2/3] ASoC: wm8741: Set OSR mode in hw_params()
Quoted 12 lines · Sergej Sawazki
Am 05.09.2017 um 18:12 schrieb Charles Keepax:
Quoted 10 lines · Sergej Sawazki
sound/soc/codecs/wm8741.c static int wm8741_hw_params(struct snd_pcm_substream *substream, · line 228
Quoted 5 lines
sound/soc/codecs/wm8741.c +5
-0+/* oversampling rate */ +if (params_rate (params) >96000 ) + mode |=0x0040 ; +else if (params_rate (params) >48000 ) + mode |=0x0020 ;Should this not have a case for <= 48k as well? To reset the mode if it was set on a previous playback.
Quoted 7 lines
It is reset in here:
u16 mode = snd_soc_read(codec, WM8741_MODE_CONTROL_1) & 0x183;For <= 48k we simply leave it 0. I though about an empty else statement, but it is kind of strange, too.
Oops.. sorry yes that is fine.
Quoted 13 lines
Quoted 12 lines
sound/soc/codecs/wm8741.c static int wm8741_hw_params(struct snd_pcm_substream *substream, · line 252
Quoted 8 lines
sound/soc/codecs/wm8741.c +2
-0+/* bit size */ switch (params_width (params)) {case 16 :@@ -243,6 +250,7 @@ static int wm8741_hw_params(struct snd_pcm_substream *substream, params_width(params), params_rate(params));snd_soc_write (codec,WM8741_FORMAT_CONTROL , iface); +snd_soc_write (codec,WM8741_MODE_CONTROL_1 , mode);Better to use an
update_bitsrather than basically open-code it with read and then this write.
Quoted 5 lines
I have used
write()and notupdate_bits()here to be consistent with the way theWM8741_FORMAT_CONTROLregister is written. If we change it toupdate_bits(), we should refactor theWM8741_FORMAT_CONTROLwrite to useupdate_bits()too, right?
Yeah that should probably be an update bits too by the looks of it.
Thanks,
Charles
Re: [PATCH 2/3] ASoC: wm8741: Set OSR mode in hw_params()
Am 06.09.2017 um 10:20 schrieb Charles Keepax:
Quoted 3 lines · Sergej Sawazki
Quoted 2 lines
Am 05.09.2017 um 18:12 schrieb Charles Keepax:
Quoted 1 line · Sergej Sawazki
[...]
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
sound/soc/codecs/wm8741.c static int wm8741_hw_params(struct snd_pcm_substream *substream, · line 252
Quoted 4 lines
sound/soc/codecs/wm8741.c +1
-0@@ -243,6 +250,7 @@ static int wm8741_hw_params(struct snd_pcm_substream *substream, params_width(params), params_rate(params));snd_soc_write (codec,WM8741_FORMAT_CONTROL , iface); +snd_soc_write (codec,WM8741_MODE_CONTROL_1 , mode);Better to use an
update_bitsrather than basically open-code it with read and then this write.
Quoted 8 lines
Quoted 5 lines
I have used
write()and notupdate_bits()here to be consistent with the way theWM8741_FORMAT_CONTROLregister is written. If we change it toupdate_bits(), we should refactor theWM8741_FORMAT_CONTROLwrite to useupdate_bits()too, right?Yeah that should probably be an update bits too by the looks of it.
Charles,
I think we should split "adding the OSR mode configuration" and "refactoring the code to use update_bits()" in at least two commits.
For consistency, I would keep the write() in this patch, and provide the update_bits() refactoring later. What do you think?
Thanks,
Sergej
Re: [PATCH 2/3] ASoC: wm8741: Set OSR mode in hw_params()
Quoted 25 lines · Sergej Sawazki
Am 06.09.2017 um 10:20 schrieb Charles Keepax:
Quoted 3 lines · Sergej Sawazki
Quoted 2 lines
Am 05.09.2017 um 18:12 schrieb Charles Keepax:
Quoted 1 line · Sergej Sawazki
[...]
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
sound/soc/codecs/wm8741.c static int wm8741_hw_params(struct snd_pcm_substream *substream, · line 252
Quoted 4 lines
sound/soc/codecs/wm8741.c +1
-0@@ -243,6 +250,7 @@ static int wm8741_hw_params(struct snd_pcm_substream *substream, params_width(params), params_rate(params));snd_soc_write (codec,WM8741_FORMAT_CONTROL , iface); +snd_soc_write (codec,WM8741_MODE_CONTROL_1 , mode);Better to use an
update_bitsrather than basically open-code it with read and then this write.Quoted 8 lines
Quoted 5 lines
I have used
write()and notupdate_bits()here to be consistent with the way theWM8741_FORMAT_CONTROLregister is written. If we change it toupdate_bits(), we should refactor theWM8741_FORMAT_CONTROLwrite to useupdate_bits()too, right?Yeah that should probably be an update bits too by the looks of it.
Quoted 8 lines
Charles,
I think we should split "adding the OSR mode configuration" and "refactoring the code to use
update_bits()" in at least two commits.For consistency, I would keep the
write()in this patch, and provide theupdate_bits()refactoring later. What do you think?
Two commits seems sensible although its only a very small refactoring so feels like we might as well get it done whilst changing the code. I am happy to do the initial refactoring patch, if that helps but I don't presently have hardware to test this CODEC.
Thanks,
Charles
Re: [PATCH 2/3] ASoC: wm8741: Set OSR mode in hw_params()
Quoted 2 lines · Charles Keepax
Quoted 1 line · Sergej Sawazki
Am 06.09.2017 um 10:20 schrieb Charles Keepax:
...
Quoted 8 lines
Quoted 7 lines
I think we should split "adding the OSR mode configuration" and "refactoring the code to use
update_bits()" in at least two commits.For consistency, I would keep the
write()in this patch, and provide theupdate_bits()refactoring later. What do you think?
Quoted 6 lines
Two commits seems sensible although its only a very small refactoring so feels like we might as well get it done whilst changing the code. I am happy to do the initial refactoring patch, if that helps but I don't presently have hardware to test this CODEC.
Thanks Charles,
I have the hardware and could make the tests if you provide initial refactoring patch.
Regards
Sergej
PATCH 3/3 ASoC: wm8741: Set SR mode in hw_params()
In reply to Sergej SawazkiSet the ratio of MCLK/LRCLK in hw_params() instead of relying on the auto-detection.
The ratio of MCLK/LRCLK is known to the driver, there is no need to let the device to detect it.
--- sound/soc/codecs/wm8741.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-)
sound/soc/codecs/wm8741.c +21 -8
@@ -198,7 +198,6 @@ static int wm8741_hw_params(struct snd_pcm_substream *substream,struct wm8741_priv *wm8741 =snd_soc_codec_get_drvdata (codec);u16 iface =snd_soc_read (codec,WM8741_FORMAT_CONTROL ) &0x1FC ;u16 mode =snd_soc_read (codec,WM8741_MODE_CONTROL_1 ) &0x183 ; -int i;/* The set of sample rates that can be supported depends on the * MCLK supplied to the CODEC - enforce this.
@@ -209,13 +208,27 @@ static int wm8741_hw_params(struct snd_pcm_substream *substream,return -EINVAL ; } -/* Find a supported LRCLK rate */ -for (i =0 ; i < wm8741->sysclk_constraints->count; i++) { -if (wm8741->sysclk_constraints->list[i] ==params_rate (params)) -break ; - } - -if (i == wm8741->sysclk_constraints->count) { +/* MCLK to LRCLK sampling rate ratio */ +switch (wm8741->sysclk /params_rate (params)) { +case 128 : + mode |=0x0004 ; +break ; +case 192 : + mode |=0x0008 ; +break ; +case 256 : + mode |=0x000C ; +break ; +case 384 : + mode |=0x0010 ; +break ; +case 512 : + mode |=0x0014 ; +break ; +case 768 : + mode |=0x0018 ; +break ; +default :dev_err (codec->dev,"LRCLK %d unsupported with MCLK %d\n" ,params_rate (params), wm8741->sysclk);return -EINVAL ;
Signature · 1 line
2.7.4
Re: [PATCH 3/3] ASoC: wm8741: Set SR mode in hw_params()
Quoted 6 lines · Sergej Sawazki
Set the ratio of MCLK/LRCLK in
hw_params()instead of relying on the auto-detection.The ratio of MCLK/LRCLK is known to the driver, there is no need to let the device to detect it.
But also no reason to not let it do so, are there some problems with the auto-detect?
Quoted 18 lines
Signed-off-by Sergej Sawazki <[email protected]>--- sound/soc/codecs/wm8741.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-)sound/soc/codecs/wm8741.c +0
-1@@ -198,7 +198,6 @@ static int wm8741_hw_params(struct snd_pcm_substream *substream,struct wm8741_priv *wm8741 =snd_soc_codec_get_drvdata (codec);u16 iface =snd_soc_read (codec,WM8741_FORMAT_CONTROL ) &0x1FC ;u16 mode =snd_soc_read (codec,WM8741_MODE_CONTROL_1 ) &0x183 ; -int i;/* The set of sample rates that can be supported depends on the * MCLK supplied to the CODEC - enforce this.
sound/soc/codecs/wm8741.c static int wm8741_hw_params(struct snd_pcm_substream *substream, · line 216
Quoted 8 lines
sound/soc/codecs/wm8741.c +0
-5@@ -209,13 +208,27 @@ static int wm8741_hw_params(struct snd_pcm_substream *substream,return -EINVAL ; } -/* Find a supported LRCLK rate */ -for (i =0 ; i < wm8741->sysclk_constraints->count; i++) { -if (wm8741->sysclk_constraints->list[i] ==params_rate (params)) -break ; - }
This looks like it should be in a separate patch, is removing this part of this patch? It feels like the constraints should have already been applied by startup so we should never be able to fail here in hw_params, is that why you are removing it?
Thanks,
Charles
Re: [PATCH 3/3] ASoC: wm8741: Set SR mode in hw_params()
Am 05.09.2017 um 18:23 schrieb Charles Keepax:
Quoted 11 lines · Sergej Sawazki
Quoted 6 lines
Set the ratio of MCLK/LRCLK in
hw_params()instead of relying on the auto-detection.The ratio of MCLK/LRCLK is known to the driver, there is no need to let the device to detect it.
But also no reason to not let it do so, are there some problems with the auto-detect?
I haven't noticed any problems. But, as we know the ratio and the device provides an interface to set it, why don't we just do it? Setting it feels right somehow, even if it is not absolutely necessary.
Quoted 21 lines
Quoted 21 lines
Signed-off-by Sergej Sawazki <[email protected]>--- sound/soc/codecs/wm8741.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-)sound/soc/codecs/wm8741.c +0
-1@@ -198,7 +198,6 @@ static int wm8741_hw_params(struct snd_pcm_substream *substream,struct wm8741_priv *wm8741 =snd_soc_codec_get_drvdata (codec);u16 iface =snd_soc_read (codec,WM8741_FORMAT_CONTROL ) &0x1FC ;u16 mode =snd_soc_read (codec,WM8741_MODE_CONTROL_1 ) &0x183 ; -int i;/* The set of sample rates that can be supported depends on the * MCLK supplied to the CODEC - enforce this. @@ -209,13 +208,27 @@ static int wm8741_hw_params(struct snd_pcm_substream *substream,return -EINVAL ; }
Quoted 11 lines
sound/soc/codecs/wm8741.c static int wm8741_hw_params(struct snd_pcm_substream *substream, · line 216
Quoted 5 lines
sound/soc/codecs/wm8741.c +0
-5-/* Find a supported LRCLK rate */ -for (i =0 ; i < wm8741->sysclk_constraints->count; i++) { -if (wm8741->sysclk_constraints->list[i] ==params_rate (params)) -break ; - }This looks like it should be in a separate patch, is removing this part of this patch? It feels like the constraints should have already been applied by startup so we should never be able to fail here in
hw_params, is that why you are removing it?
This for loop has been replaced by a switch statement. The switch is now checking if the LRCLK rate is supported with the supplied MCLK and sets the MCLK/LRCLK ratio if it is.
Thanks,
Sergej
Re: [PATCH 3/3] ASoC: wm8741: Set SR mode in hw_params()
Quoted 9 lines · Sergej Sawazki
Am 05.09.2017 um 18:23 schrieb Charles Keepax:
Quoted 8 lines · Sergej Sawazki
Quoted 6 lines
Set the ratio of MCLK/LRCLK in
hw_params()instead of relying on the auto-detection.The ratio of MCLK/LRCLK is known to the driver, there is no need to let the device to detect it.
Quoted 8 lines
Quoted 3 lines
But also no reason to not let it do so, are there some problems with the auto-detect?
I haven't noticed any problems. But, as we know the ratio and the device provides an interface to set it, why don't we just do it? Setting it feels right somehow, even if it is not absolutely necessary.
I would lean more towards if the auto-detect works we might as well use it and not add code we don't need.
Thanks,
Charles