linux-sound.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Charles Keepax <ckeepax@opensource.cirrus.com>
To: <broonie@kernel.org>
Cc: <andy.shevchenko@gmail.com>, <lgirdwood@gmail.com>,
	<alsa-devel@alsa-project.org>, <patches@opensource.cirrus.com>,
	<linux-sound@vger.kernel.org>
Subject: [PATCH v2 7/7] ASoC: cs42l43: Use fls to calculate the pre-divider for the PLL
Date: Thu, 25 Jan 2024 10:31:17 +0000	[thread overview]
Message-ID: <20240125103117.2622095-7-ckeepax@opensource.cirrus.com> (raw)
In-Reply-To: <20240125103117.2622095-1-ckeepax@opensource.cirrus.com>

Use fls to calculate the pre-divider and input frequency for the PLL,
this is marginally faster than the previous loop.

Suggested-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
---

Changes since v1:
 - Change / into >>

Thanks,
Charles

 sound/soc/codecs/cs42l43.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/sound/soc/codecs/cs42l43.c b/sound/soc/codecs/cs42l43.c
index 23e9557494afa..2c402086924d3 100644
--- a/sound/soc/codecs/cs42l43.c
+++ b/sound/soc/codecs/cs42l43.c
@@ -1338,10 +1338,9 @@ static int cs42l43_enable_pll(struct cs42l43_codec *priv)
 
 	dev_dbg(priv->dev, "Enabling PLL at %uHz\n", freq);
 
-	while (freq > cs42l43_pll_configs[ARRAY_SIZE(cs42l43_pll_configs) - 1].freq) {
-		div++;
-		freq /= 2;
-	}
+	div = fls(freq) -
+	      fls(cs42l43_pll_configs[ARRAY_SIZE(cs42l43_pll_configs) - 1].freq);
+	freq >>= div;
 
 	if (div <= CS42L43_PLL_REFCLK_DIV_MASK) {
 		int i;
-- 
2.30.2


  parent reply	other threads:[~2024-01-25 10:31 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-25 10:31 [PATCH v2 1/7] ASoC: cs42l43: Tidy up header includes Charles Keepax
2024-01-25 10:31 ` [PATCH v2 2/7] ASoC: cs42l43: Minor code tidy ups Charles Keepax
2024-01-25 10:31 ` [PATCH v2 3/7] ASoC: cs42l43: Check error from device_property_read_u32_array() Charles Keepax
2024-01-25 10:31 ` [PATCH v2 4/7] ASoC: cs42l43: Add pm_ptr around the power ops Charles Keepax
2024-01-25 19:00   ` Andy Shevchenko
2024-01-25 10:31 ` [PATCH v2 5/7] ASoC: cs42l43: Use USEC_PER_MSEC rather than hard coding Charles Keepax
2024-01-25 10:31 ` [PATCH v2 6/7] ASoC: cs42l43: Refactor to use for_each_set_bit() Charles Keepax
2024-01-25 19:11   ` Andy Shevchenko
2024-01-29 16:27     ` Charles Keepax
2024-01-29 23:45       ` Andy Shevchenko
2024-01-25 10:31 ` Charles Keepax [this message]
2024-01-25 19:13 ` [PATCH v2 1/7] ASoC: cs42l43: Tidy up header includes Andy Shevchenko
2024-01-26 21:38 ` 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=20240125103117.2622095-7-ckeepax@opensource.cirrus.com \
    --to=ckeepax@opensource.cirrus.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=andy.shevchenko@gmail.com \
    --cc=broonie@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-sound@vger.kernel.org \
    --cc=patches@opensource.cirrus.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).