clock.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. /*
  2. * linux/arch/arm/mach-omap2/clock.c
  3. *
  4. * Copyright (C) 2005-2008 Texas Instruments, Inc.
  5. * Copyright (C) 2004-2010 Nokia Corporation
  6. *
  7. * Contacts:
  8. * Richard Woodruff <r-woodruff2@ti.com>
  9. * Paul Walmsley
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License version 2 as
  13. * published by the Free Software Foundation.
  14. */
  15. #undef DEBUG
  16. #include <linux/kernel.h>
  17. #include <linux/export.h>
  18. #include <linux/list.h>
  19. #include <linux/errno.h>
  20. #include <linux/err.h>
  21. #include <linux/delay.h>
  22. #include <linux/clk-provider.h>
  23. #include <linux/io.h>
  24. #include <linux/bitops.h>
  25. #include <linux/clk-private.h>
  26. #include <asm/cpu.h>
  27. #include <trace/events/power.h>
  28. #include "soc.h"
  29. #include "clockdomain.h"
  30. #include "clock.h"
  31. #include "cm.h"
  32. #include "cm2xxx.h"
  33. #include "cm3xxx.h"
  34. #include "cm-regbits-24xx.h"
  35. #include "cm-regbits-34xx.h"
  36. #include "common.h"
  37. /*
  38. * MAX_MODULE_ENABLE_WAIT: maximum of number of microseconds to wait
  39. * for a module to indicate that it is no longer in idle
  40. */
  41. #define MAX_MODULE_ENABLE_WAIT 100000
  42. u16 cpu_mask;
  43. /*
  44. * clkdm_control: if true, then when a clock is enabled in the
  45. * hardware, its clockdomain will first be enabled; and when a clock
  46. * is disabled in the hardware, its clockdomain will be disabled
  47. * afterwards.
  48. */
  49. static bool clkdm_control = true;
  50. static LIST_HEAD(clk_hw_omap_clocks);
  51. /*
  52. * Used for clocks that have the same value as the parent clock,
  53. * divided by some factor
  54. */
  55. unsigned long omap_fixed_divisor_recalc(struct clk_hw *hw,
  56. unsigned long parent_rate)
  57. {
  58. struct clk_hw_omap *oclk;
  59. if (!hw) {
  60. pr_warn("%s: hw is NULL\n", __func__);
  61. return -EINVAL;
  62. }
  63. oclk = to_clk_hw_omap(hw);
  64. WARN_ON(!oclk->fixed_div);
  65. return parent_rate / oclk->fixed_div;
  66. }
  67. /*
  68. * OMAP2+ specific clock functions
  69. */
  70. /* Private functions */
  71. /**
  72. * _wait_idlest_generic - wait for a module to leave the idle state
  73. * @reg: virtual address of module IDLEST register
  74. * @mask: value to mask against to determine if the module is active
  75. * @idlest: idle state indicator (0 or 1) for the clock
  76. * @name: name of the clock (for printk)
  77. *
  78. * Wait for a module to leave idle, where its idle-status register is
  79. * not inside the CM module. Returns 1 if the module left idle
  80. * promptly, or 0 if the module did not leave idle before the timeout
  81. * elapsed. XXX Deprecated - should be moved into drivers for the
  82. * individual IP block that the IDLEST register exists in.
  83. */
  84. static int _wait_idlest_generic(void __iomem *reg, u32 mask, u8 idlest,
  85. const char *name)
  86. {
  87. int i = 0, ena = 0;
  88. ena = (idlest) ? 0 : mask;
  89. omap_test_timeout(((__raw_readl(reg) & mask) == ena),
  90. MAX_MODULE_ENABLE_WAIT, i);
  91. if (i < MAX_MODULE_ENABLE_WAIT)
  92. pr_debug("omap clock: module associated with clock %s ready after %d loops\n",
  93. name, i);
  94. else
  95. pr_err("omap clock: module associated with clock %s didn't enable in %d tries\n",
  96. name, MAX_MODULE_ENABLE_WAIT);
  97. return (i < MAX_MODULE_ENABLE_WAIT) ? 1 : 0;
  98. };
  99. /**
  100. * _omap2_module_wait_ready - wait for an OMAP module to leave IDLE
  101. * @clk: struct clk * belonging to the module
  102. *
  103. * If the necessary clocks for the OMAP hardware IP block that
  104. * corresponds to clock @clk are enabled, then wait for the module to
  105. * indicate readiness (i.e., to leave IDLE). This code does not
  106. * belong in the clock code and will be moved in the medium term to
  107. * module-dependent code. No return value.
  108. */
  109. static void _omap2_module_wait_ready(struct clk_hw_omap *clk)
  110. {
  111. void __iomem *companion_reg, *idlest_reg;
  112. u8 other_bit, idlest_bit, idlest_val, idlest_reg_id;
  113. s16 prcm_mod;
  114. int r;
  115. /* Not all modules have multiple clocks that their IDLEST depends on */
  116. if (clk->ops->find_companion) {
  117. clk->ops->find_companion(clk, &companion_reg, &other_bit);
  118. if (!(__raw_readl(companion_reg) & (1 << other_bit)))
  119. return;
  120. }
  121. clk->ops->find_idlest(clk, &idlest_reg, &idlest_bit, &idlest_val);
  122. r = cm_split_idlest_reg(idlest_reg, &prcm_mod, &idlest_reg_id);
  123. if (r) {
  124. /* IDLEST register not in the CM module */
  125. _wait_idlest_generic(idlest_reg, (1 << idlest_bit), idlest_val,
  126. __clk_get_name(clk->hw.clk));
  127. } else {
  128. cm_wait_module_ready(prcm_mod, idlest_reg_id, idlest_bit);
  129. };
  130. }
  131. /* Public functions */
  132. /**
  133. * omap2_init_clk_clkdm - look up a clockdomain name, store pointer in clk
  134. * @clk: OMAP clock struct ptr to use
  135. *
  136. * Convert a clockdomain name stored in a struct clk 'clk' into a
  137. * clockdomain pointer, and save it into the struct clk. Intended to be
  138. * called during clk_register(). No return value.
  139. */
  140. void omap2_init_clk_clkdm(struct clk_hw *hw)
  141. {
  142. struct clk_hw_omap *clk = to_clk_hw_omap(hw);
  143. struct clockdomain *clkdm;
  144. const char *clk_name;
  145. if (!clk->clkdm_name)
  146. return;
  147. clk_name = __clk_get_name(hw->clk);
  148. clkdm = clkdm_lookup(clk->clkdm_name);
  149. if (clkdm) {
  150. pr_debug("clock: associated clk %s to clkdm %s\n",
  151. clk_name, clk->clkdm_name);
  152. clk->clkdm = clkdm;
  153. } else {
  154. pr_debug("clock: could not associate clk %s to clkdm %s\n",
  155. clk_name, clk->clkdm_name);
  156. }
  157. }
  158. /**
  159. * omap2_clk_disable_clkdm_control - disable clkdm control on clk enable/disable
  160. *
  161. * Prevent the OMAP clock code from calling into the clockdomain code
  162. * when a hardware clock in that clockdomain is enabled or disabled.
  163. * Intended to be called at init time from omap*_clk_init(). No
  164. * return value.
  165. */
  166. void __init omap2_clk_disable_clkdm_control(void)
  167. {
  168. clkdm_control = false;
  169. }
  170. /**
  171. * omap2_clk_dflt_find_companion - find companion clock to @clk
  172. * @clk: struct clk * to find the companion clock of
  173. * @other_reg: void __iomem ** to return the companion clock CM_*CLKEN va in
  174. * @other_bit: u8 ** to return the companion clock bit shift in
  175. *
  176. * Note: We don't need special code here for INVERT_ENABLE for the
  177. * time being since INVERT_ENABLE only applies to clocks enabled by
  178. * CM_CLKEN_PLL
  179. *
  180. * Convert CM_ICLKEN* <-> CM_FCLKEN*. This conversion assumes it's
  181. * just a matter of XORing the bits.
  182. *
  183. * Some clocks don't have companion clocks. For example, modules with
  184. * only an interface clock (such as MAILBOXES) don't have a companion
  185. * clock. Right now, this code relies on the hardware exporting a bit
  186. * in the correct companion register that indicates that the
  187. * nonexistent 'companion clock' is active. Future patches will
  188. * associate this type of code with per-module data structures to
  189. * avoid this issue, and remove the casts. No return value.
  190. */
  191. void omap2_clk_dflt_find_companion(struct clk_hw_omap *clk,
  192. void __iomem **other_reg, u8 *other_bit)
  193. {
  194. u32 r;
  195. /*
  196. * Convert CM_ICLKEN* <-> CM_FCLKEN*. This conversion assumes
  197. * it's just a matter of XORing the bits.
  198. */
  199. r = ((__force u32)clk->enable_reg ^ (CM_FCLKEN ^ CM_ICLKEN));
  200. *other_reg = (__force void __iomem *)r;
  201. *other_bit = clk->enable_bit;
  202. }
  203. /**
  204. * omap2_clk_dflt_find_idlest - find CM_IDLEST reg va, bit shift for @clk
  205. * @clk: struct clk * to find IDLEST info for
  206. * @idlest_reg: void __iomem ** to return the CM_IDLEST va in
  207. * @idlest_bit: u8 * to return the CM_IDLEST bit shift in
  208. * @idlest_val: u8 * to return the idle status indicator
  209. *
  210. * Return the CM_IDLEST register address and bit shift corresponding
  211. * to the module that "owns" this clock. This default code assumes
  212. * that the CM_IDLEST bit shift is the CM_*CLKEN bit shift, and that
  213. * the IDLEST register address ID corresponds to the CM_*CLKEN
  214. * register address ID (e.g., that CM_FCLKEN2 corresponds to
  215. * CM_IDLEST2). This is not true for all modules. No return value.
  216. */
  217. void omap2_clk_dflt_find_idlest(struct clk_hw_omap *clk,
  218. void __iomem **idlest_reg, u8 *idlest_bit, u8 *idlest_val)
  219. {
  220. u32 r;
  221. r = (((__force u32)clk->enable_reg & ~0xf0) | 0x20);
  222. *idlest_reg = (__force void __iomem *)r;
  223. *idlest_bit = clk->enable_bit;
  224. /*
  225. * 24xx uses 0 to indicate not ready, and 1 to indicate ready.
  226. * 34xx reverses this, just to keep us on our toes
  227. * AM35xx uses both, depending on the module.
  228. */
  229. if (cpu_is_omap24xx())
  230. *idlest_val = OMAP24XX_CM_IDLEST_VAL;
  231. else if (cpu_is_omap34xx())
  232. *idlest_val = OMAP34XX_CM_IDLEST_VAL;
  233. else
  234. BUG();
  235. }
  236. /**
  237. * omap2_dflt_clk_enable - enable a clock in the hardware
  238. * @hw: struct clk_hw * of the clock to enable
  239. *
  240. * Enable the clock @hw in the hardware. We first call into the OMAP
  241. * clockdomain code to "enable" the corresponding clockdomain if this
  242. * is the first enabled user of the clockdomain. Then program the
  243. * hardware to enable the clock. Then wait for the IP block that uses
  244. * this clock to leave idle (if applicable). Returns the error value
  245. * from clkdm_clk_enable() if it terminated with an error, or -EINVAL
  246. * if @hw has a null clock enable_reg, or zero upon success.
  247. */
  248. int omap2_dflt_clk_enable(struct clk_hw *hw)
  249. {
  250. struct clk_hw_omap *clk;
  251. u32 v;
  252. int ret = 0;
  253. clk = to_clk_hw_omap(hw);
  254. if (clkdm_control && clk->clkdm) {
  255. ret = clkdm_clk_enable(clk->clkdm, hw->clk);
  256. if (ret) {
  257. WARN(1, "%s: could not enable %s's clockdomain %s: %d\n",
  258. __func__, __clk_get_name(hw->clk),
  259. clk->clkdm->name, ret);
  260. return ret;
  261. }
  262. }
  263. if (unlikely(clk->enable_reg == NULL)) {
  264. pr_err("%s: %s missing enable_reg\n", __func__,
  265. __clk_get_name(hw->clk));
  266. ret = -EINVAL;
  267. goto err;
  268. }
  269. /* FIXME should not have INVERT_ENABLE bit here */
  270. v = __raw_readl(clk->enable_reg);
  271. if (clk->flags & INVERT_ENABLE)
  272. v &= ~(1 << clk->enable_bit);
  273. else
  274. v |= (1 << clk->enable_bit);
  275. __raw_writel(v, clk->enable_reg);
  276. v = __raw_readl(clk->enable_reg); /* OCP barrier */
  277. if (clk->ops && clk->ops->find_idlest)
  278. _omap2_module_wait_ready(clk);
  279. return 0;
  280. err:
  281. if (clkdm_control && clk->clkdm)
  282. clkdm_clk_disable(clk->clkdm, hw->clk);
  283. return ret;
  284. }
  285. /**
  286. * omap2_dflt_clk_disable - disable a clock in the hardware
  287. * @hw: struct clk_hw * of the clock to disable
  288. *
  289. * Disable the clock @hw in the hardware, and call into the OMAP
  290. * clockdomain code to "disable" the corresponding clockdomain if all
  291. * clocks/hwmods in that clockdomain are now disabled. No return
  292. * value.
  293. */
  294. void omap2_dflt_clk_disable(struct clk_hw *hw)
  295. {
  296. struct clk_hw_omap *clk;
  297. u32 v;
  298. clk = to_clk_hw_omap(hw);
  299. if (!clk->enable_reg) {
  300. /*
  301. * 'independent' here refers to a clock which is not
  302. * controlled by its parent.
  303. */
  304. pr_err("%s: independent clock %s has no enable_reg\n",
  305. __func__, __clk_get_name(hw->clk));
  306. return;
  307. }
  308. v = __raw_readl(clk->enable_reg);
  309. if (clk->flags & INVERT_ENABLE)
  310. v |= (1 << clk->enable_bit);
  311. else
  312. v &= ~(1 << clk->enable_bit);
  313. __raw_writel(v, clk->enable_reg);
  314. /* No OCP barrier needed here since it is a disable operation */
  315. if (clkdm_control && clk->clkdm)
  316. clkdm_clk_disable(clk->clkdm, hw->clk);
  317. }
  318. /**
  319. * omap2_clkops_enable_clkdm - increment usecount on clkdm of @hw
  320. * @hw: struct clk_hw * of the clock being enabled
  321. *
  322. * Increment the usecount of the clockdomain of the clock pointed to
  323. * by @hw; if the usecount is 1, the clockdomain will be "enabled."
  324. * Only needed for clocks that don't use omap2_dflt_clk_enable() as
  325. * their enable function pointer. Passes along the return value of
  326. * clkdm_clk_enable(), -EINVAL if @hw is not associated with a
  327. * clockdomain, or 0 if clock framework-based clockdomain control is
  328. * not implemented.
  329. */
  330. int omap2_clkops_enable_clkdm(struct clk_hw *hw)
  331. {
  332. struct clk_hw_omap *clk;
  333. int ret = 0;
  334. clk = to_clk_hw_omap(hw);
  335. if (unlikely(!clk->clkdm)) {
  336. pr_err("%s: %s: no clkdm set ?!\n", __func__,
  337. __clk_get_name(hw->clk));
  338. return -EINVAL;
  339. }
  340. if (unlikely(clk->enable_reg))
  341. pr_err("%s: %s: should use dflt_clk_enable ?!\n", __func__,
  342. __clk_get_name(hw->clk));
  343. if (!clkdm_control) {
  344. pr_err("%s: %s: clkfw-based clockdomain control disabled ?!\n",
  345. __func__, __clk_get_name(hw->clk));
  346. return 0;
  347. }
  348. ret = clkdm_clk_enable(clk->clkdm, hw->clk);
  349. WARN(ret, "%s: could not enable %s's clockdomain %s: %d\n",
  350. __func__, __clk_get_name(hw->clk), clk->clkdm->name, ret);
  351. return ret;
  352. }
  353. /**
  354. * omap2_clkops_disable_clkdm - decrement usecount on clkdm of @hw
  355. * @hw: struct clk_hw * of the clock being disabled
  356. *
  357. * Decrement the usecount of the clockdomain of the clock pointed to
  358. * by @hw; if the usecount is 0, the clockdomain will be "disabled."
  359. * Only needed for clocks that don't use omap2_dflt_clk_disable() as their
  360. * disable function pointer. No return value.
  361. */
  362. void omap2_clkops_disable_clkdm(struct clk_hw *hw)
  363. {
  364. struct clk_hw_omap *clk;
  365. clk = to_clk_hw_omap(hw);
  366. if (unlikely(!clk->clkdm)) {
  367. pr_err("%s: %s: no clkdm set ?!\n", __func__,
  368. __clk_get_name(hw->clk));
  369. return;
  370. }
  371. if (unlikely(clk->enable_reg))
  372. pr_err("%s: %s: should use dflt_clk_disable ?!\n", __func__,
  373. __clk_get_name(hw->clk));
  374. if (!clkdm_control) {
  375. pr_err("%s: %s: clkfw-based clockdomain control disabled ?!\n",
  376. __func__, __clk_get_name(hw->clk));
  377. return;
  378. }
  379. clkdm_clk_disable(clk->clkdm, hw->clk);
  380. }
  381. /**
  382. * omap2_dflt_clk_is_enabled - is clock enabled in the hardware?
  383. * @hw: struct clk_hw * to check
  384. *
  385. * Return 1 if the clock represented by @hw is enabled in the
  386. * hardware, or 0 otherwise. Intended for use in the struct
  387. * clk_ops.is_enabled function pointer.
  388. */
  389. int omap2_dflt_clk_is_enabled(struct clk_hw *hw)
  390. {
  391. struct clk_hw_omap *clk = to_clk_hw_omap(hw);
  392. u32 v;
  393. v = __raw_readl(clk->enable_reg);
  394. if (clk->flags & INVERT_ENABLE)
  395. v ^= BIT(clk->enable_bit);
  396. v &= BIT(clk->enable_bit);
  397. return v ? 1 : 0;
  398. }
  399. static int __initdata mpurate;
  400. /*
  401. * By default we use the rate set by the bootloader.
  402. * You can override this with mpurate= cmdline option.
  403. */
  404. static int __init omap_clk_setup(char *str)
  405. {
  406. get_option(&str, &mpurate);
  407. if (!mpurate)
  408. return 1;
  409. if (mpurate < 1000)
  410. mpurate *= 1000000;
  411. return 1;
  412. }
  413. __setup("mpurate=", omap_clk_setup);
  414. /**
  415. * omap2_init_clk_hw_omap_clocks - initialize an OMAP clock
  416. * @clk: struct clk * to initialize
  417. *
  418. * Add an OMAP clock @clk to the internal list of OMAP clocks. Used
  419. * temporarily for autoidle handling, until this support can be
  420. * integrated into the common clock framework code in some way. No
  421. * return value.
  422. */
  423. void omap2_init_clk_hw_omap_clocks(struct clk *clk)
  424. {
  425. struct clk_hw_omap *c;
  426. if (__clk_get_flags(clk) & CLK_IS_BASIC)
  427. return;
  428. c = to_clk_hw_omap(__clk_get_hw(clk));
  429. list_add(&c->node, &clk_hw_omap_clocks);
  430. }
  431. /**
  432. * omap2_clk_enable_autoidle_all - enable autoidle on all OMAP clocks that
  433. * support it
  434. *
  435. * Enable clock autoidle on all OMAP clocks that have allow_idle
  436. * function pointers associated with them. This function is intended
  437. * to be temporary until support for this is added to the common clock
  438. * code. Returns 0.
  439. */
  440. int omap2_clk_enable_autoidle_all(void)
  441. {
  442. struct clk_hw_omap *c;
  443. list_for_each_entry(c, &clk_hw_omap_clocks, node)
  444. if (c->ops && c->ops->allow_idle)
  445. c->ops->allow_idle(c);
  446. return 0;
  447. }
  448. /**
  449. * omap2_clk_disable_autoidle_all - disable autoidle on all OMAP clocks that
  450. * support it
  451. *
  452. * Disable clock autoidle on all OMAP clocks that have allow_idle
  453. * function pointers associated with them. This function is intended
  454. * to be temporary until support for this is added to the common clock
  455. * code. Returns 0.
  456. */
  457. int omap2_clk_disable_autoidle_all(void)
  458. {
  459. struct clk_hw_omap *c;
  460. list_for_each_entry(c, &clk_hw_omap_clocks, node)
  461. if (c->ops && c->ops->deny_idle)
  462. c->ops->deny_idle(c);
  463. return 0;
  464. }
  465. /**
  466. * omap2_clk_enable_init_clocks - prepare & enable a list of clocks
  467. * @clk_names: ptr to an array of strings of clock names to enable
  468. * @num_clocks: number of clock names in @clk_names
  469. *
  470. * Prepare and enable a list of clocks, named by @clk_names. No
  471. * return value. XXX Deprecated; only needed until these clocks are
  472. * properly claimed and enabled by the drivers or core code that uses
  473. * them. XXX What code disables & calls clk_put on these clocks?
  474. */
  475. void omap2_clk_enable_init_clocks(const char **clk_names, u8 num_clocks)
  476. {
  477. struct clk *init_clk;
  478. int i;
  479. for (i = 0; i < num_clocks; i++) {
  480. init_clk = clk_get(NULL, clk_names[i]);
  481. clk_prepare_enable(init_clk);
  482. }
  483. }
  484. const struct clk_hw_omap_ops clkhwops_wait = {
  485. .find_idlest = omap2_clk_dflt_find_idlest,
  486. .find_companion = omap2_clk_dflt_find_companion,
  487. };
  488. /**
  489. * omap_clocks_register - register an array of omap_clk
  490. * @ocs: pointer to an array of omap_clk to register
  491. */
  492. void __init omap_clocks_register(struct omap_clk oclks[], int cnt)
  493. {
  494. struct omap_clk *c;
  495. for (c = oclks; c < oclks + cnt; c++) {
  496. clkdev_add(&c->lk);
  497. if (!__clk_init(NULL, c->lk.clk))
  498. omap2_init_clk_hw_omap_clocks(c->lk.clk);
  499. }
  500. }
  501. /**
  502. * omap2_clk_switch_mpurate_at_boot - switch ARM MPU rate by boot-time argument
  503. * @mpurate_ck_name: clk name of the clock to change rate
  504. *
  505. * Change the ARM MPU clock rate to the rate specified on the command
  506. * line, if one was specified. @mpurate_ck_name should be
  507. * "virt_prcm_set" on OMAP2xxx and "dpll1_ck" on OMAP34xx/OMAP36xx.
  508. * XXX Does not handle voltage scaling - on OMAP2xxx this is currently
  509. * handled by the virt_prcm_set clock, but this should be handled by
  510. * the OPP layer. XXX This is intended to be handled by the OPP layer
  511. * code in the near future and should be removed from the clock code.
  512. * Returns -EINVAL if 'mpurate' is zero or if clk_set_rate() rejects
  513. * the rate, -ENOENT if the struct clk referred to by @mpurate_ck_name
  514. * cannot be found, or 0 upon success.
  515. */
  516. int __init omap2_clk_switch_mpurate_at_boot(const char *mpurate_ck_name)
  517. {
  518. struct clk *mpurate_ck;
  519. int r;
  520. if (!mpurate)
  521. return -EINVAL;
  522. mpurate_ck = clk_get(NULL, mpurate_ck_name);
  523. if (WARN(IS_ERR(mpurate_ck), "Failed to get %s.\n", mpurate_ck_name))
  524. return -ENOENT;
  525. r = clk_set_rate(mpurate_ck, mpurate);
  526. if (r < 0) {
  527. WARN(1, "clock: %s: unable to set MPU rate to %d: %d\n",
  528. mpurate_ck_name, mpurate, r);
  529. clk_put(mpurate_ck);
  530. return -EINVAL;
  531. }
  532. calibrate_delay();
  533. clk_put(mpurate_ck);
  534. return 0;
  535. }
  536. /**
  537. * omap2_clk_print_new_rates - print summary of current clock tree rates
  538. * @hfclkin_ck_name: clk name for the off-chip HF oscillator
  539. * @core_ck_name: clk name for the on-chip CORE_CLK
  540. * @mpu_ck_name: clk name for the ARM MPU clock
  541. *
  542. * Prints a short message to the console with the HFCLKIN oscillator
  543. * rate, the rate of the CORE clock, and the rate of the ARM MPU clock.
  544. * Called by the boot-time MPU rate switching code. XXX This is intended
  545. * to be handled by the OPP layer code in the near future and should be
  546. * removed from the clock code. No return value.
  547. */
  548. void __init omap2_clk_print_new_rates(const char *hfclkin_ck_name,
  549. const char *core_ck_name,
  550. const char *mpu_ck_name)
  551. {
  552. struct clk *hfclkin_ck, *core_ck, *mpu_ck;
  553. unsigned long hfclkin_rate;
  554. mpu_ck = clk_get(NULL, mpu_ck_name);
  555. if (WARN(IS_ERR(mpu_ck), "clock: failed to get %s.\n", mpu_ck_name))
  556. return;
  557. core_ck = clk_get(NULL, core_ck_name);
  558. if (WARN(IS_ERR(core_ck), "clock: failed to get %s.\n", core_ck_name))
  559. return;
  560. hfclkin_ck = clk_get(NULL, hfclkin_ck_name);
  561. if (WARN(IS_ERR(hfclkin_ck), "Failed to get %s.\n", hfclkin_ck_name))
  562. return;
  563. hfclkin_rate = clk_get_rate(hfclkin_ck);
  564. pr_info("Switched to new clocking rate (Crystal/Core/MPU): %ld.%01ld/%ld/%ld MHz\n",
  565. (hfclkin_rate / 1000000), ((hfclkin_rate / 100000) % 10),
  566. (clk_get_rate(core_ck) / 1000000),
  567. (clk_get_rate(mpu_ck) / 1000000));
  568. }