* [PATCH v2] ASoC: wm8524: enable constraints when sysclk is configured.
@ 2025-06-17 7:18 Shengjiu Wang
2025-06-17 8:55 ` Charles Keepax
0 siblings, 1 reply; 4+ messages in thread
From: Shengjiu Wang @ 2025-06-17 7:18 UTC (permalink / raw)
To: lgirdwood, broonie, perex, tiwai, patches, linux-sound,
linux-kernel, shengjiu.wang
In some cases, the sysclk won't be configured on init, and sysclk can be
changed in hw_params() according to different sample rate, for example,
for 44kHz sample rate, the sysclk is 11.2896MHz, for 48kHz sample rate,
the sysclk is 12.288MHz.
In order to support the above case, only enable constraints when sysclk
is configured.
Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com>
---
changes in v2
- Don't remove constraints, but only enable constraints when sysclk
is configured.
sound/soc/codecs/wm8524.c | 17 +++++++----------
1 file changed, 7 insertions(+), 10 deletions(-)
diff --git a/sound/soc/codecs/wm8524.c b/sound/soc/codecs/wm8524.c
index 403e513f3fa8..5d8fb45db272 100644
--- a/sound/soc/codecs/wm8524.c
+++ b/sound/soc/codecs/wm8524.c
@@ -63,17 +63,12 @@ static int wm8524_startup(struct snd_pcm_substream *substream,
struct wm8524_priv *wm8524 = snd_soc_component_get_drvdata(component);
/* The set of sample rates that can be supported depends on the
- * MCLK supplied to the CODEC - enforce this.
+ * MCLK supplied to the CODEC.
*/
- if (!wm8524->sysclk) {
- dev_err(component->dev,
- "No MCLK configured, call set_sysclk() on init\n");
- return -EINVAL;
- }
-
- snd_pcm_hw_constraint_list(substream->runtime, 0,
- SNDRV_PCM_HW_PARAM_RATE,
- &wm8524->rate_constraint);
+ if (wm8524->sysclk)
+ snd_pcm_hw_constraint_list(substream->runtime, 0,
+ SNDRV_PCM_HW_PARAM_RATE,
+ &wm8524->rate_constraint);
gpiod_set_value_cansleep(wm8524->mute, 1);
@@ -98,6 +93,8 @@ static int wm8524_set_dai_sysclk(struct snd_soc_dai *codec_dai,
int i, j = 0;
wm8524->sysclk = freq;
+ if (!wm8524->sysclk)
+ return 0;
wm8524->rate_constraint.count = 0;
for (i = 0; i < ARRAY_SIZE(lrclk_ratios); i++) {
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] ASoC: wm8524: enable constraints when sysclk is configured.
2025-06-17 7:18 [PATCH v2] ASoC: wm8524: enable constraints when sysclk is configured Shengjiu Wang
@ 2025-06-17 8:55 ` Charles Keepax
2025-06-18 7:45 ` Shengjiu Wang
0 siblings, 1 reply; 4+ messages in thread
From: Charles Keepax @ 2025-06-17 8:55 UTC (permalink / raw)
To: Shengjiu Wang
Cc: lgirdwood, broonie, perex, tiwai, patches, linux-sound,
linux-kernel, shengjiu.wang
On Tue, Jun 17, 2025 at 03:18:33PM +0800, Shengjiu Wang wrote:
> In some cases, the sysclk won't be configured on init, and sysclk can be
> changed in hw_params() according to different sample rate, for example,
> for 44kHz sample rate, the sysclk is 11.2896MHz, for 48kHz sample rate,
> the sysclk is 12.288MHz.
>
> In order to support the above case, only enable constraints when sysclk
> is configured.
>
> Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com>
> ---
> changes in v2
> - Don't remove constraints, but only enable constraints when sysclk
> is configured.
>
> sound/soc/codecs/wm8524.c | 17 +++++++----------
> 1 file changed, 7 insertions(+), 10 deletions(-)
>
> diff --git a/sound/soc/codecs/wm8524.c b/sound/soc/codecs/wm8524.c
> index 403e513f3fa8..5d8fb45db272 100644
> --- a/sound/soc/codecs/wm8524.c
> +++ b/sound/soc/codecs/wm8524.c
> @@ -63,17 +63,12 @@ static int wm8524_startup(struct snd_pcm_substream *substream,
> struct wm8524_priv *wm8524 = snd_soc_component_get_drvdata(component);
>
> /* The set of sample rates that can be supported depends on the
> - * MCLK supplied to the CODEC - enforce this.
> + * MCLK supplied to the CODEC.
> */
> - if (!wm8524->sysclk) {
> - dev_err(component->dev,
> - "No MCLK configured, call set_sysclk() on init\n");
> - return -EINVAL;
> - }
> -
> - snd_pcm_hw_constraint_list(substream->runtime, 0,
> - SNDRV_PCM_HW_PARAM_RATE,
> - &wm8524->rate_constraint);
> + if (wm8524->sysclk)
> + snd_pcm_hw_constraint_list(substream->runtime, 0,
> + SNDRV_PCM_HW_PARAM_RATE,
> + &wm8524->rate_constraint);
>
> gpiod_set_value_cansleep(wm8524->mute, 1);
>
If we are allow the clock to be set at hw_params time, we
should probably also double check the rates in hw_params and
return an error if its not supported.
> @@ -98,6 +93,8 @@ static int wm8524_set_dai_sysclk(struct snd_soc_dai *codec_dai,
> int i, j = 0;
>
> wm8524->sysclk = freq;
> + if (!wm8524->sysclk)
> + return 0;
>
> wm8524->rate_constraint.count = 0;
> for (i = 0; i < ARRAY_SIZE(lrclk_ratios); i++) {
We probably should clear rate_constraint.count in the clearing
sysclk case, and we should probably also check if the DAI is
active. The user shoudln't be allowed to change clock there is
audio already happening.
Thanks,
Charles
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] ASoC: wm8524: enable constraints when sysclk is configured.
2025-06-17 8:55 ` Charles Keepax
@ 2025-06-18 7:45 ` Shengjiu Wang
2025-06-18 8:42 ` Charles Keepax
0 siblings, 1 reply; 4+ messages in thread
From: Shengjiu Wang @ 2025-06-18 7:45 UTC (permalink / raw)
To: Charles Keepax
Cc: Shengjiu Wang, lgirdwood, broonie, perex, tiwai, patches,
linux-sound, linux-kernel
On Tue, Jun 17, 2025 at 4:55 PM Charles Keepax
<ckeepax@opensource.cirrus.com> wrote:
>
> On Tue, Jun 17, 2025 at 03:18:33PM +0800, Shengjiu Wang wrote:
> > In some cases, the sysclk won't be configured on init, and sysclk can be
> > changed in hw_params() according to different sample rate, for example,
> > for 44kHz sample rate, the sysclk is 11.2896MHz, for 48kHz sample rate,
> > the sysclk is 12.288MHz.
> >
> > In order to support the above case, only enable constraints when sysclk
> > is configured.
> >
> > Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com>
> > ---
> > changes in v2
> > - Don't remove constraints, but only enable constraints when sysclk
> > is configured.
> >
> > sound/soc/codecs/wm8524.c | 17 +++++++----------
> > 1 file changed, 7 insertions(+), 10 deletions(-)
> >
> > diff --git a/sound/soc/codecs/wm8524.c b/sound/soc/codecs/wm8524.c
> > index 403e513f3fa8..5d8fb45db272 100644
> > --- a/sound/soc/codecs/wm8524.c
> > +++ b/sound/soc/codecs/wm8524.c
> > @@ -63,17 +63,12 @@ static int wm8524_startup(struct snd_pcm_substream *substream,
> > struct wm8524_priv *wm8524 = snd_soc_component_get_drvdata(component);
> >
> > /* The set of sample rates that can be supported depends on the
> > - * MCLK supplied to the CODEC - enforce this.
> > + * MCLK supplied to the CODEC.
> > */
> > - if (!wm8524->sysclk) {
> > - dev_err(component->dev,
> > - "No MCLK configured, call set_sysclk() on init\n");
> > - return -EINVAL;
> > - }
> > -
> > - snd_pcm_hw_constraint_list(substream->runtime, 0,
> > - SNDRV_PCM_HW_PARAM_RATE,
> > - &wm8524->rate_constraint);
> > + if (wm8524->sysclk)
> > + snd_pcm_hw_constraint_list(substream->runtime, 0,
> > + SNDRV_PCM_HW_PARAM_RATE,
> > + &wm8524->rate_constraint);
> >
> > gpiod_set_value_cansleep(wm8524->mute, 1);
> >
>
> If we are allow the clock to be set at hw_params time, we
> should probably also double check the rates in hw_params and
> return an error if its not supported.
Ok, will add the check in hw_params.
>
> > @@ -98,6 +93,8 @@ static int wm8524_set_dai_sysclk(struct snd_soc_dai *codec_dai,
> > int i, j = 0;
> >
> > wm8524->sysclk = freq;
> > + if (!wm8524->sysclk)
> > + return 0;
> >
> > wm8524->rate_constraint.count = 0;
> > for (i = 0; i < ARRAY_SIZE(lrclk_ratios); i++) {
>
> We probably should clear rate_constraint.count in the clearing
> sysclk case, and we should probably also check if the DAI is
> active. The user shoudln't be allowed to change clock there is
> audio already happening.
Seems we can't check if the DAI is active or not in sysclk(),
because startup()->set_sysclk(), in sysclk() the dai is always
active. if we allow the clock changed in hw_params time, then
we can't check if the DAI is active.
best regards
Shengjiu Wang
>
> Thanks,
> Charles
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] ASoC: wm8524: enable constraints when sysclk is configured.
2025-06-18 7:45 ` Shengjiu Wang
@ 2025-06-18 8:42 ` Charles Keepax
0 siblings, 0 replies; 4+ messages in thread
From: Charles Keepax @ 2025-06-18 8:42 UTC (permalink / raw)
To: Shengjiu Wang
Cc: Shengjiu Wang, lgirdwood, broonie, perex, tiwai, patches,
linux-sound, linux-kernel
On Wed, Jun 18, 2025 at 03:45:48PM +0800, Shengjiu Wang wrote:
> On Tue, Jun 17, 2025 at 4:55 PM Charles Keepax
> <ckeepax@opensource.cirrus.com> wrote:
> > On Tue, Jun 17, 2025 at 03:18:33PM +0800, Shengjiu Wang wrote:
> > > In some cases, the sysclk won't be configured on init, and sysclk can be
> > > changed in hw_params() according to different sample rate, for example,
> > > for 44kHz sample rate, the sysclk is 11.2896MHz, for 48kHz sample rate,
> > > the sysclk is 12.288MHz.
> > >
> > > In order to support the above case, only enable constraints when sysclk
> > > is configured.
> > >
> > > Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com>
> > > ---
> > > @@ -98,6 +93,8 @@ static int wm8524_set_dai_sysclk(struct snd_soc_dai *codec_dai,
> > > int i, j = 0;
> > >
> > > wm8524->sysclk = freq;
> > > + if (!wm8524->sysclk)
> > > + return 0;
> > >
> > > wm8524->rate_constraint.count = 0;
> > > for (i = 0; i < ARRAY_SIZE(lrclk_ratios); i++) {
> >
> > We probably should clear rate_constraint.count in the clearing
> > sysclk case, and we should probably also check if the DAI is
> > active. The user shoudln't be allowed to change clock there is
> > audio already happening.
>
> Seems we can't check if the DAI is active or not in sysclk(),
> because startup()->set_sysclk(), in sysclk() the dai is always
> active. if we allow the clock changed in hw_params time, then
> we can't check if the DAI is active.
Yeah seems you are correct there, feel free to ignore this
comment. Looking in more detail as there is only a single, single
direction DAI, I think there is less concern here as well as we
can't really open the hardware for two rates at once anyway.
Thanks,
Charles
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-06-18 8:42 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-17 7:18 [PATCH v2] ASoC: wm8524: enable constraints when sysclk is configured Shengjiu Wang
2025-06-17 8:55 ` Charles Keepax
2025-06-18 7:45 ` Shengjiu Wang
2025-06-18 8:42 ` Charles Keepax
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).