Skip to content

Commit 23b04c8

Browse files
committed
clk: renesas: div6: Simplify src mask handling
Simplify the handling of the register bits to select the parent clock, by storing a bitmask instead of separate shift and width values. Signed-off-by: Geert Uytterhoeven <[email protected]> Link: https://lore.kernel.org/r/5f05a5110d222ce5a113e683fe2aa726f4100b73.1617281699.git.geert+renesas@glider.be
1 parent 6c7bc7d commit 23b04c8

File tree

1 file changed

+11
-20
lines changed

1 file changed

+11
-20
lines changed

drivers/clk/renesas/clk-div6.c

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,15 @@
2828
* @hw: handle between common and hardware-specific interfaces
2929
* @reg: IO-remapped register
3030
* @div: divisor value (1-64)
31-
* @src_shift: Shift to access the register bits to select the parent clock
32-
* @src_width: Number of register bits to select the parent clock (may be 0)
31+
* @src_mask: Bitmask covering the register bits to select the parent clock
3332
* @nb: Notifier block to save/restore clock state for system resume
3433
* @parents: Array to map from valid parent clocks indices to hardware indices
3534
*/
3635
struct div6_clock {
3736
struct clk_hw hw;
3837
void __iomem *reg;
3938
unsigned int div;
40-
u32 src_shift;
41-
u32 src_width;
39+
u32 src_mask;
4240
struct notifier_block nb;
4341
u8 parents[];
4442
};
@@ -133,11 +131,11 @@ static u8 cpg_div6_clock_get_parent(struct clk_hw *hw)
133131
unsigned int i;
134132
u8 hw_index;
135133

136-
if (clock->src_width == 0)
134+
if (clock->src_mask == 0)
137135
return 0;
138136

139-
hw_index = (readl(clock->reg) >> clock->src_shift) &
140-
(BIT(clock->src_width) - 1);
137+
hw_index = (readl(clock->reg) & clock->src_mask) >>
138+
__ffs(clock->src_mask);
141139
for (i = 0; i < clk_hw_get_num_parents(hw); i++) {
142140
if (clock->parents[i] == hw_index)
143141
return i;
@@ -151,18 +149,13 @@ static u8 cpg_div6_clock_get_parent(struct clk_hw *hw)
151149
static int cpg_div6_clock_set_parent(struct clk_hw *hw, u8 index)
152150
{
153151
struct div6_clock *clock = to_div6_clock(hw);
154-
u8 hw_index;
155-
u32 mask;
152+
u32 src;
156153

157154
if (index >= clk_hw_get_num_parents(hw))
158155
return -EINVAL;
159156

160-
mask = ~((BIT(clock->src_width) - 1) << clock->src_shift);
161-
hw_index = clock->parents[index];
162-
163-
writel((readl(clock->reg) & mask) | (hw_index << clock->src_shift),
164-
clock->reg);
165-
157+
src = clock->parents[index] << __ffs(clock->src_mask);
158+
writel((readl(clock->reg) & ~clock->src_mask) | src, clock->reg);
166159
return 0;
167160
}
168161

@@ -236,17 +229,15 @@ struct clk * __init cpg_div6_register(const char *name,
236229
switch (num_parents) {
237230
case 1:
238231
/* fixed parent clock */
239-
clock->src_shift = clock->src_width = 0;
232+
clock->src_mask = 0;
240233
break;
241234
case 4:
242235
/* clock with EXSRC bits 6-7 */
243-
clock->src_shift = 6;
244-
clock->src_width = 2;
236+
clock->src_mask = GENMASK(7, 6);
245237
break;
246238
case 8:
247239
/* VCLK with EXSRC bits 12-14 */
248-
clock->src_shift = 12;
249-
clock->src_width = 3;
240+
clock->src_mask = GENMASK(14, 12);
250241
break;
251242
default:
252243
pr_err("%s: invalid number of parents for DIV6 clock %s\n",

0 commit comments

Comments
 (0)