Skip to contentSkip to conversation

clk: si521xx: simplify si521xx_diff_idx_to_reg_bit()

PATCH Applied Yury Norov 2 participants 2 messages Sep 25 – Sep 29 Common clk

lore
Share & tools
lore

Yury Norov

author
#0 lore raw

PATCH 1/1 clk: si521xx: simplify si521xx_diff_idx_to_reg_bit()

Switch the function to using fns(), and get rid of the double for-loop.

---
 drivers/clk/clk-si521xx.c | 31 +++++++++++++++++++------------
 1 file changed, 19 insertions(+), 12 deletions(-)
drivers/clk/clk-si521xx.c +19 -12
index e3fb8df712ef..186fb0916066 100644
@@ -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 *
Signature · 1 line
2.53.0
Applied
#1 lore raw
Quoted 1 line · Yury Norov

clk: si521xx: simplify si521xx_diff_idx_to_reg_bit()

Applied, thanks!

[1/1] clk: si521xx: simplify si521xx_diff_idx_to_reg_bit()

      commit: f619355a6bc6e2ce8b2b104abfd4f2c86e22aad3

Best regards,

Signature · 1 line
Brian Masney <[email protected]>