From: Krzysztof Kozlowski <krzk@kernel.org>
To: "Maxim Kochetkov" <fido_max@inbox.ru>,
"Liam Girdwood" <lgirdwood@gmail.com>,
"Mark Brown" <broonie@kernel.org>,
"Jaroslav Kysela" <perex@perex.cz>,
"Takashi Iwai" <tiwai@suse.com>,
"Uwe Kleine-König" <u.kleine-koenig@baylibre.com>,
"Andy Shevchenko" <andy.shevchenko@gmail.com>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"John Hsu" <KCHSU0@nuvoton.com>
Cc: linux-sound@vger.kernel.org, devicetree@vger.kernel.org,
alsa-devel@alsa-project.org
Subject: Re: [PATCH v2 1/2] ASoC: codecs: nau8824: Add master clock handling
Date: Fri, 28 Jun 2024 08:24:18 +0200 [thread overview]
Message-ID: <e177530a-046b-407b-8da5-85947d2d1340@kernel.org> (raw)
In-Reply-To: <20240628061750.11141-2-fido_max@inbox.ru>
On 28/06/2024 08:17, Maxim Kochetkov wrote:
> Use master clock "mclk" if provided through device tree.
>
> Signed-off-by: Maxim Kochetkov <fido_max@inbox.ru>
> ---
> sound/soc/codecs/nau8824.c | 21 +++++++++++++++++++--
> sound/soc/codecs/nau8824.h | 1 +
> 2 files changed, 20 insertions(+), 2 deletions(-)
>
> diff --git a/sound/soc/codecs/nau8824.c b/sound/soc/codecs/nau8824.c
> index f92b95b21cae..7153b746f4b1 100644
> --- a/sound/soc/codecs/nau8824.c
> +++ b/sound/soc/codecs/nau8824.c
> @@ -520,8 +520,15 @@ static int system_clock_control(struct snd_soc_dapm_widget *w,
> } else {
> nau8824_config_sysclk(nau8824, NAU8824_CLK_DIS, 0);
> }
> +
> + if (!IS_ERR(nau8824->mclk))
> + clk_disable_unprepare(nau8824->mclk);
> } else {
> dev_dbg(nau8824->dev, "system clock control : POWER ON\n");
> +
> + if (!IS_ERR(nau8824->mclk))
Nah, clock API is not used like this. Open clk_prepare_enable() and look
how it handles NULL ptr.
> + clk_prepare_enable(nau8824->mclk);
> +
> /* Check the clock source setting is proper or not
> * no matter the source is from FLL or MCLK.
> */
> @@ -563,16 +570,22 @@ static int dmic_clock_control(struct snd_soc_dapm_widget *w,
> struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
> struct nau8824 *nau8824 = snd_soc_component_get_drvdata(component);
> int src;
> + unsigned int freq;
> +
> + if (!IS_ERR(nau8824->mclk))
> + freq = clk_get_rate(nau8824->mclk);
> + else
> + freq = nau8824->fs * 256;
>
> /* The DMIC clock is gotten from system clock (256fs) divided by
> * DMIC_SRC (1, 2, 4, 8, 16, 32). The clock has to be equal or
> * less than 3.072 MHz.
> */
> for (src = 0; src < 5; src++) {
> - if ((0x1 << (8 - src)) * nau8824->fs <= DMIC_CLK)
> + if (freq / (0x1 << src) <= DMIC_CLK)
> break;
> }
> - dev_dbg(nau8824->dev, "dmic src %d for mclk %d\n", src, nau8824->fs * 256);
> + dev_dbg(nau8824->dev, "dmic src %d for mclk %d\n", src, freq);
> regmap_update_bits(nau8824->regmap, NAU8824_REG_CLK_DIVIDER,
> NAU8824_CLK_DMIC_SRC_MASK, (src << NAU8824_CLK_DMIC_SRC_SFT));
>
> @@ -1871,6 +1884,10 @@ static int nau8824_read_device_properties(struct device *dev,
> if (ret)
> nau8824->jack_eject_debounce = 1;
>
> + nau8824->mclk = devm_clk_get(dev, "mclk");
> + if (PTR_ERR(nau8824->mclk) == -EPROBE_DEFER)
> + return -EPROBE_DEFER;
Aren't you open-coding getting optional clock?
Best regards,
Krzysztof
next prev parent reply other threads:[~2024-06-28 6:24 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-28 6:17 [PATCH v2 0/2] Add master clock handling for nau8824 Maxim Kochetkov
2024-06-28 6:17 ` [PATCH v2 1/2] ASoC: codecs: nau8824: Add master clock handling Maxim Kochetkov
2024-06-28 6:24 ` Krzysztof Kozlowski [this message]
2024-06-28 6:17 ` [PATCH v2 2/2] ASoC: dt-bindings: " Maxim Kochetkov
2024-06-28 6:24 ` Krzysztof Kozlowski
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=e177530a-046b-407b-8da5-85947d2d1340@kernel.org \
--to=krzk@kernel.org \
--cc=KCHSU0@nuvoton.com \
--cc=alsa-devel@alsa-project.org \
--cc=andy.shevchenko@gmail.com \
--cc=broonie@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=fido_max@inbox.ru \
--cc=krzk+dt@kernel.org \
--cc=lgirdwood@gmail.com \
--cc=linux-sound@vger.kernel.org \
--cc=perex@perex.cz \
--cc=robh@kernel.org \
--cc=tiwai@suse.com \
--cc=u.kleine-koenig@baylibre.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).