core.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791
  1. /*
  2. * SuperH clock framework
  3. *
  4. * Copyright (C) 2005 - 2010 Paul Mundt
  5. *
  6. * This clock framework is derived from the OMAP version by:
  7. *
  8. * Copyright (C) 2004 - 2008 Nokia Corporation
  9. * Written by Tuukka Tikkanen <tuukka.tikkanen@elektrobit.com>
  10. *
  11. * Modified for omap shared clock framework by Tony Lindgren <tony@atomide.com>
  12. *
  13. * This file is subject to the terms and conditions of the GNU General Public
  14. * License. See the file "COPYING" in the main directory of this archive
  15. * for more details.
  16. */
  17. #define pr_fmt(fmt) "clock: " fmt
  18. #include <linux/kernel.h>
  19. #include <linux/init.h>
  20. #include <linux/module.h>
  21. #include <linux/mutex.h>
  22. #include <linux/list.h>
  23. #include <linux/syscore_ops.h>
  24. #include <linux/seq_file.h>
  25. #include <linux/err.h>
  26. #include <linux/io.h>
  27. #include <linux/debugfs.h>
  28. #include <linux/cpufreq.h>
  29. #include <linux/clk.h>
  30. #include <linux/sh_clk.h>
  31. static LIST_HEAD(clock_list);
  32. static DEFINE_SPINLOCK(clock_lock);
  33. static DEFINE_MUTEX(clock_list_sem);
  34. /* clock disable operations are not passed on to hardware during boot */
  35. static int allow_disable;
  36. void clk_rate_table_build(struct clk *clk,
  37. struct cpufreq_frequency_table *freq_table,
  38. int nr_freqs,
  39. struct clk_div_mult_table *src_table,
  40. unsigned long *bitmap)
  41. {
  42. unsigned long mult, div;
  43. unsigned long freq;
  44. int i;
  45. clk->nr_freqs = nr_freqs;
  46. for (i = 0; i < nr_freqs; i++) {
  47. div = 1;
  48. mult = 1;
  49. if (src_table->divisors && i < src_table->nr_divisors)
  50. div = src_table->divisors[i];
  51. if (src_table->multipliers && i < src_table->nr_multipliers)
  52. mult = src_table->multipliers[i];
  53. if (!div || !mult || (bitmap && !test_bit(i, bitmap)))
  54. freq = CPUFREQ_ENTRY_INVALID;
  55. else
  56. freq = clk->parent->rate * mult / div;
  57. freq_table[i].index = i;
  58. freq_table[i].frequency = freq;
  59. }
  60. /* Termination entry */
  61. freq_table[i].index = i;
  62. freq_table[i].frequency = CPUFREQ_TABLE_END;
  63. }
  64. struct clk_rate_round_data;
  65. struct clk_rate_round_data {
  66. unsigned long rate;
  67. unsigned int min, max;
  68. long (*func)(unsigned int, struct clk_rate_round_data *);
  69. void *arg;
  70. };
  71. #define for_each_frequency(pos, r, freq) \
  72. for (pos = r->min, freq = r->func(pos, r); \
  73. pos <= r->max; pos++, freq = r->func(pos, r)) \
  74. if (unlikely(freq == 0)) \
  75. ; \
  76. else
  77. static long clk_rate_round_helper(struct clk_rate_round_data *rounder)
  78. {
  79. unsigned long rate_error, rate_error_prev = ~0UL;
  80. unsigned long highest, lowest, freq;
  81. long rate_best_fit = -ENOENT;
  82. int i;
  83. highest = 0;
  84. lowest = ~0UL;
  85. for_each_frequency(i, rounder, freq) {
  86. if (freq > highest)
  87. highest = freq;
  88. if (freq < lowest)
  89. lowest = freq;
  90. rate_error = abs(freq - rounder->rate);
  91. if (rate_error < rate_error_prev) {
  92. rate_best_fit = freq;
  93. rate_error_prev = rate_error;
  94. }
  95. if (rate_error == 0)
  96. break;
  97. }
  98. if (rounder->rate >= highest)
  99. rate_best_fit = highest;
  100. if (rounder->rate <= lowest)
  101. rate_best_fit = lowest;
  102. return rate_best_fit;
  103. }
  104. static long clk_rate_table_iter(unsigned int pos,
  105. struct clk_rate_round_data *rounder)
  106. {
  107. struct cpufreq_frequency_table *freq_table = rounder->arg;
  108. unsigned long freq = freq_table[pos].frequency;
  109. if (freq == CPUFREQ_ENTRY_INVALID)
  110. freq = 0;
  111. return freq;
  112. }
  113. long clk_rate_table_round(struct clk *clk,
  114. struct cpufreq_frequency_table *freq_table,
  115. unsigned long rate)
  116. {
  117. struct clk_rate_round_data table_round = {
  118. .min = 0,
  119. .max = clk->nr_freqs - 1,
  120. .func = clk_rate_table_iter,
  121. .arg = freq_table,
  122. .rate = rate,
  123. };
  124. if (clk->nr_freqs < 1)
  125. return -ENOSYS;
  126. return clk_rate_round_helper(&table_round);
  127. }
  128. static long clk_rate_div_range_iter(unsigned int pos,
  129. struct clk_rate_round_data *rounder)
  130. {
  131. return clk_get_rate(rounder->arg) / pos;
  132. }
  133. long clk_rate_div_range_round(struct clk *clk, unsigned int div_min,
  134. unsigned int div_max, unsigned long rate)
  135. {
  136. struct clk_rate_round_data div_range_round = {
  137. .min = div_min,
  138. .max = div_max,
  139. .func = clk_rate_div_range_iter,
  140. .arg = clk_get_parent(clk),
  141. .rate = rate,
  142. };
  143. return clk_rate_round_helper(&div_range_round);
  144. }
  145. static long clk_rate_mult_range_iter(unsigned int pos,
  146. struct clk_rate_round_data *rounder)
  147. {
  148. return clk_get_rate(rounder->arg) * pos;
  149. }
  150. long clk_rate_mult_range_round(struct clk *clk, unsigned int mult_min,
  151. unsigned int mult_max, unsigned long rate)
  152. {
  153. struct clk_rate_round_data mult_range_round = {
  154. .min = mult_min,
  155. .max = mult_max,
  156. .func = clk_rate_mult_range_iter,
  157. .arg = clk_get_parent(clk),
  158. .rate = rate,
  159. };
  160. return clk_rate_round_helper(&mult_range_round);
  161. }
  162. int clk_rate_table_find(struct clk *clk,
  163. struct cpufreq_frequency_table *freq_table,
  164. unsigned long rate)
  165. {
  166. int i;
  167. for (i = 0; freq_table[i].frequency != CPUFREQ_TABLE_END; i++) {
  168. unsigned long freq = freq_table[i].frequency;
  169. if (freq == CPUFREQ_ENTRY_INVALID)
  170. continue;
  171. if (freq == rate)
  172. return i;
  173. }
  174. return -ENOENT;
  175. }
  176. /* Used for clocks that always have same value as the parent clock */
  177. unsigned long followparent_recalc(struct clk *clk)
  178. {
  179. return clk->parent ? clk->parent->rate : 0;
  180. }
  181. int clk_reparent(struct clk *child, struct clk *parent)
  182. {
  183. list_del_init(&child->sibling);
  184. if (parent)
  185. list_add(&child->sibling, &parent->children);
  186. child->parent = parent;
  187. /* now do the debugfs renaming to reattach the child
  188. to the proper parent */
  189. return 0;
  190. }
  191. /* Propagate rate to children */
  192. void propagate_rate(struct clk *tclk)
  193. {
  194. struct clk *clkp;
  195. list_for_each_entry(clkp, &tclk->children, sibling) {
  196. if (clkp->ops && clkp->ops->recalc)
  197. clkp->rate = clkp->ops->recalc(clkp);
  198. propagate_rate(clkp);
  199. }
  200. }
  201. static void __clk_disable(struct clk *clk)
  202. {
  203. if (WARN(!clk->usecount, "Trying to disable clock %p with 0 usecount\n",
  204. clk))
  205. return;
  206. if (!(--clk->usecount)) {
  207. if (likely(allow_disable && clk->ops && clk->ops->disable))
  208. clk->ops->disable(clk);
  209. if (likely(clk->parent))
  210. __clk_disable(clk->parent);
  211. }
  212. }
  213. void clk_disable(struct clk *clk)
  214. {
  215. unsigned long flags;
  216. if (!clk)
  217. return;
  218. spin_lock_irqsave(&clock_lock, flags);
  219. __clk_disable(clk);
  220. spin_unlock_irqrestore(&clock_lock, flags);
  221. }
  222. EXPORT_SYMBOL_GPL(clk_disable);
  223. static int __clk_enable(struct clk *clk)
  224. {
  225. int ret = 0;
  226. if (clk->usecount++ == 0) {
  227. if (clk->parent) {
  228. ret = __clk_enable(clk->parent);
  229. if (unlikely(ret))
  230. goto err;
  231. }
  232. if (clk->ops && clk->ops->enable) {
  233. ret = clk->ops->enable(clk);
  234. if (ret) {
  235. if (clk->parent)
  236. __clk_disable(clk->parent);
  237. goto err;
  238. }
  239. }
  240. }
  241. return ret;
  242. err:
  243. clk->usecount--;
  244. return ret;
  245. }
  246. int clk_enable(struct clk *clk)
  247. {
  248. unsigned long flags;
  249. int ret;
  250. if (!clk)
  251. return -EINVAL;
  252. spin_lock_irqsave(&clock_lock, flags);
  253. ret = __clk_enable(clk);
  254. spin_unlock_irqrestore(&clock_lock, flags);
  255. return ret;
  256. }
  257. EXPORT_SYMBOL_GPL(clk_enable);
  258. static LIST_HEAD(root_clks);
  259. /**
  260. * recalculate_root_clocks - recalculate and propagate all root clocks
  261. *
  262. * Recalculates all root clocks (clocks with no parent), which if the
  263. * clock's .recalc is set correctly, should also propagate their rates.
  264. * Called at init.
  265. */
  266. void recalculate_root_clocks(void)
  267. {
  268. struct clk *clkp;
  269. list_for_each_entry(clkp, &root_clks, sibling) {
  270. if (clkp->ops && clkp->ops->recalc)
  271. clkp->rate = clkp->ops->recalc(clkp);
  272. propagate_rate(clkp);
  273. }
  274. }
  275. static struct clk_mapping dummy_mapping;
  276. static struct clk *lookup_root_clock(struct clk *clk)
  277. {
  278. while (clk->parent)
  279. clk = clk->parent;
  280. return clk;
  281. }
  282. static int clk_establish_mapping(struct clk *clk)
  283. {
  284. struct clk_mapping *mapping = clk->mapping;
  285. /*
  286. * Propagate mappings.
  287. */
  288. if (!mapping) {
  289. struct clk *clkp;
  290. /*
  291. * dummy mapping for root clocks with no specified ranges
  292. */
  293. if (!clk->parent) {
  294. clk->mapping = &dummy_mapping;
  295. return 0;
  296. }
  297. /*
  298. * If we're on a child clock and it provides no mapping of its
  299. * own, inherit the mapping from its root clock.
  300. */
  301. clkp = lookup_root_clock(clk);
  302. mapping = clkp->mapping;
  303. BUG_ON(!mapping);
  304. }
  305. /*
  306. * Establish initial mapping.
  307. */
  308. if (!mapping->base && mapping->phys) {
  309. kref_init(&mapping->ref);
  310. mapping->base = ioremap_nocache(mapping->phys, mapping->len);
  311. if (unlikely(!mapping->base))
  312. return -ENXIO;
  313. } else if (mapping->base) {
  314. /*
  315. * Bump the refcount for an existing mapping
  316. */
  317. kref_get(&mapping->ref);
  318. }
  319. clk->mapping = mapping;
  320. return 0;
  321. }
  322. static void clk_destroy_mapping(struct kref *kref)
  323. {
  324. struct clk_mapping *mapping;
  325. mapping = container_of(kref, struct clk_mapping, ref);
  326. iounmap(mapping->base);
  327. }
  328. static void clk_teardown_mapping(struct clk *clk)
  329. {
  330. struct clk_mapping *mapping = clk->mapping;
  331. /* Nothing to do */
  332. if (mapping == &dummy_mapping)
  333. return;
  334. kref_put(&mapping->ref, clk_destroy_mapping);
  335. clk->mapping = NULL;
  336. }
  337. int clk_register(struct clk *clk)
  338. {
  339. int ret;
  340. if (IS_ERR_OR_NULL(clk))
  341. return -EINVAL;
  342. /*
  343. * trap out already registered clocks
  344. */
  345. if (clk->node.next || clk->node.prev)
  346. return 0;
  347. mutex_lock(&clock_list_sem);
  348. INIT_LIST_HEAD(&clk->children);
  349. clk->usecount = 0;
  350. ret = clk_establish_mapping(clk);
  351. if (unlikely(ret))
  352. goto out_unlock;
  353. if (clk->parent)
  354. list_add(&clk->sibling, &clk->parent->children);
  355. else
  356. list_add(&clk->sibling, &root_clks);
  357. list_add(&clk->node, &clock_list);
  358. #ifdef CONFIG_SH_CLK_CPG_LEGACY
  359. if (clk->ops && clk->ops->init)
  360. clk->ops->init(clk);
  361. #endif
  362. out_unlock:
  363. mutex_unlock(&clock_list_sem);
  364. return ret;
  365. }
  366. EXPORT_SYMBOL_GPL(clk_register);
  367. void clk_unregister(struct clk *clk)
  368. {
  369. mutex_lock(&clock_list_sem);
  370. list_del(&clk->sibling);
  371. list_del(&clk->node);
  372. clk_teardown_mapping(clk);
  373. mutex_unlock(&clock_list_sem);
  374. }
  375. EXPORT_SYMBOL_GPL(clk_unregister);
  376. void clk_enable_init_clocks(void)
  377. {
  378. struct clk *clkp;
  379. list_for_each_entry(clkp, &clock_list, node)
  380. if (clkp->flags & CLK_ENABLE_ON_INIT)
  381. clk_enable(clkp);
  382. }
  383. unsigned long clk_get_rate(struct clk *clk)
  384. {
  385. return clk->rate;
  386. }
  387. EXPORT_SYMBOL_GPL(clk_get_rate);
  388. int clk_set_rate(struct clk *clk, unsigned long rate)
  389. {
  390. int ret = -EOPNOTSUPP;
  391. unsigned long flags;
  392. spin_lock_irqsave(&clock_lock, flags);
  393. if (likely(clk->ops && clk->ops->set_rate)) {
  394. ret = clk->ops->set_rate(clk, rate);
  395. if (ret != 0)
  396. goto out_unlock;
  397. } else {
  398. clk->rate = rate;
  399. ret = 0;
  400. }
  401. if (clk->ops && clk->ops->recalc)
  402. clk->rate = clk->ops->recalc(clk);
  403. propagate_rate(clk);
  404. out_unlock:
  405. spin_unlock_irqrestore(&clock_lock, flags);
  406. return ret;
  407. }
  408. EXPORT_SYMBOL_GPL(clk_set_rate);
  409. int clk_set_parent(struct clk *clk, struct clk *parent)
  410. {
  411. unsigned long flags;
  412. int ret = -EINVAL;
  413. if (!parent || !clk)
  414. return ret;
  415. if (clk->parent == parent)
  416. return 0;
  417. spin_lock_irqsave(&clock_lock, flags);
  418. if (clk->usecount == 0) {
  419. if (clk->ops->set_parent)
  420. ret = clk->ops->set_parent(clk, parent);
  421. else
  422. ret = clk_reparent(clk, parent);
  423. if (ret == 0) {
  424. if (clk->ops->recalc)
  425. clk->rate = clk->ops->recalc(clk);
  426. pr_debug("set parent of %p to %p (new rate %ld)\n",
  427. clk, clk->parent, clk->rate);
  428. propagate_rate(clk);
  429. }
  430. } else
  431. ret = -EBUSY;
  432. spin_unlock_irqrestore(&clock_lock, flags);
  433. return ret;
  434. }
  435. EXPORT_SYMBOL_GPL(clk_set_parent);
  436. struct clk *clk_get_parent(struct clk *clk)
  437. {
  438. return clk->parent;
  439. }
  440. EXPORT_SYMBOL_GPL(clk_get_parent);
  441. long clk_round_rate(struct clk *clk, unsigned long rate)
  442. {
  443. if (likely(clk->ops && clk->ops->round_rate)) {
  444. unsigned long flags, rounded;
  445. spin_lock_irqsave(&clock_lock, flags);
  446. rounded = clk->ops->round_rate(clk, rate);
  447. spin_unlock_irqrestore(&clock_lock, flags);
  448. return rounded;
  449. }
  450. return clk_get_rate(clk);
  451. }
  452. EXPORT_SYMBOL_GPL(clk_round_rate);
  453. long clk_round_parent(struct clk *clk, unsigned long target,
  454. unsigned long *best_freq, unsigned long *parent_freq,
  455. unsigned int div_min, unsigned int div_max)
  456. {
  457. struct cpufreq_frequency_table *freq, *best = NULL;
  458. unsigned long error = ULONG_MAX, freq_high, freq_low, div;
  459. struct clk *parent = clk_get_parent(clk);
  460. if (!parent) {
  461. *parent_freq = 0;
  462. *best_freq = clk_round_rate(clk, target);
  463. return abs(target - *best_freq);
  464. }
  465. for (freq = parent->freq_table; freq->frequency != CPUFREQ_TABLE_END;
  466. freq++) {
  467. if (freq->frequency == CPUFREQ_ENTRY_INVALID)
  468. continue;
  469. if (unlikely(freq->frequency / target <= div_min - 1)) {
  470. unsigned long freq_max;
  471. freq_max = (freq->frequency + div_min / 2) / div_min;
  472. if (error > target - freq_max) {
  473. error = target - freq_max;
  474. best = freq;
  475. if (best_freq)
  476. *best_freq = freq_max;
  477. }
  478. pr_debug("too low freq %u, error %lu\n", freq->frequency,
  479. target - freq_max);
  480. if (!error)
  481. break;
  482. continue;
  483. }
  484. if (unlikely(freq->frequency / target >= div_max)) {
  485. unsigned long freq_min;
  486. freq_min = (freq->frequency + div_max / 2) / div_max;
  487. if (error > freq_min - target) {
  488. error = freq_min - target;
  489. best = freq;
  490. if (best_freq)
  491. *best_freq = freq_min;
  492. }
  493. pr_debug("too high freq %u, error %lu\n", freq->frequency,
  494. freq_min - target);
  495. if (!error)
  496. break;
  497. continue;
  498. }
  499. div = freq->frequency / target;
  500. freq_high = freq->frequency / div;
  501. freq_low = freq->frequency / (div + 1);
  502. if (freq_high - target < error) {
  503. error = freq_high - target;
  504. best = freq;
  505. if (best_freq)
  506. *best_freq = freq_high;
  507. }
  508. if (target - freq_low < error) {
  509. error = target - freq_low;
  510. best = freq;
  511. if (best_freq)
  512. *best_freq = freq_low;
  513. }
  514. pr_debug("%u / %lu = %lu, / %lu = %lu, best %lu, parent %u\n",
  515. freq->frequency, div, freq_high, div + 1, freq_low,
  516. *best_freq, best->frequency);
  517. if (!error)
  518. break;
  519. }
  520. if (parent_freq)
  521. *parent_freq = best->frequency;
  522. return error;
  523. }
  524. EXPORT_SYMBOL_GPL(clk_round_parent);
  525. #ifdef CONFIG_PM
  526. static void clks_core_resume(void)
  527. {
  528. struct clk *clkp;
  529. list_for_each_entry(clkp, &clock_list, node) {
  530. if (likely(clkp->usecount && clkp->ops)) {
  531. unsigned long rate = clkp->rate;
  532. if (likely(clkp->ops->set_parent))
  533. clkp->ops->set_parent(clkp,
  534. clkp->parent);
  535. if (likely(clkp->ops->set_rate))
  536. clkp->ops->set_rate(clkp, rate);
  537. else if (likely(clkp->ops->recalc))
  538. clkp->rate = clkp->ops->recalc(clkp);
  539. }
  540. }
  541. }
  542. static struct syscore_ops clks_syscore_ops = {
  543. .resume = clks_core_resume,
  544. };
  545. static int __init clk_syscore_init(void)
  546. {
  547. register_syscore_ops(&clks_syscore_ops);
  548. return 0;
  549. }
  550. subsys_initcall(clk_syscore_init);
  551. #endif
  552. /*
  553. * debugfs support to trace clock tree hierarchy and attributes
  554. */
  555. static struct dentry *clk_debugfs_root;
  556. static int clk_debugfs_register_one(struct clk *c)
  557. {
  558. int err;
  559. struct dentry *d;
  560. struct clk *pa = c->parent;
  561. char s[255];
  562. char *p = s;
  563. p += sprintf(p, "%p", c);
  564. d = debugfs_create_dir(s, pa ? pa->dentry : clk_debugfs_root);
  565. if (!d)
  566. return -ENOMEM;
  567. c->dentry = d;
  568. d = debugfs_create_u8("usecount", S_IRUGO, c->dentry, (u8 *)&c->usecount);
  569. if (!d) {
  570. err = -ENOMEM;
  571. goto err_out;
  572. }
  573. d = debugfs_create_u32("rate", S_IRUGO, c->dentry, (u32 *)&c->rate);
  574. if (!d) {
  575. err = -ENOMEM;
  576. goto err_out;
  577. }
  578. d = debugfs_create_x32("flags", S_IRUGO, c->dentry, (u32 *)&c->flags);
  579. if (!d) {
  580. err = -ENOMEM;
  581. goto err_out;
  582. }
  583. return 0;
  584. err_out:
  585. debugfs_remove_recursive(c->dentry);
  586. return err;
  587. }
  588. static int clk_debugfs_register(struct clk *c)
  589. {
  590. int err;
  591. struct clk *pa = c->parent;
  592. if (pa && !pa->dentry) {
  593. err = clk_debugfs_register(pa);
  594. if (err)
  595. return err;
  596. }
  597. if (!c->dentry) {
  598. err = clk_debugfs_register_one(c);
  599. if (err)
  600. return err;
  601. }
  602. return 0;
  603. }
  604. static int __init clk_debugfs_init(void)
  605. {
  606. struct clk *c;
  607. struct dentry *d;
  608. int err;
  609. d = debugfs_create_dir("clock", NULL);
  610. if (!d)
  611. return -ENOMEM;
  612. clk_debugfs_root = d;
  613. list_for_each_entry(c, &clock_list, node) {
  614. err = clk_debugfs_register(c);
  615. if (err)
  616. goto err_out;
  617. }
  618. return 0;
  619. err_out:
  620. debugfs_remove_recursive(clk_debugfs_root);
  621. return err;
  622. }
  623. late_initcall(clk_debugfs_init);
  624. static int __init clk_late_init(void)
  625. {
  626. unsigned long flags;
  627. struct clk *clk;
  628. /* disable all clocks with zero use count */
  629. mutex_lock(&clock_list_sem);
  630. spin_lock_irqsave(&clock_lock, flags);
  631. list_for_each_entry(clk, &clock_list, node)
  632. if (!clk->usecount && clk->ops && clk->ops->disable)
  633. clk->ops->disable(clk);
  634. /* from now on allow clock disable operations */
  635. allow_disable = 1;
  636. spin_unlock_irqrestore(&clock_lock, flags);
  637. mutex_unlock(&clock_list_sem);
  638. return 0;
  639. }
  640. late_initcall(clk_late_init);