blob: a0367b086f41fb15489bba06b3fe38aeca11cccf [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. */
Patrick Daly0a78a0e2012-07-23 13:18:59 -070036int find_vdd_level(struct clk *clk, unsigned long rate)
Matt Wagantalle18bbc82011-10-06 10:07:28 -070037{
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
Stephen Boyd2c2875f2012-01-24 17:36:34 -0800159 ret = vote_rate_vdd(clk, clk->rate);
160 if (ret)
161 goto err_vote_vdd;
Stephen Boyd3bbf3462012-01-12 00:19:23 -0800162 if (clk->ops->prepare)
163 ret = clk->ops->prepare(clk);
164 if (ret)
165 goto err_prepare_clock;
166 }
167 clk->prepare_count++;
168out:
169 mutex_unlock(&clk->prepare_lock);
170 return ret;
171err_prepare_clock:
Stephen Boyd2c2875f2012-01-24 17:36:34 -0800172 unvote_rate_vdd(clk, clk->rate);
173err_vote_vdd:
Stephen Boyd3bbf3462012-01-12 00:19:23 -0800174 clk_unprepare(clk->depends);
175err_prepare_depends:
176 clk_unprepare(parent);
177 goto out;
178}
179EXPORT_SYMBOL(clk_prepare);
180
Brian Swetland600f7cf2008-09-09 11:04:14 -0700181/*
Brian Swetland600f7cf2008-09-09 11:04:14 -0700182 * Standard clock functions defined in include/linux/clk.h
183 */
Brian Swetland600f7cf2008-09-09 11:04:14 -0700184int clk_enable(struct clk *clk)
185{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700186 int ret = 0;
Matt Wagantall7205eea2011-11-04 17:31:29 -0700187 unsigned long flags;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700188 struct clk *parent;
189
190 if (!clk)
191 return 0;
Vikram Mulukutla55e8f992012-04-17 19:25:10 -0700192 if (IS_ERR(clk))
193 return -EINVAL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700194
195 spin_lock_irqsave(&clk->lock, flags);
Stephen Boyd3bbf3462012-01-12 00:19:23 -0800196 if (WARN(!clk->warned && !clk->prepare_count,
197 "%s: Don't call enable on unprepared clocks\n",
198 clk->dbg_name))
199 clk->warned = true;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700200 if (clk->count == 0) {
201 parent = clk_get_parent(clk);
Matt Wagantalle18bbc82011-10-06 10:07:28 -0700202
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700203 ret = clk_enable(parent);
204 if (ret)
Matt Wagantalle18bbc82011-10-06 10:07:28 -0700205 goto err_enable_parent;
Stephen Boyd7fa26742011-08-11 23:22:29 -0700206 ret = clk_enable(clk->depends);
Matt Wagantalle18bbc82011-10-06 10:07:28 -0700207 if (ret)
208 goto err_enable_depends;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700209
Stephen Boyd5bc44d52012-03-29 11:00:57 -0700210 trace_clock_enable(clk->dbg_name, 1, smp_processor_id());
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700211 if (clk->ops->enable)
212 ret = clk->ops->enable(clk);
Matt Wagantalle18bbc82011-10-06 10:07:28 -0700213 if (ret)
214 goto err_enable_clock;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700215 }
Brian Swetland600f7cf2008-09-09 11:04:14 -0700216 clk->count++;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700217 spin_unlock_irqrestore(&clk->lock, flags);
218
Matt Wagantalle18bbc82011-10-06 10:07:28 -0700219 return 0;
220
221err_enable_clock:
Matt Wagantalle18bbc82011-10-06 10:07:28 -0700222 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);
Stephen Boyd7fa26742011-08-11 23:22:29 -0700252 clk_disable(clk->depends);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700253 clk_disable(parent);
254 }
Brian Swetland600f7cf2008-09-09 11:04:14 -0700255 clk->count--;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700256out:
257 spin_unlock_irqrestore(&clk->lock, flags);
Brian Swetland600f7cf2008-09-09 11:04:14 -0700258}
259EXPORT_SYMBOL(clk_disable);
260
Stephen Boyd3bbf3462012-01-12 00:19:23 -0800261void clk_unprepare(struct clk *clk)
262{
Vikram Mulukutla55e8f992012-04-17 19:25:10 -0700263 if (IS_ERR_OR_NULL(clk))
Stephen Boyd3bbf3462012-01-12 00:19:23 -0800264 return;
265
266 mutex_lock(&clk->prepare_lock);
267 if (!clk->prepare_count) {
268 if (WARN(!clk->warned, "%s is unbalanced (prepare)",
269 clk->dbg_name))
270 clk->warned = true;
271 goto out;
272 }
273 if (clk->prepare_count == 1) {
274 struct clk *parent = clk_get_parent(clk);
275
276 if (WARN(!clk->warned && clk->count,
277 "%s: Don't call unprepare when the clock is enabled\n",
278 clk->dbg_name))
279 clk->warned = true;
280
281 if (clk->ops->unprepare)
282 clk->ops->unprepare(clk);
Stephen Boyd2c2875f2012-01-24 17:36:34 -0800283 unvote_rate_vdd(clk, clk->rate);
Stephen Boyd3bbf3462012-01-12 00:19:23 -0800284 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{
Stephen Boyd2c2875f2012-01-24 17:36:34 -0800319 unsigned long start_rate;
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
Stephen Boyd2c2875f2012-01-24 17:36:34 -0800328 mutex_lock(&clk->prepare_lock);
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 Boyd2c2875f2012-01-24 17:36:34 -0800334 trace_clock_set_rate(clk->dbg_name, rate, raw_smp_processor_id());
335 if (clk->prepare_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:
Stephen Boyd2c2875f2012-01-24 17:36:34 -0800353 mutex_unlock(&clk->prepare_lock);
Matt Wagantalle18bbc82011-10-06 10:07:28 -0700354 return rc;
355
356err_set_rate:
357 unvote_rate_vdd(clk, rate);
358err_vote_vdd:
Stephen Boyd2c2875f2012-01-24 17:36:34 -0800359 goto out;
Brian Swetland600f7cf2008-09-09 11:04:14 -0700360}
Matt Wagantall77952c42011-11-08 18:45:48 -0800361EXPORT_SYMBOL(clk_set_rate);
Brian Swetland600f7cf2008-09-09 11:04:14 -0700362
Daniel Walker5e96da52010-05-12 13:43:28 -0700363long clk_round_rate(struct clk *clk, unsigned long rate)
364{
Vikram Mulukutla55e8f992012-04-17 19:25:10 -0700365 if (IS_ERR_OR_NULL(clk))
366 return -EINVAL;
367
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700368 if (!clk->ops->round_rate)
369 return -ENOSYS;
370
371 return clk->ops->round_rate(clk, rate);
Daniel Walker5e96da52010-05-12 13:43:28 -0700372}
373EXPORT_SYMBOL(clk_round_rate);
374
Daniel Walker5e96da52010-05-12 13:43:28 -0700375int clk_set_max_rate(struct clk *clk, unsigned long rate)
376{
Vikram Mulukutla55e8f992012-04-17 19:25:10 -0700377 if (IS_ERR_OR_NULL(clk))
378 return -EINVAL;
379
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700380 if (!clk->ops->set_max_rate)
381 return -ENOSYS;
382
383 return clk->ops->set_max_rate(clk, rate);
Daniel Walker5e96da52010-05-12 13:43:28 -0700384}
385EXPORT_SYMBOL(clk_set_max_rate);
386
Brian Swetland600f7cf2008-09-09 11:04:14 -0700387int clk_set_parent(struct clk *clk, struct clk *parent)
388{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700389 if (!clk->ops->set_parent)
390 return 0;
391
392 return clk->ops->set_parent(clk, parent);
Brian Swetland600f7cf2008-09-09 11:04:14 -0700393}
394EXPORT_SYMBOL(clk_set_parent);
395
396struct clk *clk_get_parent(struct clk *clk)
397{
Vikram Mulukutla55e8f992012-04-17 19:25:10 -0700398 if (IS_ERR_OR_NULL(clk))
399 return NULL;
400
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700401 if (!clk->ops->get_parent)
402 return NULL;
403
404 return clk->ops->get_parent(clk);
Brian Swetland600f7cf2008-09-09 11:04:14 -0700405}
406EXPORT_SYMBOL(clk_get_parent);
407
408int clk_set_flags(struct clk *clk, unsigned long flags)
409{
Vikram Mulukutla55e8f992012-04-17 19:25:10 -0700410 if (IS_ERR_OR_NULL(clk))
Brian Swetland600f7cf2008-09-09 11:04:14 -0700411 return -EINVAL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700412 if (!clk->ops->set_flags)
413 return -ENOSYS;
414
415 return clk->ops->set_flags(clk, flags);
Brian Swetland600f7cf2008-09-09 11:04:14 -0700416}
417EXPORT_SYMBOL(clk_set_flags);
418
Stephen Boydbb600ae2011-08-02 20:11:40 -0700419static struct clock_init_data __initdata *clk_init_data;
Brian Swetland600f7cf2008-09-09 11:04:14 -0700420
Matt Wagantallf30fceb2012-06-12 19:13:11 -0700421static enum handoff __init __handoff_clk(struct clk *clk)
422{
423 enum handoff ret;
424 struct handoff_clk *h;
Matt Wagantall2a59b212012-06-12 19:16:01 -0700425 unsigned long rate;
Matt Wagantallf30fceb2012-06-12 19:13:11 -0700426 int err = 0;
427
428 /*
429 * Tree roots don't have parents, but need to be handed off. So,
430 * terminate recursion by returning "enabled". Also return "enabled"
431 * for clocks with non-zero enable counts since they must have already
432 * been handed off.
433 */
434 if (clk == NULL || clk->count)
435 return HANDOFF_ENABLED_CLK;
436
437 /* Clocks without handoff functions are assumed to be disabled. */
438 if (!clk->ops->handoff || (clk->flags & CLKFLAG_SKIP_HANDOFF))
439 return HANDOFF_DISABLED_CLK;
440
441 /*
442 * Handoff functions for children must be called before their parents'
443 * so that the correct parent is returned by the clk_get_parent() below.
444 */
445 ret = clk->ops->handoff(clk);
446 if (ret == HANDOFF_ENABLED_CLK) {
447 ret = __handoff_clk(clk_get_parent(clk));
448 if (ret == HANDOFF_ENABLED_CLK) {
449 h = kmalloc(sizeof(*h), GFP_KERNEL);
450 if (!h) {
451 err = -ENOMEM;
452 goto out;
453 }
454 err = clk_prepare_enable(clk);
455 if (err)
456 goto out;
Matt Wagantall2a59b212012-06-12 19:16:01 -0700457 rate = clk_get_rate(clk);
458 if (rate)
459 pr_debug("%s rate=%lu\n", clk->dbg_name, rate);
Matt Wagantallf30fceb2012-06-12 19:13:11 -0700460 h->clk = clk;
461 list_add_tail(&h->list, &handoff_list);
462 }
463 }
464out:
465 if (err) {
466 pr_err("%s handoff failed (%d)\n", clk->dbg_name, err);
467 kfree(h);
468 ret = HANDOFF_DISABLED_CLK;
469 }
470 return ret;
471}
472
Stephen Boydbb600ae2011-08-02 20:11:40 -0700473void __init msm_clock_init(struct clock_init_data *data)
Brian Swetland600f7cf2008-09-09 11:04:14 -0700474{
475 unsigned n;
Stephen Boyd94625ef2011-07-12 17:06:01 -0700476 struct clk_lookup *clock_tbl;
477 size_t num_clocks;
Matt Wagantallb37fea42012-04-04 16:47:23 -0700478 struct clk *clk;
Stephen Boydbb600ae2011-08-02 20:11:40 -0700479
480 clk_init_data = data;
Matt Wagantallb64888f2012-04-02 21:35:07 -0700481 if (clk_init_data->pre_init)
482 clk_init_data->pre_init();
Brian Swetland600f7cf2008-09-09 11:04:14 -0700483
Stephen Boyd94625ef2011-07-12 17:06:01 -0700484 clock_tbl = data->table;
485 num_clocks = data->size;
486
Stephen Boydbd323442011-02-23 09:37:42 -0800487 for (n = 0; n < num_clocks; n++) {
Matt Wagantallb37fea42012-04-04 16:47:23 -0700488 struct clk *parent;
489 clk = clock_tbl[n].clk;
490 parent = clk_get_parent(clk);
Matt Wagantalle1482bf2012-04-04 16:23:45 -0700491 if (parent && list_empty(&clk->siblings))
492 list_add(&clk->siblings, &parent->children);
Matt Wagantallb37fea42012-04-04 16:47:23 -0700493 }
494
495 /*
496 * Detect and preserve initial clock state until clock_late_init() or
497 * a driver explicitly changes it, whichever is first.
498 */
Matt Wagantallf30fceb2012-06-12 19:13:11 -0700499 for (n = 0; n < num_clocks; n++)
500 __handoff_clk(clock_tbl[n].clk);
Daniel Walker5e96da52010-05-12 13:43:28 -0700501
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700502 clkdev_add_table(clock_tbl, num_clocks);
Matt Wagantallb64888f2012-04-02 21:35:07 -0700503
504 if (clk_init_data->post_init)
505 clk_init_data->post_init();
Brian Swetland600f7cf2008-09-09 11:04:14 -0700506}
507
Brian Swetland600f7cf2008-09-09 11:04:14 -0700508static int __init clock_late_init(void)
509{
Matt Wagantall158f73b2012-05-16 11:29:35 -0700510 struct handoff_clk *h, *h_temp;
Matt Wagantall647d1c12012-05-16 14:32:14 -0700511 int n, ret = 0;
Brian Swetland600f7cf2008-09-09 11:04:14 -0700512
Stephen Boydbb600ae2011-08-02 20:11:40 -0700513 clock_debug_init(clk_init_data);
Matt Wagantall647d1c12012-05-16 14:32:14 -0700514 for (n = 0; n < clk_init_data->size; n++)
515 clock_debug_add(clk_init_data->table[n].clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700516
Matt Wagantall647d1c12012-05-16 14:32:14 -0700517 pr_info("%s: Removing enables held for handed-off clocks\n", __func__);
Matt Wagantall158f73b2012-05-16 11:29:35 -0700518 list_for_each_entry_safe(h, h_temp, &handoff_list, list) {
519 clk_disable_unprepare(h->clk);
520 list_del(&h->list);
521 kfree(h);
522 }
523
Stephen Boydbb600ae2011-08-02 20:11:40 -0700524 if (clk_init_data->late_init)
525 ret = clk_init_data->late_init();
526 return ret;
Brian Swetland600f7cf2008-09-09 11:04:14 -0700527}
Brian Swetland600f7cf2008-09-09 11:04:14 -0700528late_initcall(clock_late_init);