28
28
* @hw: handle between common and hardware-specific interfaces
29
29
* @reg: IO-remapped register
30
30
* @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
33
32
* @nb: Notifier block to save/restore clock state for system resume
34
33
* @parents: Array to map from valid parent clocks indices to hardware indices
35
34
*/
36
35
struct div6_clock {
37
36
struct clk_hw hw ;
38
37
void __iomem * reg ;
39
38
unsigned int div ;
40
- u32 src_shift ;
41
- u32 src_width ;
39
+ u32 src_mask ;
42
40
struct notifier_block nb ;
43
41
u8 parents [];
44
42
};
@@ -133,11 +131,11 @@ static u8 cpg_div6_clock_get_parent(struct clk_hw *hw)
133
131
unsigned int i ;
134
132
u8 hw_index ;
135
133
136
- if (clock -> src_width == 0 )
134
+ if (clock -> src_mask == 0 )
137
135
return 0 ;
138
136
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 );
141
139
for (i = 0 ; i < clk_hw_get_num_parents (hw ); i ++ ) {
142
140
if (clock -> parents [i ] == hw_index )
143
141
return i ;
@@ -151,18 +149,13 @@ static u8 cpg_div6_clock_get_parent(struct clk_hw *hw)
151
149
static int cpg_div6_clock_set_parent (struct clk_hw * hw , u8 index )
152
150
{
153
151
struct div6_clock * clock = to_div6_clock (hw );
154
- u8 hw_index ;
155
- u32 mask ;
152
+ u32 src ;
156
153
157
154
if (index >= clk_hw_get_num_parents (hw ))
158
155
return - EINVAL ;
159
156
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 );
166
159
return 0 ;
167
160
}
168
161
@@ -236,17 +229,15 @@ struct clk * __init cpg_div6_register(const char *name,
236
229
switch (num_parents ) {
237
230
case 1 :
238
231
/* fixed parent clock */
239
- clock -> src_shift = clock -> src_width = 0 ;
232
+ clock -> src_mask = 0 ;
240
233
break ;
241
234
case 4 :
242
235
/* clock with EXSRC bits 6-7 */
243
- clock -> src_shift = 6 ;
244
- clock -> src_width = 2 ;
236
+ clock -> src_mask = GENMASK (7 , 6 );
245
237
break ;
246
238
case 8 :
247
239
/* VCLK with EXSRC bits 12-14 */
248
- clock -> src_shift = 12 ;
249
- clock -> src_width = 3 ;
240
+ clock -> src_mask = GENMASK (14 , 12 );
250
241
break ;
251
242
default :
252
243
pr_err ("%s: invalid number of parents for DIV6 clock %s\n" ,
0 commit comments