@@ -43,26 +43,26 @@ static DEFINE_MUTEX(clock_list_sem);
4343 */
4444static struct clk master_clk = {
4545 .name = "master_clk" ,
46- .flags = CLK_ALWAYS_ENABLED ,
46+ .flags = CLK_ENABLE_ON_INIT ,
4747 .rate = CONFIG_SH_PCLK_FREQ ,
4848};
4949
5050static struct clk module_clk = {
5151 .name = "module_clk" ,
5252 .parent = & master_clk ,
53- .flags = CLK_ALWAYS_ENABLED ,
53+ .flags = CLK_ENABLE_ON_INIT ,
5454};
5555
5656static struct clk bus_clk = {
5757 .name = "bus_clk" ,
5858 .parent = & master_clk ,
59- .flags = CLK_ALWAYS_ENABLED ,
59+ .flags = CLK_ENABLE_ON_INIT ,
6060};
6161
6262static struct clk cpu_clk = {
6363 .name = "cpu_clk" ,
6464 .parent = & master_clk ,
65- .flags = CLK_ALWAYS_ENABLED ,
65+ .flags = CLK_ENABLE_ON_INIT ,
6666};
6767
6868/*
@@ -93,39 +93,11 @@ void propagate_rate(struct clk *tclk)
9393 }
9494}
9595
96- static void __clk_init (struct clk * clk )
97- {
98- /*
99- * See if this is the first time we're enabling the clock, some
100- * clocks that are always enabled still require "special"
101- * initialization. This is especially true if the clock mode
102- * changes and the clock needs to hunt for the proper set of
103- * divisors to use before it can effectively recalc.
104- */
105-
106- if (clk -> flags & CLK_NEEDS_INIT ) {
107- if (clk -> ops && clk -> ops -> init )
108- clk -> ops -> init (clk );
109-
110- clk -> flags &= ~CLK_NEEDS_INIT ;
111- }
112- }
113-
11496static int __clk_enable (struct clk * clk )
11597{
116- if (!clk )
117- return - EINVAL ;
118-
119- clk -> usecount ++ ;
120-
121- /* nothing to do if always enabled */
122- if (clk -> flags & CLK_ALWAYS_ENABLED )
123- return 0 ;
124-
125- if (clk -> usecount == 1 ) {
126- __clk_init (clk );
127-
128- __clk_enable (clk -> parent );
98+ if (clk -> usecount ++ == 0 ) {
99+ if (clk -> parent )
100+ __clk_enable (clk -> parent );
129101
130102 if (clk -> ops && clk -> ops -> enable )
131103 clk -> ops -> enable (clk );
@@ -139,6 +111,9 @@ int clk_enable(struct clk *clk)
139111 unsigned long flags ;
140112 int ret ;
141113
114+ if (!clk )
115+ return - EINVAL ;
116+
142117 spin_lock_irqsave (& clock_lock , flags );
143118 ret = __clk_enable (clk );
144119 spin_unlock_irqrestore (& clock_lock , flags );
@@ -149,28 +124,21 @@ EXPORT_SYMBOL_GPL(clk_enable);
149124
150125static void __clk_disable (struct clk * clk )
151126{
152- if (!clk )
153- return ;
154-
155- clk -> usecount -- ;
156-
157- WARN_ON (clk -> usecount < 0 );
158-
159- if (clk -> flags & CLK_ALWAYS_ENABLED )
160- return ;
161-
162- if (clk -> usecount == 0 ) {
127+ if (clk -> usecount > 0 && !(-- clk -> usecount )) {
163128 if (likely (clk -> ops && clk -> ops -> disable ))
164129 clk -> ops -> disable (clk );
165-
166- __clk_disable (clk -> parent );
130+ if ( likely ( clk -> parent ))
131+ __clk_disable (clk -> parent );
167132 }
168133}
169134
170135void clk_disable (struct clk * clk )
171136{
172137 unsigned long flags ;
173138
139+ if (!clk )
140+ return ;
141+
174142 spin_lock_irqsave (& clock_lock , flags );
175143 __clk_disable (clk );
176144 spin_unlock_irqrestore (& clock_lock , flags );
@@ -211,26 +179,18 @@ int clk_register(struct clk *clk)
211179 mutex_lock (& clock_list_sem );
212180
213181 INIT_LIST_HEAD (& clk -> children );
182+ clk -> usecount = 0 ;
214183
215184 if (clk -> parent )
216185 list_add (& clk -> sibling , & clk -> parent -> children );
217186 else
218187 list_add (& clk -> sibling , & root_clks );
219188
220189 list_add (& clk -> node , & clock_list );
221- clk -> usecount = 0 ;
222- clk -> flags |= CLK_NEEDS_INIT ;
223-
190+ if (clk -> ops -> init )
191+ clk -> ops -> init (clk );
224192 mutex_unlock (& clock_list_sem );
225193
226- if (clk -> flags & CLK_ALWAYS_ENABLED ) {
227- __clk_init (clk );
228- pr_debug ( "Clock '%s' is ALWAYS_ENABLED\n" , clk -> name );
229- if (clk -> ops && clk -> ops -> enable )
230- clk -> ops -> enable (clk );
231- pr_debug ( "Enabled." );
232- }
233-
234194 return 0 ;
235195}
236196EXPORT_SYMBOL_GPL (clk_register );
@@ -244,6 +204,15 @@ void clk_unregister(struct clk *clk)
244204}
245205EXPORT_SYMBOL_GPL (clk_unregister );
246206
207+ static void clk_enable_init_clocks (void )
208+ {
209+ struct clk * clkp ;
210+
211+ list_for_each_entry (clkp , & clock_list , node )
212+ if (clkp -> flags & CLK_ENABLE_ON_INIT )
213+ clk_enable (clkp );
214+ }
215+
247216unsigned long clk_get_rate (struct clk * clk )
248217{
249218 return clk -> rate ;
@@ -404,9 +373,7 @@ static int show_clocks(char *buf, char **start, off_t off,
404373
405374 p += sprintf (p , "%-12s\t: %ld.%02ldMHz\t%s\n" , clk -> name ,
406375 rate / 1000000 , (rate % 1000000 ) / 10000 ,
407- ((clk -> flags & CLK_ALWAYS_ENABLED ) ||
408- clk -> usecount > 0 ) ?
409- "enabled" : "disabled" );
376+ (clk -> usecount > 0 ) ? "enabled" : "disabled" );
410377 }
411378
412379 return p - buf ;
@@ -496,6 +463,9 @@ int __init clk_init(void)
496463 /* Kick the child clocks.. */
497464 recalculate_root_clocks ();
498465
466+ /* Enable the necessary init clocks */
467+ clk_enable_init_clocks ();
468+
499469 return ret ;
500470}
501471
0 commit comments