From: Yury Norov <ynorov@nvidia.com>
To: Stephen Boyd <sboyd@kernel.org>,
Brian Masney <bmasney+clk@redhat.com>,
Jerome Brunet <jbrunet+clk@baylibre.com>,
linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Yury Norov <ynorov@nvidia.com>, Yury Norov <yury.norov@gmail.com>
Subject: [PATCH] clk: si521xx: simplify si521xx_diff_idx_to_reg_bit()
Date: Fri, 25 Sep 2026 15:38:58 -0400 [thread overview]
Message-ID: <20260925193858.250215-1-ynorov@nvidia.com> (raw)
Switch the function to using fns(), and get rid of the double for-loop.
Signed-off-by: Yury Norov <ynorov@nvidia.com>
---
drivers/clk/clk-si521xx.c | 31 +++++++++++++++++++------------
1 file changed, 19 insertions(+), 12 deletions(-)
diff --git a/drivers/clk/clk-si521xx.c b/drivers/clk/clk-si521xx.c
index e3fb8df712ef..186fb0916066 100644
--- a/drivers/clk/clk-si521xx.c
+++ b/drivers/clk/clk-si521xx.c
@@ -13,6 +13,7 @@
*/
#include <linux/bitfield.h>
+#include <linux/bitops.h>
#include <linux/bitrev.h>
#include <linux/clk-provider.h>
#include <linux/i2c.h>
@@ -255,18 +256,24 @@ static void si521xx_diff_idx_to_reg_bit(const u16 chip_info, const int idx,
struct si_clk *clk)
{
unsigned long mask;
- int oe, b, ctr = 0;
-
- for (oe = 1; oe <= 2; oe++) {
- mask = bitrev8(SI521XX_OE_MAP_GET_OE(oe, chip_info));
- for_each_set_bit(b, &mask, 8) {
- if (ctr++ != idx)
- continue;
- clk->reg = SI521XX_REG_OE(oe);
- clk->bit = 7 - b;
- return;
- }
- }
+ unsigned int bit;
+ int oe = 1;
+
+ mask = bitrev8(SI521XX_OE_MAP_GET_OE(1, chip_info));
+ bit = fns(mask, idx);
+ if (bit < 8)
+ goto out;
+
+ oe = 2;
+ bit = idx - hweight8(mask);
+ mask = bitrev8(SI521XX_OE_MAP_GET_OE(2, chip_info));
+ bit = fns(mask, bit);
+ if (bit >= 8)
+ return;
+
+out:
+ clk->reg = SI521XX_REG_OE(oe);
+ clk->bit = 7 - bit;
}
static struct clk_hw *
--
2.53.0
reply other threads:[~2026-09-25 19:39 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260925193858.250215-1-ynorov@nvidia.com \
--to=ynorov@nvidia.com \
--cc=bmasney+clk@redhat.com \
--cc=jbrunet+clk@baylibre.com \
--cc=linux-clk@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=sboyd@kernel.org \
--cc=yury.norov@gmail.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
all inboxes | Powered by JetHome®