3131
3232struct private_data {
3333 struct device * cpu_dev ;
34- struct regulator * cpu_reg ;
3534 struct thermal_cooling_device * cdev ;
3635 const char * reg_name ;
3736};
@@ -88,91 +87,83 @@ static const char *find_supply_name(struct device *dev)
8887 return name ;
8988}
9089
91- static int allocate_resources (int cpu , struct device * * cdev ,
92- struct regulator * * creg , struct clk * * cclk )
90+ static int resources_available (void )
9391{
9492 struct device * cpu_dev ;
9593 struct regulator * cpu_reg ;
9694 struct clk * cpu_clk ;
9795 int ret = 0 ;
98- char * reg_cpu0 = "cpu0" , * reg_cpu = "cpu" , * reg ;
96+ const char * name ;
9997
100- cpu_dev = get_cpu_device (cpu );
98+ cpu_dev = get_cpu_device (0 );
10199 if (!cpu_dev ) {
102- pr_err ("failed to get cpu%d device\n" , cpu );
100+ pr_err ("failed to get cpu0 device\n" );
103101 return - ENODEV ;
104102 }
105103
106- /* Try "cpu0" for older DTs */
107- if (!cpu )
108- reg = reg_cpu0 ;
109- else
110- reg = reg_cpu ;
111-
112- try_again :
113- cpu_reg = regulator_get_optional (cpu_dev , reg );
114- ret = PTR_ERR_OR_ZERO (cpu_reg );
104+ cpu_clk = clk_get (cpu_dev , NULL );
105+ ret = PTR_ERR_OR_ZERO (cpu_clk );
115106 if (ret ) {
116107 /*
117- * If cpu's regulator supply node is present, but regulator is
118- * not yet registered, we should try defering probe.
108+ * If cpu's clk node is present, but clock is not yet
109+ * registered, we should try defering probe.
119110 */
120- if (ret == - EPROBE_DEFER ) {
121- dev_dbg (cpu_dev , "cpu%d regulator not ready, retry\n" ,
122- cpu );
123- return ret ;
124- }
125-
126- /* Try with "cpu-supply" */
127- if (reg == reg_cpu0 ) {
128- reg = reg_cpu ;
129- goto try_again ;
130- }
111+ if (ret == - EPROBE_DEFER )
112+ dev_dbg (cpu_dev , "clock not ready, retry\n" );
113+ else
114+ dev_err (cpu_dev , "failed to get clock: %d\n" , ret );
131115
132- dev_dbg ( cpu_dev , "no regulator for cpu%d: %d\n" , cpu , ret ) ;
116+ return ret ;
133117 }
134118
135- cpu_clk = clk_get ( cpu_dev , NULL );
136- ret = PTR_ERR_OR_ZERO ( cpu_clk );
137- if ( ret ) {
138- /* put regulator */
139- if (!IS_ERR ( cpu_reg ) )
140- regulator_put ( cpu_reg ) ;
119+ clk_put ( cpu_clk );
120+
121+ name = find_supply_name ( cpu_dev );
122+ /* Platform doesn't require regulator */
123+ if (!name )
124+ return 0 ;
141125
126+ cpu_reg = regulator_get_optional (cpu_dev , name );
127+ ret = PTR_ERR_OR_ZERO (cpu_reg );
128+ if (ret ) {
142129 /*
143- * If cpu's clk node is present, but clock is not yet
144- * registered, we should try defering probe.
130+ * If cpu's regulator supply node is present, but regulator is
131+ * not yet registered, we should try defering probe.
145132 */
146133 if (ret == - EPROBE_DEFER )
147- dev_dbg (cpu_dev , "cpu%d clock not ready, retry\n" , cpu );
134+ dev_dbg (cpu_dev , "cpu0 regulator not ready, retry\n" );
148135 else
149- dev_err (cpu_dev , "failed to get cpu%d clock: %d\n" , cpu ,
150- ret );
151- } else {
152- * cdev = cpu_dev ;
153- * creg = cpu_reg ;
154- * cclk = cpu_clk ;
136+ dev_dbg (cpu_dev , "no regulator for cpu0: %d\n" , ret );
137+
138+ return ret ;
155139 }
156140
157- return ret ;
141+ regulator_put (cpu_reg );
142+ return 0 ;
158143}
159144
160145static int cpufreq_init (struct cpufreq_policy * policy )
161146{
162147 struct cpufreq_frequency_table * freq_table ;
163148 struct private_data * priv ;
164149 struct device * cpu_dev ;
165- struct regulator * cpu_reg ;
166150 struct clk * cpu_clk ;
167151 struct dev_pm_opp * suspend_opp ;
168152 unsigned int transition_latency ;
169153 bool opp_v1 = false;
170154 const char * name ;
171155 int ret ;
172156
173- ret = allocate_resources (policy -> cpu , & cpu_dev , & cpu_reg , & cpu_clk );
174- if (ret ) {
175- pr_err ("%s: Failed to allocate resources: %d\n" , __func__ , ret );
157+ cpu_dev = get_cpu_device (policy -> cpu );
158+ if (!cpu_dev ) {
159+ pr_err ("failed to get cpu%d device\n" , policy -> cpu );
160+ return - ENODEV ;
161+ }
162+
163+ cpu_clk = clk_get (cpu_dev , NULL );
164+ if (IS_ERR (cpu_clk )) {
165+ ret = PTR_ERR (cpu_clk );
166+ dev_err (cpu_dev , "%s: failed to get clk: %d\n" , __func__ , ret );
176167 return ret ;
177168 }
178169
@@ -186,7 +177,7 @@ static int cpufreq_init(struct cpufreq_policy *policy)
186177 if (ret == - ENOENT )
187178 opp_v1 = true;
188179 else
189- goto out_put_reg_clk ;
180+ goto out_put_clk ;
190181 }
191182
192183 /*
@@ -199,7 +190,7 @@ static int cpufreq_init(struct cpufreq_policy *policy)
199190 if (ret ) {
200191 dev_err (cpu_dev , "Failed to set regulator for cpu%d: %d\n" ,
201192 policy -> cpu , ret );
202- goto out_put_reg_clk ;
193+ goto out_put_clk ;
203194 }
204195 }
205196
@@ -257,9 +248,7 @@ static int cpufreq_init(struct cpufreq_policy *policy)
257248 }
258249
259250 priv -> cpu_dev = cpu_dev ;
260- priv -> cpu_reg = cpu_reg ;
261251 policy -> driver_data = priv ;
262-
263252 policy -> clk = cpu_clk ;
264253
265254 rcu_read_lock ();
@@ -300,10 +289,8 @@ static int cpufreq_init(struct cpufreq_policy *policy)
300289 dev_pm_opp_of_cpumask_remove_table (policy -> cpus );
301290 if (name )
302291 dev_pm_opp_put_regulator (cpu_dev );
303- out_put_reg_clk :
292+ out_put_clk :
304293 clk_put (cpu_clk );
305- if (!IS_ERR (cpu_reg ))
306- regulator_put (cpu_reg );
307294
308295 return ret ;
309296}
@@ -319,8 +306,6 @@ static int cpufreq_exit(struct cpufreq_policy *policy)
319306 dev_pm_opp_put_regulator (priv -> cpu_dev );
320307
321308 clk_put (policy -> clk );
322- if (!IS_ERR (priv -> cpu_reg ))
323- regulator_put (priv -> cpu_reg );
324309 kfree (priv );
325310
326311 return 0 ;
@@ -373,9 +358,6 @@ static struct cpufreq_driver dt_cpufreq_driver = {
373358
374359static int dt_cpufreq_probe (struct platform_device * pdev )
375360{
376- struct device * cpu_dev ;
377- struct regulator * cpu_reg ;
378- struct clk * cpu_clk ;
379361 int ret ;
380362
381363 /*
@@ -385,19 +367,15 @@ static int dt_cpufreq_probe(struct platform_device *pdev)
385367 *
386368 * FIXME: Is checking this only for CPU0 sufficient ?
387369 */
388- ret = allocate_resources ( 0 , & cpu_dev , & cpu_reg , & cpu_clk );
370+ ret = resources_available ( );
389371 if (ret )
390372 return ret ;
391373
392- clk_put (cpu_clk );
393- if (!IS_ERR (cpu_reg ))
394- regulator_put (cpu_reg );
395-
396374 dt_cpufreq_driver .driver_data = dev_get_platdata (& pdev -> dev );
397375
398376 ret = cpufreq_register_driver (& dt_cpufreq_driver );
399377 if (ret )
400- dev_err (cpu_dev , "failed register driver: %d\n" , ret );
378+ dev_err (& pdev -> dev , "failed register driver: %d\n" , ret );
401379
402380 return ret ;
403381}
0 commit comments