From: Charles Keepax <ckeepax@opensource.cirrus.com>
To: Shengjiu Wang <shengjiu.wang@nxp.com>
Cc: lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz,
tiwai@suse.com, patches@opensource.cirrus.com,
linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org,
shengjiu.wang@gmail.com
Subject: Re: [PATCH v3] ASoC: wm8524: enable constraints when sysclk is configured.
Date: Fri, 20 Jun 2025 09:26:00 +0100 [thread overview]
Message-ID: <aFUbGFNAISmamfv8@opensource.cirrus.com> (raw)
In-Reply-To: <20250620021403.624303-1-shengjiu.wang@nxp.com>
On Fri, Jun 20, 2025 at 10:14:03AM +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, and check the rate in hw_params.
>
> So overall there are three cases that need to be considered:
> - call set_sysclk() on init, then constraints will be initialized.
> - don't call set_sysclk() on init, but call it after startup(), then
> constraints will be configured, the constraints can be cleared with
> call set_sysclk() again in shutdown().
> - don't call set_sysclk() in the whole flow, then there are no any
> constraints. The clocks depend on cpu dai.
>
> Enlarge the WM8524_NUM_RATES to 12, as the supported rate range is 8kHz
> to 192kHz.
>
> Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com>
> ---
> +static int wm8524_hw_params(struct snd_pcm_substream *substream,
> + struct snd_pcm_hw_params *params,
> + struct snd_soc_dai *dai)
> +{
> + struct snd_soc_component *component = dai->component;
> + struct wm8524_priv *wm8524 = snd_soc_component_get_drvdata(component);
> + int i;
> +
> + /* If sysclk is not configured, no need to check the rate */
> + if (!wm8524->sysclk)
> + return 0;
This is kinda the opposite of what I was hoping we could do. The
idea was to make sure we returned an error if we can't support
the given rate. So if we don't have the constraint, we check the
value in hw_params. This looks like it checks in hw_params only
in the case the constraint existed, but in that case there is no
need to check because we had the constraint.
Thanks,
Charles
> + /* Find a supported LRCLK rate */
> + for (i = 0; i < wm8524->rate_constraint.count; i++) {
> + if (wm8524->rate_constraint.list[i] == params_rate(params))
> + break;
> + }
> +
> + if (i == wm8524->rate_constraint.count) {
> + dev_err(component->dev, "LRCLK %d unsupported with MCLK %d\n",
> + params_rate(params), wm8524->sysclk);
> + return -EINVAL;
> + }
> +
> + return 0;
> +}
next prev parent reply other threads:[~2025-06-20 8:26 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-20 2:14 [PATCH v3] ASoC: wm8524: enable constraints when sysclk is configured Shengjiu Wang
2025-06-20 8:26 ` Charles Keepax [this message]
2025-06-20 8:42 ` Charles Keepax
2025-06-20 12:42 ` Mark Brown
2025-06-20 16:01 ` Charles Keepax
2025-06-24 8:24 ` Shengjiu Wang
2025-06-25 14:36 ` Mark Brown
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aFUbGFNAISmamfv8@opensource.cirrus.com \
--to=ckeepax@opensource.cirrus.com \
--cc=broonie@kernel.org \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=patches@opensource.cirrus.com \
--cc=perex@perex.cz \
--cc=shengjiu.wang@gmail.com \
--cc=shengjiu.wang@nxp.com \
--cc=tiwai@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).