Skip to content

Commit 3937b05

Browse files
geertuYuryNorov
authored andcommitted
clk: renesas: Use bitfield helpers
Use the FIELD_{GET,PREP}() and field_{get,prep}() helpers for const respective non-const bitfields, instead of open-coding the same operations. Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be> Reviewed-by: Stephen Boyd <sboyd@kernel.org> Signed-off-by: Yury Norov (NVIDIA) <yury.norov@gmail.com>
1 parent b1cff2f commit 3937b05

3 files changed

Lines changed: 11 additions & 19 deletions

File tree

drivers/clk/renesas/clk-div6.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* Contact: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
88
*/
99

10+
#include <linux/bitfield.h>
1011
#include <linux/clk-provider.h>
1112
#include <linux/init.h>
1213
#include <linux/io.h>
@@ -171,8 +172,7 @@ static u8 cpg_div6_clock_get_parent(struct clk_hw *hw)
171172
if (clock->src_mask == 0)
172173
return 0;
173174

174-
hw_index = (readl(clock->reg) & clock->src_mask) >>
175-
__ffs(clock->src_mask);
175+
hw_index = field_get(clock->src_mask, readl(clock->reg));
176176
for (i = 0; i < clk_hw_get_num_parents(hw); i++) {
177177
if (clock->parents[i] == hw_index)
178178
return i;
@@ -191,7 +191,7 @@ static int cpg_div6_clock_set_parent(struct clk_hw *hw, u8 index)
191191
if (index >= clk_hw_get_num_parents(hw))
192192
return -EINVAL;
193193

194-
src = clock->parents[index] << __ffs(clock->src_mask);
194+
src = field_prep(clock->src_mask, clock->parents[index]);
195195
writel((readl(clock->reg) & ~clock->src_mask) | src, clock->reg);
196196
return 0;
197197
}

drivers/clk/renesas/rcar-gen3-cpg.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,8 @@ static unsigned long cpg_pll_clk_recalc_rate(struct clk_hw *hw,
5454
{
5555
struct cpg_pll_clk *pll_clk = to_pll_clk(hw);
5656
unsigned int mult;
57-
u32 val;
5857

59-
val = readl(pll_clk->pllcr_reg) & CPG_PLLnCR_STC_MASK;
60-
mult = (val >> __ffs(CPG_PLLnCR_STC_MASK)) + 1;
58+
mult = FIELD_GET(CPG_PLLnCR_STC_MASK, readl(pll_clk->pllcr_reg)) + 1;
6159

6260
return parent_rate * mult * pll_clk->fixed_mult;
6361
}
@@ -94,7 +92,7 @@ static int cpg_pll_clk_set_rate(struct clk_hw *hw, unsigned long rate,
9492

9593
val = readl(pll_clk->pllcr_reg);
9694
val &= ~CPG_PLLnCR_STC_MASK;
97-
val |= (mult - 1) << __ffs(CPG_PLLnCR_STC_MASK);
95+
val |= FIELD_PREP(CPG_PLLnCR_STC_MASK, mult - 1);
9896
writel(val, pll_clk->pllcr_reg);
9997

10098
for (i = 1000; i; i--) {
@@ -176,11 +174,7 @@ static unsigned long cpg_z_clk_recalc_rate(struct clk_hw *hw,
176174
unsigned long parent_rate)
177175
{
178176
struct cpg_z_clk *zclk = to_z_clk(hw);
179-
unsigned int mult;
180-
u32 val;
181-
182-
val = readl(zclk->reg) & zclk->mask;
183-
mult = 32 - (val >> __ffs(zclk->mask));
177+
unsigned int mult = 32 - field_get(zclk->mask, readl(zclk->reg));
184178

185179
return DIV_ROUND_CLOSEST_ULL((u64)parent_rate * mult,
186180
32 * zclk->fixed_div);
@@ -231,7 +225,8 @@ static int cpg_z_clk_set_rate(struct clk_hw *hw, unsigned long rate,
231225
if (readl(zclk->kick_reg) & CPG_FRQCRB_KICK)
232226
return -EBUSY;
233227

234-
cpg_reg_modify(zclk->reg, zclk->mask, (32 - mult) << __ffs(zclk->mask));
228+
cpg_reg_modify(zclk->reg, zclk->mask,
229+
field_prep(zclk->mask, 32 - mult));
235230

236231
/*
237232
* Set KICK bit in FRQCRB to update hardware setting and wait for

drivers/clk/renesas/rcar-gen4-cpg.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -279,11 +279,7 @@ static unsigned long cpg_z_clk_recalc_rate(struct clk_hw *hw,
279279
unsigned long parent_rate)
280280
{
281281
struct cpg_z_clk *zclk = to_z_clk(hw);
282-
unsigned int mult;
283-
u32 val;
284-
285-
val = readl(zclk->reg) & zclk->mask;
286-
mult = 32 - (val >> __ffs(zclk->mask));
282+
unsigned int mult = 32 - field_get(zclk->mask, readl(zclk->reg));
287283

288284
return DIV_ROUND_CLOSEST_ULL((u64)parent_rate * mult,
289285
32 * zclk->fixed_div);
@@ -334,7 +330,8 @@ static int cpg_z_clk_set_rate(struct clk_hw *hw, unsigned long rate,
334330
if (readl(zclk->kick_reg) & CPG_FRQCRB_KICK)
335331
return -EBUSY;
336332

337-
cpg_reg_modify(zclk->reg, zclk->mask, (32 - mult) << __ffs(zclk->mask));
333+
cpg_reg_modify(zclk->reg, zclk->mask,
334+
field_prep(zclk->mask, 32 - mult));
338335

339336
/*
340337
* Set KICK bit in FRQCRB to update hardware setting and wait for

0 commit comments

Comments
 (0)