blob: da8c3a9f20edcbbdf266fc288b23f0f5b3647102 [file] [log] [blame]
Brian Swetland600f7cf2008-09-09 11:04:14 -07001/* arch/arm/mach-msm/clock.c
2 *
3 * Copyright (C) 2007 Google, Inc.
Tianyi Gou7949ecb2012-02-14 14:25:32 -08004 * Copyright (c) 2007-2012, Code Aurora Forum. All rights reserved.
Brian Swetland600f7cf2008-09-09 11:04:14 -07005 *
6 * This software is licensed under the terms of the GNU General Public
7 * License version 2, as published by the Free Software Foundation, and
8 * may be copied, distributed, and modified under those terms.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 */
16
Brian Swetland600f7cf2008-09-09 11:04:14 -070017#include <linux/kernel.h>
Brian Swetland600f7cf2008-09-09 11:04:14 -070018#include <linux/err.h>
Brian Swetland600f7cf2008-09-09 11:04:14 -070019#include <linux/spinlock.h>
Stephen Boydbd323442011-02-23 09:37:42 -080020#include <linux/string.h>
21#include <linux/module.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070022#include <linux/clk.h>
Stephen Boydbd323442011-02-23 09:37:42 -080023#include <linux/clkdev.h>
Matt Wagantall158f73b2012-05-16 11:29:35 -070024#include <linux/list.h>
Stephen Boyd5bc44d52012-03-29 11:00:57 -070025#include <trace/events/power.h>
Brian Swetland600f7cf2008-09-09 11:04:14 -070026
27#include "clock.h"
Brian Swetland600f7cf2008-09-09 11:04:14 -070028
Matt Wagantall158f73b2012-05-16 11:29:35 -070029struct handoff_clk {
30 struct list_head list;
31 struct clk *clk;
32};
33static LIST_HEAD(handoff_list);
34
Matt Wagantalle18bbc82011-10-06 10:07:28 -070035/* Find the voltage level required for a given rate. */
36static int find_vdd_level(struct clk *clk, unsigned long rate)
37{
38 int level;
39
40 for (level = 0; level < ARRAY_SIZE(clk->fmax); level++)
41 if (rate <= clk->fmax[level])
42 break;
43
44 if (level == ARRAY_SIZE(clk->fmax)) {
45 pr_err("Rate %lu for %s is greater than highest Fmax\n", rate,
46 clk->dbg_name);
47 return -EINVAL;
48 }
49
50 return level;
51}
52
53/* Update voltage level given the current votes. */
54static int update_vdd(struct clk_vdd_class *vdd_class)
55{
56 int level, rc;
57
58 for (level = ARRAY_SIZE(vdd_class->level_votes)-1; level > 0; level--)
59 if (vdd_class->level_votes[level])
60 break;
61
62 if (level == vdd_class->cur_level)
63 return 0;
64
65 rc = vdd_class->set_vdd(vdd_class, level);
66 if (!rc)
67 vdd_class->cur_level = level;
68
69 return rc;
70}
71
72/* Vote for a voltage level. */
73int vote_vdd_level(struct clk_vdd_class *vdd_class, int level)
74{
75 unsigned long flags;
76 int rc;
77
78 spin_lock_irqsave(&vdd_class->lock, flags);
79 vdd_class->level_votes[level]++;
80 rc = update_vdd(vdd_class);
81 if (rc)
82 vdd_class->level_votes[level]--;
83 spin_unlock_irqrestore(&vdd_class->lock, flags);
84
85 return rc;
86}
87
88/* Remove vote for a voltage level. */
89int unvote_vdd_level(struct clk_vdd_class *vdd_class, int level)
90{
91 unsigned long flags;
92 int rc = 0;
93
94 spin_lock_irqsave(&vdd_class->lock, flags);
95 if (WARN(!vdd_class->level_votes[level],
96 "Reference counts are incorrect for %s level %d\n",
97 vdd_class->class_name, level))
98 goto out;
99 vdd_class->level_votes[level]--;
100 rc = update_vdd(vdd_class);
101 if (rc)
102 vdd_class->level_votes[level]++;
103out:
104 spin_unlock_irqrestore(&vdd_class->lock, flags);
105 return rc;
106}
107
108/* Vote for a voltage level corresponding to a clock's rate. */
109static int vote_rate_vdd(struct clk *clk, unsigned long rate)
110{
111 int level;
112
113 if (!clk->vdd_class)
114 return 0;
115
116 level = find_vdd_level(clk, rate);
117 if (level < 0)
118 return level;
119
120 return vote_vdd_level(clk->vdd_class, level);
121}
122
123/* Remove vote for a voltage level corresponding to a clock's rate. */
124static void unvote_rate_vdd(struct clk *clk, unsigned long rate)
125{
126 int level;
127
128 if (!clk->vdd_class)
129 return;
130
131 level = find_vdd_level(clk, rate);
132 if (level < 0)
133 return;
134
135 unvote_vdd_level(clk->vdd_class, level);
136}
137
Stephen Boyd3bbf3462012-01-12 00:19:23 -0800138int clk_prepare(struct clk *clk)
139{
140 int ret = 0;
141 struct clk *parent;
Vikram Mulukutla55e8f992012-04-17 19:25:10 -0700142
Stephen Boyd3bbf3462012-01-12 00:19:23 -0800143 if (!clk)
144 return 0;
Vikram Mulukutla55e8f992012-04-17 19:25:10 -0700145 if (IS_ERR(clk))
146 return -EINVAL;
Stephen Boyd3bbf3462012-01-12 00:19:23 -0800147
148 mutex_lock(&clk->prepare_lock);
149 if (clk->prepare_count == 0) {
150 parent = clk_get_parent(clk);
151
152 ret = clk_prepare(parent);
153 if (ret)
154 goto out;
155 ret = clk_prepare(clk->depends);
156 if (ret)
157 goto err_prepare_depends;
158
159 if (clk->ops->prepare)
160 ret = clk->ops->prepare(clk);
161 if (ret)
162 goto err_prepare_clock;
163 }
164 clk->prepare_count++;
165out:
166 mutex_unlock(&clk->prepare_lock);
167 return ret;
168err_prepare_clock:
169 clk_unprepare(clk->depends);
170err_prepare_depends:
171 clk_unprepare(parent);
172 goto out;
173}
174EXPORT_SYMBOL(clk_prepare);
175
Brian Swetland600f7cf2008-09-09 11:04:14 -0700176/*
Brian Swetland600f7cf2008-09-09 11:04:14 -0700177 * Standard clock functions defined in include/linux/clk.h
178 */
Brian Swetland600f7cf2008-09-09 11:04:14 -0700179int clk_enable(struct clk *clk)
180{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700181 int ret = 0;
Matt Wagantall7205eea2011-11-04 17:31:29 -0700182 unsigned long flags;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700183 struct clk *parent;
184
185 if (!clk)
186 return 0;
Vikram Mulukutla55e8f992012-04-17 19:25:10 -0700187 if (IS_ERR(clk))
188 return -EINVAL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700189
190 spin_lock_irqsave(&clk->lock, flags);
Stephen Boyd3bbf3462012-01-12 00:19:23 -0800191 if (WARN(!clk->warned && !clk->prepare_count,
192 "%s: Don't call enable on unprepared clocks\n",
193 clk->dbg_name))
194 clk->warned = true;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700195 if (clk->count == 0) {
196 parent = clk_get_parent(clk);
Matt Wagantalle18bbc82011-10-06 10:07:28 -0700197
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700198 ret = clk_enable(parent);
199 if (ret)
Matt Wagantalle18bbc82011-10-06 10:07:28 -0700200 goto err_enable_parent;
Stephen Boyd7fa26742011-08-11 23:22:29 -0700201 ret = clk_enable(clk->depends);
Matt Wagantalle18bbc82011-10-06 10:07:28 -0700202 if (ret)
203 goto err_enable_depends;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700204
Matt Wagantall7205eea2011-11-04 17:31:29 -0700205 ret = vote_rate_vdd(clk, clk->rate);
Matt Wagantalle18bbc82011-10-06 10:07:28 -0700206 if (ret)
207 goto err_vote_vdd;
Stephen Boyd5bc44d52012-03-29 11:00:57 -0700208 trace_clock_enable(clk->dbg_name, 1, smp_processor_id());
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700209 if (clk->ops->enable)
210 ret = clk->ops->enable(clk);
Matt Wagantalle18bbc82011-10-06 10:07:28 -0700211 if (ret)
212 goto err_enable_clock;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700213 }
Brian Swetland600f7cf2008-09-09 11:04:14 -0700214 clk->count++;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700215 spin_unlock_irqrestore(&clk->lock, flags);
216
Matt Wagantalle18bbc82011-10-06 10:07:28 -0700217 return 0;
218
219err_enable_clock:
Matt Wagantall7205eea2011-11-04 17:31:29 -0700220 unvote_rate_vdd(clk, clk->rate);
Matt Wagantalle18bbc82011-10-06 10:07:28 -0700221err_vote_vdd:
222 clk_disable(clk->depends);
223err_enable_depends:
224 clk_disable(parent);
225err_enable_parent:
226 spin_unlock_irqrestore(&clk->lock, flags);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700227 return ret;
Brian Swetland600f7cf2008-09-09 11:04:14 -0700228}
229EXPORT_SYMBOL(clk_enable);
230
231void clk_disable(struct clk *clk)
232{
233 unsigned long flags;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700234
Vikram Mulukutla55e8f992012-04-17 19:25:10 -0700235 if (IS_ERR_OR_NULL(clk))
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700236 return;
237
238 spin_lock_irqsave(&clk->lock, flags);
Stephen Boyd3bbf3462012-01-12 00:19:23 -0800239 if (WARN(!clk->warned && !clk->prepare_count,
240 "%s: Never called prepare or calling disable "
241 "after unprepare\n",
242 clk->dbg_name))
243 clk->warned = true;
Stephen Boydd906b522011-07-26 10:51:41 -0700244 if (WARN(clk->count == 0, "%s is unbalanced", clk->dbg_name))
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700245 goto out;
246 if (clk->count == 1) {
Matt Wagantalle18bbc82011-10-06 10:07:28 -0700247 struct clk *parent = clk_get_parent(clk);
Matt Wagantalle18bbc82011-10-06 10:07:28 -0700248
Stephen Boyd5bc44d52012-03-29 11:00:57 -0700249 trace_clock_disable(clk->dbg_name, 0, smp_processor_id());
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700250 if (clk->ops->disable)
251 clk->ops->disable(clk);
Matt Wagantall7205eea2011-11-04 17:31:29 -0700252 unvote_rate_vdd(clk, clk->rate);
Stephen Boyd7fa26742011-08-11 23:22:29 -0700253 clk_disable(clk->depends);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700254 clk_disable(parent);
255 }
Brian Swetland600f7cf2008-09-09 11:04:14 -0700256 clk->count--;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700257out:
258 spin_unlock_irqrestore(&clk->lock, flags);
Brian Swetland600f7cf2008-09-09 11:04:14 -0700259}
260EXPORT_SYMBOL(clk_disable);
261
Stephen Boyd3bbf3462012-01-12 00:19:23 -0800262void clk_unprepare(struct clk *clk)
263{
Vikram Mulukutla55e8f992012-04-17 19:25:10 -0700264 if (IS_ERR_OR_NULL(clk))
Stephen Boyd3bbf3462012-01-12 00:19:23 -0800265 return;
266
267 mutex_lock(&clk->prepare_lock);
268 if (!clk->prepare_count) {
269 if (WARN(!clk->warned, "%s is unbalanced (prepare)",
270 clk->dbg_name))
271 clk->warned = true;
272 goto out;
273 }
274 if (clk->prepare_count == 1) {
275 struct clk *parent = clk_get_parent(clk);
276
277 if (WARN(!clk->warned && clk->count,
278 "%s: Don't call unprepare when the clock is enabled\n",
279 clk->dbg_name))
280 clk->warned = true;
281
282 if (clk->ops->unprepare)
283 clk->ops->unprepare(clk);
284 clk_unprepare(clk->depends);
285 clk_unprepare(parent);
286 }
287 clk->prepare_count--;
288out:
289 mutex_unlock(&clk->prepare_lock);
290}
291EXPORT_SYMBOL(clk_unprepare);
292
Daniel Walker5e96da52010-05-12 13:43:28 -0700293int clk_reset(struct clk *clk, enum clk_reset_action action)
294{
Vikram Mulukutla55e8f992012-04-17 19:25:10 -0700295 if (IS_ERR_OR_NULL(clk))
296 return -EINVAL;
297
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700298 if (!clk->ops->reset)
299 return -ENOSYS;
300
301 return clk->ops->reset(clk, action);
Daniel Walker5e96da52010-05-12 13:43:28 -0700302}
303EXPORT_SYMBOL(clk_reset);
304
Brian Swetland600f7cf2008-09-09 11:04:14 -0700305unsigned long clk_get_rate(struct clk *clk)
306{
Vikram Mulukutla55e8f992012-04-17 19:25:10 -0700307 if (IS_ERR_OR_NULL(clk))
308 return 0;
309
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700310 if (!clk->ops->get_rate)
Tianyi Gou7949ecb2012-02-14 14:25:32 -0800311 return clk->rate;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700312
313 return clk->ops->get_rate(clk);
Brian Swetland600f7cf2008-09-09 11:04:14 -0700314}
315EXPORT_SYMBOL(clk_get_rate);
316
Matt Wagantall77952c42011-11-08 18:45:48 -0800317int clk_set_rate(struct clk *clk, unsigned long rate)
Brian Swetland600f7cf2008-09-09 11:04:14 -0700318{
Matt Wagantalle18bbc82011-10-06 10:07:28 -0700319 unsigned long start_rate, flags;
Stephen Boyd4fefefc2012-04-13 13:37:46 -0700320 int rc = 0;
Matt Wagantalle18bbc82011-10-06 10:07:28 -0700321
Vikram Mulukutla55e8f992012-04-17 19:25:10 -0700322 if (IS_ERR_OR_NULL(clk))
323 return -EINVAL;
324
Matt Wagantall77952c42011-11-08 18:45:48 -0800325 if (!clk->ops->set_rate)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700326 return -ENOSYS;
Daniel Walker3a790bb2010-12-13 14:35:10 -0800327
Matt Wagantalle18bbc82011-10-06 10:07:28 -0700328 spin_lock_irqsave(&clk->lock, flags);
Stephen Boyd4fefefc2012-04-13 13:37:46 -0700329
330 /* Return early if the rate isn't going to change */
331 if (clk->rate == rate)
332 goto out;
333
Stephen Boyd5bc44d52012-03-29 11:00:57 -0700334 trace_clock_set_rate(clk->dbg_name, rate, smp_processor_id());
Matt Wagantalle18bbc82011-10-06 10:07:28 -0700335 if (clk->count) {
Matt Wagantall7205eea2011-11-04 17:31:29 -0700336 start_rate = clk->rate;
Matt Wagantalle18bbc82011-10-06 10:07:28 -0700337 /* Enforce vdd requirements for target frequency. */
338 rc = vote_rate_vdd(clk, rate);
339 if (rc)
340 goto err_vote_vdd;
Matt Wagantall77952c42011-11-08 18:45:48 -0800341 rc = clk->ops->set_rate(clk, rate);
Matt Wagantalle18bbc82011-10-06 10:07:28 -0700342 if (rc)
343 goto err_set_rate;
344 /* Release vdd requirements for starting frequency. */
345 unvote_rate_vdd(clk, start_rate);
346 } else {
Matt Wagantall77952c42011-11-08 18:45:48 -0800347 rc = clk->ops->set_rate(clk, rate);
Matt Wagantalle18bbc82011-10-06 10:07:28 -0700348 }
Matt Wagantall7205eea2011-11-04 17:31:29 -0700349
350 if (!rc)
351 clk->rate = rate;
Stephen Boyd4fefefc2012-04-13 13:37:46 -0700352out:
Matt Wagantalle18bbc82011-10-06 10:07:28 -0700353 spin_unlock_irqrestore(&clk->lock, flags);
354 return rc;
355
356err_set_rate:
357 unvote_rate_vdd(clk, rate);
358err_vote_vdd:
359 spin_unlock_irqrestore(&clk->lock, flags);
360 return rc;
Brian Swetland600f7cf2008-09-09 11:04:14 -0700361}
Matt Wagantall77952c42011-11-08 18:45:48 -0800362EXPORT_SYMBOL(clk_set_rate);
Brian Swetland600f7cf2008-09-09 11:04:14 -0700363
Daniel Walker5e96da52010-05-12 13:43:28 -0700364long clk_round_rate(struct clk *clk, unsigned long rate)
365{
Vikram Mulukutla55e8f992012-04-17 19:25:10 -0700366 if (IS_ERR_OR_NULL(clk))
367 return -EINVAL;
368
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700369 if (!clk->ops->round_rate)
370 return -ENOSYS;
371
372 return clk->ops->round_rate(clk, rate);
Daniel Walker5e96da52010-05-12 13:43:28 -0700373}
374EXPORT_SYMBOL(clk_round_rate);
375
Daniel Walker5e96da52010-05-12 13:43:28 -0700376int clk_set_max_rate(struct clk *clk, unsigned long rate)
377{
Vikram Mulukutla55e8f992012-04-17 19:25:10 -0700378 if (IS_ERR_OR_NULL(clk))
379 return -EINVAL;
380
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700381 if (!clk->ops->set_max_rate)
382 return -ENOSYS;
383
384 return clk->ops->set_max_rate(clk, rate);
Daniel Walker5e96da52010-05-12 13:43:28 -0700385}
386EXPORT_SYMBOL(clk_set_max_rate);
387
Brian Swetland600f7cf2008-09-09 11:04:14 -0700388int clk_set_parent(struct clk *clk, struct clk *parent)
389{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700390 if (!clk->ops->set_parent)
391 return 0;
392
393 return clk->ops->set_parent(clk, parent);
Brian Swetland600f7cf2008-09-09 11:04:14 -0700394}
395EXPORT_SYMBOL(clk_set_parent);
396
397struct clk *clk_get_parent(struct clk *clk)
398{
Vikram Mulukutla55e8f992012-04-17 19:25:10 -0700399 if (IS_ERR_OR_NULL(clk))
400 return NULL;
401
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700402 if (!clk->ops->get_parent)
403 return NULL;
404
405 return clk->ops->get_parent(clk);
Brian Swetland600f7cf2008-09-09 11:04:14 -0700406}
407EXPORT_SYMBOL(clk_get_parent);
408
409int clk_set_flags(struct clk *clk, unsigned long flags)
410{
Vikram Mulukutla55e8f992012-04-17 19:25:10 -0700411 if (IS_ERR_OR_NULL(clk))
Brian Swetland600f7cf2008-09-09 11:04:14 -0700412 return -EINVAL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700413 if (!clk->ops->set_flags)
414 return -ENOSYS;
415
416 return clk->ops->set_flags(clk, flags);
Brian Swetland600f7cf2008-09-09 11:04:14 -0700417}
418EXPORT_SYMBOL(clk_set_flags);
419
Stephen Boydbb600ae2011-08-02 20:11:40 -0700420static struct clock_init_data __initdata *clk_init_data;
Brian Swetland600f7cf2008-09-09 11:04:14 -0700421
Matt Wagantallf30fceb2012-06-12 19:13:11 -0700422static enum handoff __init __handoff_clk(struct clk *clk)
423{
424 enum handoff ret;
425 struct handoff_clk *h;
Matt Wagantall2a59b212012-06-12 19:16:01 -0700426 unsigned long rate;
Matt Wagantallf30fceb2012-06-12 19:13:11 -0700427 int err = 0;
428
429 /*
430 * Tree roots don't have parents, but need to be handed off. So,
431 * terminate recursion by returning "enabled". Also return "enabled"
432 * for clocks with non-zero enable counts since they must have already
433 * been handed off.
434 */
435 if (clk == NULL || clk->count)
436 return HANDOFF_ENABLED_CLK;
437
438 /* Clocks without handoff functions are assumed to be disabled. */
439 if (!clk->ops->handoff || (clk->flags & CLKFLAG_SKIP_HANDOFF))
440 return HANDOFF_DISABLED_CLK;
441
442 /*
443 * Handoff functions for children must be called before their parents'
444 * so that the correct parent is returned by the clk_get_parent() below.
445 */
446 ret = clk->ops->handoff(clk);
447 if (ret == HANDOFF_ENABLED_CLK) {
448 ret = __handoff_clk(clk_get_parent(clk));
449 if (ret == HANDOFF_ENABLED_CLK) {
450 h = kmalloc(sizeof(*h), GFP_KERNEL);
451 if (!h) {
452 err = -ENOMEM;
453 goto out;
454 }
455 err = clk_prepare_enable(clk);
456 if (err)
457 goto out;
Matt Wagantall2a59b212012-06-12 19:16:01 -0700458 rate = clk_get_rate(clk);
459 if (rate)
460 pr_debug("%s rate=%lu\n", clk->dbg_name, rate);
Matt Wagantallf30fceb2012-06-12 19:13:11 -0700461 h->clk = clk;
462 list_add_tail(&h->list, &handoff_list);
463 }
464 }
465out:
466 if (err) {
467 pr_err("%s handoff failed (%d)\n", clk->dbg_name, err);
468 kfree(h);
469 ret = HANDOFF_DISABLED_CLK;
470 }
471 return ret;
472}
473
Stephen Boydbb600ae2011-08-02 20:11:40 -0700474void __init msm_clock_init(struct clock_init_data *data)
Brian Swetland600f7cf2008-09-09 11:04:14 -0700475{
476 unsigned n;
Stephen Boyd94625ef2011-07-12 17:06:01 -0700477 struct clk_lookup *clock_tbl;
478 size_t num_clocks;
Matt Wagantallb37fea42012-04-04 16:47:23 -0700479 struct clk *clk;
Stephen Boydbb600ae2011-08-02 20:11:40 -0700480
481 clk_init_data = data;
Matt Wagantallb64888f2012-04-02 21:35:07 -0700482 if (clk_init_data->pre_init)
483 clk_init_data->pre_init();
Brian Swetland600f7cf2008-09-09 11:04:14 -0700484
Stephen Boyd94625ef2011-07-12 17:06:01 -0700485 clock_tbl = data->table;
486 num_clocks = data->size;
487
Stephen Boydbd323442011-02-23 09:37:42 -0800488 for (n = 0; n < num_clocks; n++) {
Matt Wagantallb37fea42012-04-04 16:47:23 -0700489 struct clk *parent;
490 clk = clock_tbl[n].clk;
491 parent = clk_get_parent(clk);
Matt Wagantalle1482bf2012-04-04 16:23:45 -0700492 if (parent && list_empty(&clk->siblings))
493 list_add(&clk->siblings, &parent->children);
Matt Wagantallb37fea42012-04-04 16:47:23 -0700494 }
495
496 /*
497 * Detect and preserve initial clock state until clock_late_init() or
498 * a driver explicitly changes it, whichever is first.
499 */
Matt Wagantallf30fceb2012-06-12 19:13:11 -0700500 for (n = 0; n < num_clocks; n++)
501 __handoff_clk(clock_tbl[n].clk);
Daniel Walker5e96da52010-05-12 13:43:28 -0700502
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700503 clkdev_add_table(clock_tbl, num_clocks);
Matt Wagantallb64888f2012-04-02 21:35:07 -0700504
505 if (clk_init_data->post_init)
506 clk_init_data->post_init();
Brian Swetland600f7cf2008-09-09 11:04:14 -0700507}
508
Brian Swetland600f7cf2008-09-09 11:04:14 -0700509static int __init clock_late_init(void)
510{
Matt Wagantall158f73b2012-05-16 11:29:35 -0700511 struct handoff_clk *h, *h_temp;
Matt Wagantall647d1c12012-05-16 14:32:14 -0700512 int n, ret = 0;
Brian Swetland600f7cf2008-09-09 11:04:14 -0700513
Stephen Boydbb600ae2011-08-02 20:11:40 -0700514 clock_debug_init(clk_init_data);
Matt Wagantall647d1c12012-05-16 14:32:14 -0700515 for (n = 0; n < clk_init_data->size; n++)
516 clock_debug_add(clk_init_data->table[n].clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700517
Matt Wagantall647d1c12012-05-16 14:32:14 -0700518 pr_info("%s: Removing enables held for handed-off clocks\n", __func__);
Matt Wagantall158f73b2012-05-16 11:29:35 -0700519 list_for_each_entry_safe(h, h_temp, &handoff_list, list) {
520 clk_disable_unprepare(h->clk);
521 list_del(&h->list);
522 kfree(h);
523 }
524
Stephen Boydbb600ae2011-08-02 20:11:40 -0700525 if (clk_init_data->late_init)
526 ret = clk_init_data->late_init();
527 return ret;
Brian Swetland600f7cf2008-09-09 11:04:14 -0700528}
Brian Swetland600f7cf2008-09-09 11:04:14 -0700529late_initcall(clock_late_init);