2828 * parent - fixed parent. No clk_set_parent support
2929 */
3030
31- #define div_mask (width ) ((1 << (width)) - 1)
32-
3331static unsigned int _get_table_maxdiv (const struct clk_div_table * table ,
3432 u8 width )
3533{
36- unsigned int maxdiv = 0 , mask = div_mask (width );
34+ unsigned int maxdiv = 0 , mask = clk_div_mask (width );
3735 const struct clk_div_table * clkt ;
3836
3937 for (clkt = table ; clkt -> div ; clkt ++ )
@@ -57,12 +55,12 @@ static unsigned int _get_maxdiv(const struct clk_div_table *table, u8 width,
5755 unsigned long flags )
5856{
5957 if (flags & CLK_DIVIDER_ONE_BASED )
60- return div_mask (width );
58+ return clk_div_mask (width );
6159 if (flags & CLK_DIVIDER_POWER_OF_TWO )
62- return 1 << div_mask (width );
60+ return 1 << clk_div_mask (width );
6361 if (table )
6462 return _get_table_maxdiv (table , width );
65- return div_mask (width ) + 1 ;
63+ return clk_div_mask (width ) + 1 ;
6664}
6765
6866static unsigned int _get_table_div (const struct clk_div_table * table ,
@@ -84,7 +82,7 @@ static unsigned int _get_div(const struct clk_div_table *table,
8482 if (flags & CLK_DIVIDER_POWER_OF_TWO )
8583 return 1 << val ;
8684 if (flags & CLK_DIVIDER_MAX_AT_ZERO )
87- return val ? val : div_mask (width ) + 1 ;
85+ return val ? val : clk_div_mask (width ) + 1 ;
8886 if (table )
8987 return _get_table_div (table , val );
9088 return val + 1 ;
@@ -109,7 +107,7 @@ static unsigned int _get_val(const struct clk_div_table *table,
109107 if (flags & CLK_DIVIDER_POWER_OF_TWO )
110108 return __ffs (div );
111109 if (flags & CLK_DIVIDER_MAX_AT_ZERO )
112- return (div == div_mask (width ) + 1 ) ? 0 : div ;
110+ return (div == clk_div_mask (width ) + 1 ) ? 0 : div ;
113111 if (table )
114112 return _get_table_val (table , div );
115113 return div - 1 ;
@@ -141,7 +139,7 @@ static unsigned long clk_divider_recalc_rate(struct clk_hw *hw,
141139 unsigned int val ;
142140
143141 val = clk_readl (divider -> reg ) >> divider -> shift ;
144- val &= div_mask (divider -> width );
142+ val &= clk_div_mask (divider -> width );
145143
146144 return divider_recalc_rate (hw , parent_rate , val , divider -> table ,
147145 divider -> flags , divider -> width );
@@ -344,19 +342,43 @@ long divider_round_rate_parent(struct clk_hw *hw, struct clk_hw *parent,
344342}
345343EXPORT_SYMBOL_GPL (divider_round_rate_parent );
346344
345+ long divider_ro_round_rate_parent (struct clk_hw * hw , struct clk_hw * parent ,
346+ unsigned long rate , unsigned long * prate ,
347+ const struct clk_div_table * table , u8 width ,
348+ unsigned long flags , unsigned int val )
349+ {
350+ int div ;
351+
352+ div = _get_div (table , val , flags , width );
353+
354+ /* Even a read-only clock can propagate a rate change */
355+ if (clk_hw_get_flags (hw ) & CLK_SET_RATE_PARENT ) {
356+ if (!parent )
357+ return - EINVAL ;
358+
359+ * prate = clk_hw_round_rate (parent , rate * div );
360+ }
361+
362+ return DIV_ROUND_UP_ULL ((u64 )* prate , div );
363+ }
364+ EXPORT_SYMBOL_GPL (divider_ro_round_rate_parent );
365+
366+
347367static long clk_divider_round_rate (struct clk_hw * hw , unsigned long rate ,
348368 unsigned long * prate )
349369{
350370 struct clk_divider * divider = to_clk_divider (hw );
351- int bestdiv ;
352371
353372 /* if read only, just return current value */
354373 if (divider -> flags & CLK_DIVIDER_READ_ONLY ) {
355- bestdiv = clk_readl (divider -> reg ) >> divider -> shift ;
356- bestdiv &= div_mask (divider -> width );
357- bestdiv = _get_div (divider -> table , bestdiv , divider -> flags ,
358- divider -> width );
359- return DIV_ROUND_UP_ULL ((u64 )* prate , bestdiv );
374+ u32 val ;
375+
376+ val = clk_readl (divider -> reg ) >> divider -> shift ;
377+ val &= clk_div_mask (divider -> width );
378+
379+ return divider_ro_round_rate (hw , rate , prate , divider -> table ,
380+ divider -> width , divider -> flags ,
381+ val );
360382 }
361383
362384 return divider_round_rate (hw , rate , prate , divider -> table ,
@@ -376,7 +398,7 @@ int divider_get_val(unsigned long rate, unsigned long parent_rate,
376398
377399 value = _get_val (table , div , flags , width );
378400
379- return min_t (unsigned int , value , div_mask (width ));
401+ return min_t (unsigned int , value , clk_div_mask (width ));
380402}
381403EXPORT_SYMBOL_GPL (divider_get_val );
382404
@@ -399,10 +421,10 @@ static int clk_divider_set_rate(struct clk_hw *hw, unsigned long rate,
399421 __acquire (divider -> lock );
400422
401423 if (divider -> flags & CLK_DIVIDER_HIWORD_MASK ) {
402- val = div_mask (divider -> width ) << (divider -> shift + 16 );
424+ val = clk_div_mask (divider -> width ) << (divider -> shift + 16 );
403425 } else {
404426 val = clk_readl (divider -> reg );
405- val &= ~(div_mask (divider -> width ) << divider -> shift );
427+ val &= ~(clk_div_mask (divider -> width ) << divider -> shift );
406428 }
407429 val |= (u32 )value << divider -> shift ;
408430 clk_writel (val , divider -> reg );
0 commit comments