clock.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774
  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. * Clock features setup. Used instead of CPU type checks.
  45. */
  46. struct ti_clk_features ti_clk_features;
  47. /* DPLL valid Fint frequency band limits - from 34xx TRM Section 4.7.6.2 */
  48. #define OMAP3430_DPLL_FINT_BAND1_MIN 750000
  49. #define OMAP3430_DPLL_FINT_BAND1_MAX 2100000
  50. #define OMAP3430_DPLL_FINT_BAND2_MIN 7500000
  51. #define OMAP3430_DPLL_FINT_BAND2_MAX 21000000
  52. /*
  53. * DPLL valid Fint frequency range for OMAP36xx and OMAP4xxx.
  54. * From device data manual section 4.3 "DPLL and DLL Specifications".
  55. */
  56. #define OMAP3PLUS_DPLL_FINT_MIN 32000
  57. #define OMAP3PLUS_DPLL_FINT_MAX 52000000
  58. /*
  59. * clkdm_control: if true, then when a clock is enabled in the
  60. * hardware, its clockdomain will first be enabled; and when a clock
  61. * is disabled in the hardware, its clockdomain will be disabled
  62. * afterwards.
  63. */
  64. static bool clkdm_control = true;
  65. static LIST_HEAD(clk_hw_omap_clocks);
  66. void __iomem *clk_memmaps[CLK_MAX_MEMMAPS];
  67. void omap2_clk_writel(u32 val, struct clk_hw_omap *clk, void __iomem *reg)
  68. {
  69. if (clk->flags & MEMMAP_ADDRESSING) {
  70. struct clk_omap_reg *r = (struct clk_omap_reg *)&reg;
  71. writel_relaxed(val, clk_memmaps[r->index] + r->offset);
  72. } else {
  73. writel_relaxed(val, reg);
  74. }
  75. }
  76. u32 omap2_clk_readl(struct clk_hw_omap *clk, void __iomem *reg)
  77. {
  78. u32 val;
  79. if (clk->flags & MEMMAP_ADDRESSING) {
  80. struct clk_omap_reg *r = (struct clk_omap_reg *)&reg;
  81. val = readl_relaxed(clk_memmaps[r->index] + r->offset);
  82. } else {
  83. val = readl_relaxed(reg);
  84. }
  85. return val;
  86. }
  87. /*
  88. * OMAP2+ specific clock functions
  89. */
  90. /* Private functions */
  91. /**
  92. * _wait_idlest_generic - wait for a module to leave the idle state
  93. * @clk: module clock to wait for (needed for register offsets)
  94. * @reg: virtual address of module IDLEST register
  95. * @mask: value to mask against to determine if the module is active
  96. * @idlest: idle state indicator (0 or 1) for the clock
  97. * @name: name of the clock (for printk)
  98. *
  99. * Wait for a module to leave idle, where its idle-status register is
  100. * not inside the CM module. Returns 1 if the module left idle
  101. * promptly, or 0 if the module did not leave idle before the timeout
  102. * elapsed. XXX Deprecated - should be moved into drivers for the
  103. * individual IP block that the IDLEST register exists in.
  104. */
  105. static int _wait_idlest_generic(struct clk_hw_omap *clk, void __iomem *reg,
  106. u32 mask, u8 idlest, const char *name)
  107. {
  108. int i = 0, ena = 0;
  109. ena = (idlest) ? 0 : mask;
  110. omap_test_timeout(((omap2_clk_readl(clk, reg) & mask) == ena),
  111. MAX_MODULE_ENABLE_WAIT, i);
  112. if (i < MAX_MODULE_ENABLE_WAIT)
  113. pr_debug("omap clock: module associated with clock %s ready after %d loops\n",
  114. name, i);
  115. else
  116. pr_err("omap clock: module associated with clock %s didn't enable in %d tries\n",
  117. name, MAX_MODULE_ENABLE_WAIT);
  118. return (i < MAX_MODULE_ENABLE_WAIT) ? 1 : 0;
  119. };
  120. /**
  121. * _omap2_module_wait_ready - wait for an OMAP module to leave IDLE
  122. * @clk: struct clk * belonging to the module
  123. *
  124. * If the necessary clocks for the OMAP hardware IP block that
  125. * corresponds to clock @clk are enabled, then wait for the module to
  126. * indicate readiness (i.e., to leave IDLE). This code does not
  127. * belong in the clock code and will be moved in the medium term to
  128. * module-dependent code. No return value.
  129. */
  130. static void _omap2_module_wait_ready(struct clk_hw_omap *clk)
  131. {
  132. void __iomem *companion_reg, *idlest_reg;
  133. u8 other_bit, idlest_bit, idlest_val, idlest_reg_id;
  134. s16 prcm_mod;
  135. int r;
  136. /* Not all modules have multiple clocks that their IDLEST depends on */
  137. if (clk->ops->find_companion) {
  138. clk->ops->find_companion(clk, &companion_reg, &other_bit);
  139. if (!(omap2_clk_readl(clk, companion_reg) & (1 << other_bit)))
  140. return;
  141. }
  142. clk->ops->find_idlest(clk, &idlest_reg, &idlest_bit, &idlest_val);
  143. r = cm_split_idlest_reg(idlest_reg, &prcm_mod, &idlest_reg_id);
  144. if (r) {
  145. /* IDLEST register not in the CM module */
  146. _wait_idlest_generic(clk, idlest_reg, (1 << idlest_bit),
  147. idlest_val, __clk_get_name(clk->hw.clk));
  148. } else {
  149. cm_wait_module_ready(prcm_mod, idlest_reg_id, idlest_bit);
  150. };
  151. }
  152. /* Public functions */
  153. /**
  154. * omap2_init_clk_clkdm - look up a clockdomain name, store pointer in clk
  155. * @clk: OMAP clock struct ptr to use
  156. *
  157. * Convert a clockdomain name stored in a struct clk 'clk' into a
  158. * clockdomain pointer, and save it into the struct clk. Intended to be
  159. * called during clk_register(). No return value.
  160. */
  161. void omap2_init_clk_clkdm(struct clk_hw *hw)
  162. {
  163. struct clk_hw_omap *clk = to_clk_hw_omap(hw);
  164. struct clockdomain *clkdm;
  165. const char *clk_name;
  166. if (!clk->clkdm_name)
  167. return;
  168. clk_name = __clk_get_name(hw->clk);
  169. clkdm = clkdm_lookup(clk->clkdm_name);
  170. if (clkdm) {
  171. pr_debug("clock: associated clk %s to clkdm %s\n",
  172. clk_name, clk->clkdm_name);
  173. clk->clkdm = clkdm;
  174. } else {
  175. pr_debug("clock: could not associate clk %s to clkdm %s\n",
  176. clk_name, clk->clkdm_name);
  177. }
  178. }
  179. /**
  180. * omap2_clk_disable_clkdm_control - disable clkdm control on clk enable/disable
  181. *
  182. * Prevent the OMAP clock code from calling into the clockdomain code
  183. * when a hardware clock in that clockdomain is enabled or disabled.
  184. * Intended to be called at init time from omap*_clk_init(). No
  185. * return value.
  186. */
  187. void __init omap2_clk_disable_clkdm_control(void)
  188. {
  189. clkdm_control = false;
  190. }
  191. /**
  192. * omap2_clk_dflt_find_companion - find companion clock to @clk
  193. * @clk: struct clk * to find the companion clock of
  194. * @other_reg: void __iomem ** to return the companion clock CM_*CLKEN va in
  195. * @other_bit: u8 ** to return the companion clock bit shift in
  196. *
  197. * Note: We don't need special code here for INVERT_ENABLE for the
  198. * time being since INVERT_ENABLE only applies to clocks enabled by
  199. * CM_CLKEN_PLL
  200. *
  201. * Convert CM_ICLKEN* <-> CM_FCLKEN*. This conversion assumes it's
  202. * just a matter of XORing the bits.
  203. *
  204. * Some clocks don't have companion clocks. For example, modules with
  205. * only an interface clock (such as MAILBOXES) don't have a companion
  206. * clock. Right now, this code relies on the hardware exporting a bit
  207. * in the correct companion register that indicates that the
  208. * nonexistent 'companion clock' is active. Future patches will
  209. * associate this type of code with per-module data structures to
  210. * avoid this issue, and remove the casts. No return value.
  211. */
  212. void omap2_clk_dflt_find_companion(struct clk_hw_omap *clk,
  213. void __iomem **other_reg, u8 *other_bit)
  214. {
  215. u32 r;
  216. /*
  217. * Convert CM_ICLKEN* <-> CM_FCLKEN*. This conversion assumes
  218. * it's just a matter of XORing the bits.
  219. */
  220. r = ((__force u32)clk->enable_reg ^ (CM_FCLKEN ^ CM_ICLKEN));
  221. *other_reg = (__force void __iomem *)r;
  222. *other_bit = clk->enable_bit;
  223. }
  224. /**
  225. * omap2_clk_dflt_find_idlest - find CM_IDLEST reg va, bit shift for @clk
  226. * @clk: struct clk * to find IDLEST info for
  227. * @idlest_reg: void __iomem ** to return the CM_IDLEST va in
  228. * @idlest_bit: u8 * to return the CM_IDLEST bit shift in
  229. * @idlest_val: u8 * to return the idle status indicator
  230. *
  231. * Return the CM_IDLEST register address and bit shift corresponding
  232. * to the module that "owns" this clock. This default code assumes
  233. * that the CM_IDLEST bit shift is the CM_*CLKEN bit shift, and that
  234. * the IDLEST register address ID corresponds to the CM_*CLKEN
  235. * register address ID (e.g., that CM_FCLKEN2 corresponds to
  236. * CM_IDLEST2). This is not true for all modules. No return value.
  237. */
  238. void omap2_clk_dflt_find_idlest(struct clk_hw_omap *clk,
  239. void __iomem **idlest_reg, u8 *idlest_bit, u8 *idlest_val)
  240. {
  241. u32 r;
  242. r = (((__force u32)clk->enable_reg & ~0xf0) | 0x20);
  243. *idlest_reg = (__force void __iomem *)r;
  244. *idlest_bit = clk->enable_bit;
  245. /*
  246. * 24xx uses 0 to indicate not ready, and 1 to indicate ready.
  247. * 34xx reverses this, just to keep us on our toes
  248. * AM35xx uses both, depending on the module.
  249. */
  250. *idlest_val = ti_clk_features.cm_idlest_val;
  251. }
  252. /**
  253. * omap2_dflt_clk_enable - enable a clock in the hardware
  254. * @hw: struct clk_hw * of the clock to enable
  255. *
  256. * Enable the clock @hw in the hardware. We first call into the OMAP
  257. * clockdomain code to "enable" the corresponding clockdomain if this
  258. * is the first enabled user of the clockdomain. Then program the
  259. * hardware to enable the clock. Then wait for the IP block that uses
  260. * this clock to leave idle (if applicable). Returns the error value
  261. * from clkdm_clk_enable() if it terminated with an error, or -EINVAL
  262. * if @hw has a null clock enable_reg, or zero upon success.
  263. */
  264. int omap2_dflt_clk_enable(struct clk_hw *hw)
  265. {
  266. struct clk_hw_omap *clk;
  267. u32 v;
  268. int ret = 0;
  269. clk = to_clk_hw_omap(hw);
  270. if (clkdm_control && clk->clkdm) {
  271. ret = clkdm_clk_enable(clk->clkdm, hw->clk);
  272. if (ret) {
  273. WARN(1, "%s: could not enable %s's clockdomain %s: %d\n",
  274. __func__, __clk_get_name(hw->clk),
  275. clk->clkdm->name, ret);
  276. return ret;
  277. }
  278. }
  279. if (unlikely(clk->enable_reg == NULL)) {
  280. pr_err("%s: %s missing enable_reg\n", __func__,
  281. __clk_get_name(hw->clk));
  282. ret = -EINVAL;
  283. goto err;
  284. }
  285. /* FIXME should not have INVERT_ENABLE bit here */
  286. v = omap2_clk_readl(clk, clk->enable_reg);
  287. if (clk->flags & INVERT_ENABLE)
  288. v &= ~(1 << clk->enable_bit);
  289. else
  290. v |= (1 << clk->enable_bit);
  291. omap2_clk_writel(v, clk, clk->enable_reg);
  292. v = omap2_clk_readl(clk, clk->enable_reg); /* OCP barrier */
  293. if (clk->ops && clk->ops->find_idlest)
  294. _omap2_module_wait_ready(clk);
  295. return 0;
  296. err:
  297. if (clkdm_control && clk->clkdm)
  298. clkdm_clk_disable(clk->clkdm, hw->clk);
  299. return ret;
  300. }
  301. /**
  302. * omap2_dflt_clk_disable - disable a clock in the hardware
  303. * @hw: struct clk_hw * of the clock to disable
  304. *
  305. * Disable the clock @hw in the hardware, and call into the OMAP
  306. * clockdomain code to "disable" the corresponding clockdomain if all
  307. * clocks/hwmods in that clockdomain are now disabled. No return
  308. * value.
  309. */
  310. void omap2_dflt_clk_disable(struct clk_hw *hw)
  311. {
  312. struct clk_hw_omap *clk;
  313. u32 v;
  314. clk = to_clk_hw_omap(hw);
  315. if (!clk->enable_reg) {
  316. /*
  317. * 'independent' here refers to a clock which is not
  318. * controlled by its parent.
  319. */
  320. pr_err("%s: independent clock %s has no enable_reg\n",
  321. __func__, __clk_get_name(hw->clk));
  322. return;
  323. }
  324. v = omap2_clk_readl(clk, clk->enable_reg);
  325. if (clk->flags & INVERT_ENABLE)
  326. v |= (1 << clk->enable_bit);
  327. else
  328. v &= ~(1 << clk->enable_bit);
  329. omap2_clk_writel(v, clk, clk->enable_reg);
  330. /* No OCP barrier needed here since it is a disable operation */
  331. if (clkdm_control && clk->clkdm)
  332. clkdm_clk_disable(clk->clkdm, hw->clk);
  333. }
  334. /**
  335. * omap2_clkops_enable_clkdm - increment usecount on clkdm of @hw
  336. * @hw: struct clk_hw * of the clock being enabled
  337. *
  338. * Increment the usecount of the clockdomain of the clock pointed to
  339. * by @hw; if the usecount is 1, the clockdomain will be "enabled."
  340. * Only needed for clocks that don't use omap2_dflt_clk_enable() as
  341. * their enable function pointer. Passes along the return value of
  342. * clkdm_clk_enable(), -EINVAL if @hw is not associated with a
  343. * clockdomain, or 0 if clock framework-based clockdomain control is
  344. * not implemented.
  345. */
  346. int omap2_clkops_enable_clkdm(struct clk_hw *hw)
  347. {
  348. struct clk_hw_omap *clk;
  349. int ret = 0;
  350. clk = to_clk_hw_omap(hw);
  351. if (unlikely(!clk->clkdm)) {
  352. pr_err("%s: %s: no clkdm set ?!\n", __func__,
  353. __clk_get_name(hw->clk));
  354. return -EINVAL;
  355. }
  356. if (unlikely(clk->enable_reg))
  357. pr_err("%s: %s: should use dflt_clk_enable ?!\n", __func__,
  358. __clk_get_name(hw->clk));
  359. if (!clkdm_control) {
  360. pr_err("%s: %s: clkfw-based clockdomain control disabled ?!\n",
  361. __func__, __clk_get_name(hw->clk));
  362. return 0;
  363. }
  364. ret = clkdm_clk_enable(clk->clkdm, hw->clk);
  365. WARN(ret, "%s: could not enable %s's clockdomain %s: %d\n",
  366. __func__, __clk_get_name(hw->clk), clk->clkdm->name, ret);
  367. return ret;
  368. }
  369. /**
  370. * omap2_clkops_disable_clkdm - decrement usecount on clkdm of @hw
  371. * @hw: struct clk_hw * of the clock being disabled
  372. *
  373. * Decrement the usecount of the clockdomain of the clock pointed to
  374. * by @hw; if the usecount is 0, the clockdomain will be "disabled."
  375. * Only needed for clocks that don't use omap2_dflt_clk_disable() as their
  376. * disable function pointer. No return value.
  377. */
  378. void omap2_clkops_disable_clkdm(struct clk_hw *hw)
  379. {
  380. struct clk_hw_omap *clk;
  381. clk = to_clk_hw_omap(hw);
  382. if (unlikely(!clk->clkdm)) {
  383. pr_err("%s: %s: no clkdm set ?!\n", __func__,
  384. __clk_get_name(hw->clk));
  385. return;
  386. }
  387. if (unlikely(clk->enable_reg))
  388. pr_err("%s: %s: should use dflt_clk_disable ?!\n", __func__,
  389. __clk_get_name(hw->clk));
  390. if (!clkdm_control) {
  391. pr_err("%s: %s: clkfw-based clockdomain control disabled ?!\n",
  392. __func__, __clk_get_name(hw->clk));
  393. return;
  394. }
  395. clkdm_clk_disable(clk->clkdm, hw->clk);
  396. }
  397. /**
  398. * omap2_dflt_clk_is_enabled - is clock enabled in the hardware?
  399. * @hw: struct clk_hw * to check
  400. *
  401. * Return 1 if the clock represented by @hw is enabled in the
  402. * hardware, or 0 otherwise. Intended for use in the struct
  403. * clk_ops.is_enabled function pointer.
  404. */
  405. int omap2_dflt_clk_is_enabled(struct clk_hw *hw)
  406. {
  407. struct clk_hw_omap *clk = to_clk_hw_omap(hw);
  408. u32 v;
  409. v = omap2_clk_readl(clk, clk->enable_reg);
  410. if (clk->flags & INVERT_ENABLE)
  411. v ^= BIT(clk->enable_bit);
  412. v &= BIT(clk->enable_bit);
  413. return v ? 1 : 0;
  414. }
  415. static int __initdata mpurate;
  416. /*
  417. * By default we use the rate set by the bootloader.
  418. * You can override this with mpurate= cmdline option.
  419. */
  420. static int __init omap_clk_setup(char *str)
  421. {
  422. get_option(&str, &mpurate);
  423. if (!mpurate)
  424. return 1;
  425. if (mpurate < 1000)
  426. mpurate *= 1000000;
  427. return 1;
  428. }
  429. __setup("mpurate=", omap_clk_setup);
  430. /**
  431. * omap2_init_clk_hw_omap_clocks - initialize an OMAP clock
  432. * @clk: struct clk * to initialize
  433. *
  434. * Add an OMAP clock @clk to the internal list of OMAP clocks. Used
  435. * temporarily for autoidle handling, until this support can be
  436. * integrated into the common clock framework code in some way. No
  437. * return value.
  438. */
  439. void omap2_init_clk_hw_omap_clocks(struct clk *clk)
  440. {
  441. struct clk_hw_omap *c;
  442. if (__clk_get_flags(clk) & CLK_IS_BASIC)
  443. return;
  444. c = to_clk_hw_omap(__clk_get_hw(clk));
  445. list_add(&c->node, &clk_hw_omap_clocks);
  446. }
  447. /**
  448. * omap2_clk_enable_autoidle_all - enable autoidle on all OMAP clocks that
  449. * support it
  450. *
  451. * Enable clock autoidle on all OMAP clocks that have allow_idle
  452. * function pointers associated with them. This function is intended
  453. * to be temporary until support for this is added to the common clock
  454. * code. Returns 0.
  455. */
  456. int omap2_clk_enable_autoidle_all(void)
  457. {
  458. struct clk_hw_omap *c;
  459. list_for_each_entry(c, &clk_hw_omap_clocks, node)
  460. if (c->ops && c->ops->allow_idle)
  461. c->ops->allow_idle(c);
  462. of_ti_clk_allow_autoidle_all();
  463. return 0;
  464. }
  465. /**
  466. * omap2_clk_disable_autoidle_all - disable autoidle on all OMAP clocks that
  467. * support it
  468. *
  469. * Disable clock autoidle on all OMAP clocks that have allow_idle
  470. * function pointers associated with them. This function is intended
  471. * to be temporary until support for this is added to the common clock
  472. * code. Returns 0.
  473. */
  474. int omap2_clk_disable_autoidle_all(void)
  475. {
  476. struct clk_hw_omap *c;
  477. list_for_each_entry(c, &clk_hw_omap_clocks, node)
  478. if (c->ops && c->ops->deny_idle)
  479. c->ops->deny_idle(c);
  480. of_ti_clk_deny_autoidle_all();
  481. return 0;
  482. }
  483. /**
  484. * omap2_clk_deny_idle - disable autoidle on an OMAP clock
  485. * @clk: struct clk * to disable autoidle for
  486. *
  487. * Disable autoidle on an OMAP clock.
  488. */
  489. int omap2_clk_deny_idle(struct clk *clk)
  490. {
  491. struct clk_hw_omap *c;
  492. if (__clk_get_flags(clk) & CLK_IS_BASIC)
  493. return -EINVAL;
  494. c = to_clk_hw_omap(__clk_get_hw(clk));
  495. if (c->ops && c->ops->deny_idle)
  496. c->ops->deny_idle(c);
  497. return 0;
  498. }
  499. /**
  500. * omap2_clk_allow_idle - enable autoidle on an OMAP clock
  501. * @clk: struct clk * to enable autoidle for
  502. *
  503. * Enable autoidle on an OMAP clock.
  504. */
  505. int omap2_clk_allow_idle(struct clk *clk)
  506. {
  507. struct clk_hw_omap *c;
  508. if (__clk_get_flags(clk) & CLK_IS_BASIC)
  509. return -EINVAL;
  510. c = to_clk_hw_omap(__clk_get_hw(clk));
  511. if (c->ops && c->ops->allow_idle)
  512. c->ops->allow_idle(c);
  513. return 0;
  514. }
  515. /**
  516. * omap2_clk_enable_init_clocks - prepare & enable a list of clocks
  517. * @clk_names: ptr to an array of strings of clock names to enable
  518. * @num_clocks: number of clock names in @clk_names
  519. *
  520. * Prepare and enable a list of clocks, named by @clk_names. No
  521. * return value. XXX Deprecated; only needed until these clocks are
  522. * properly claimed and enabled by the drivers or core code that uses
  523. * them. XXX What code disables & calls clk_put on these clocks?
  524. */
  525. void omap2_clk_enable_init_clocks(const char **clk_names, u8 num_clocks)
  526. {
  527. struct clk *init_clk;
  528. int i;
  529. for (i = 0; i < num_clocks; i++) {
  530. init_clk = clk_get(NULL, clk_names[i]);
  531. clk_prepare_enable(init_clk);
  532. }
  533. }
  534. const struct clk_hw_omap_ops clkhwops_wait = {
  535. .find_idlest = omap2_clk_dflt_find_idlest,
  536. .find_companion = omap2_clk_dflt_find_companion,
  537. };
  538. /**
  539. * omap_clocks_register - register an array of omap_clk
  540. * @ocs: pointer to an array of omap_clk to register
  541. */
  542. void __init omap_clocks_register(struct omap_clk oclks[], int cnt)
  543. {
  544. struct omap_clk *c;
  545. for (c = oclks; c < oclks + cnt; c++) {
  546. clkdev_add(&c->lk);
  547. if (!__clk_init(NULL, c->lk.clk))
  548. omap2_init_clk_hw_omap_clocks(c->lk.clk);
  549. }
  550. }
  551. /**
  552. * omap2_clk_switch_mpurate_at_boot - switch ARM MPU rate by boot-time argument
  553. * @mpurate_ck_name: clk name of the clock to change rate
  554. *
  555. * Change the ARM MPU clock rate to the rate specified on the command
  556. * line, if one was specified. @mpurate_ck_name should be
  557. * "virt_prcm_set" on OMAP2xxx and "dpll1_ck" on OMAP34xx/OMAP36xx.
  558. * XXX Does not handle voltage scaling - on OMAP2xxx this is currently
  559. * handled by the virt_prcm_set clock, but this should be handled by
  560. * the OPP layer. XXX This is intended to be handled by the OPP layer
  561. * code in the near future and should be removed from the clock code.
  562. * Returns -EINVAL if 'mpurate' is zero or if clk_set_rate() rejects
  563. * the rate, -ENOENT if the struct clk referred to by @mpurate_ck_name
  564. * cannot be found, or 0 upon success.
  565. */
  566. int __init omap2_clk_switch_mpurate_at_boot(const char *mpurate_ck_name)
  567. {
  568. struct clk *mpurate_ck;
  569. int r;
  570. if (!mpurate)
  571. return -EINVAL;
  572. mpurate_ck = clk_get(NULL, mpurate_ck_name);
  573. if (WARN(IS_ERR(mpurate_ck), "Failed to get %s.\n", mpurate_ck_name))
  574. return -ENOENT;
  575. r = clk_set_rate(mpurate_ck, mpurate);
  576. if (r < 0) {
  577. WARN(1, "clock: %s: unable to set MPU rate to %d: %d\n",
  578. mpurate_ck_name, mpurate, r);
  579. clk_put(mpurate_ck);
  580. return -EINVAL;
  581. }
  582. calibrate_delay();
  583. clk_put(mpurate_ck);
  584. return 0;
  585. }
  586. /**
  587. * omap2_clk_print_new_rates - print summary of current clock tree rates
  588. * @hfclkin_ck_name: clk name for the off-chip HF oscillator
  589. * @core_ck_name: clk name for the on-chip CORE_CLK
  590. * @mpu_ck_name: clk name for the ARM MPU clock
  591. *
  592. * Prints a short message to the console with the HFCLKIN oscillator
  593. * rate, the rate of the CORE clock, and the rate of the ARM MPU clock.
  594. * Called by the boot-time MPU rate switching code. XXX This is intended
  595. * to be handled by the OPP layer code in the near future and should be
  596. * removed from the clock code. No return value.
  597. */
  598. void __init omap2_clk_print_new_rates(const char *hfclkin_ck_name,
  599. const char *core_ck_name,
  600. const char *mpu_ck_name)
  601. {
  602. struct clk *hfclkin_ck, *core_ck, *mpu_ck;
  603. unsigned long hfclkin_rate;
  604. mpu_ck = clk_get(NULL, mpu_ck_name);
  605. if (WARN(IS_ERR(mpu_ck), "clock: failed to get %s.\n", mpu_ck_name))
  606. return;
  607. core_ck = clk_get(NULL, core_ck_name);
  608. if (WARN(IS_ERR(core_ck), "clock: failed to get %s.\n", core_ck_name))
  609. return;
  610. hfclkin_ck = clk_get(NULL, hfclkin_ck_name);
  611. if (WARN(IS_ERR(hfclkin_ck), "Failed to get %s.\n", hfclkin_ck_name))
  612. return;
  613. hfclkin_rate = clk_get_rate(hfclkin_ck);
  614. pr_info("Switched to new clocking rate (Crystal/Core/MPU): %ld.%01ld/%ld/%ld MHz\n",
  615. (hfclkin_rate / 1000000), ((hfclkin_rate / 100000) % 10),
  616. (clk_get_rate(core_ck) / 1000000),
  617. (clk_get_rate(mpu_ck) / 1000000));
  618. }
  619. /**
  620. * ti_clk_init_features - init clock features struct for the SoC
  621. *
  622. * Initializes the clock features struct based on the SoC type.
  623. */
  624. void __init ti_clk_init_features(void)
  625. {
  626. /* Fint setup for DPLLs */
  627. if (cpu_is_omap3430()) {
  628. ti_clk_features.fint_min = OMAP3430_DPLL_FINT_BAND1_MIN;
  629. ti_clk_features.fint_max = OMAP3430_DPLL_FINT_BAND2_MAX;
  630. ti_clk_features.fint_band1_max = OMAP3430_DPLL_FINT_BAND1_MAX;
  631. ti_clk_features.fint_band2_min = OMAP3430_DPLL_FINT_BAND2_MIN;
  632. } else {
  633. ti_clk_features.fint_min = OMAP3PLUS_DPLL_FINT_MIN;
  634. ti_clk_features.fint_max = OMAP3PLUS_DPLL_FINT_MAX;
  635. }
  636. /* Bypass value setup for DPLLs */
  637. if (cpu_is_omap24xx()) {
  638. ti_clk_features.dpll_bypass_vals |=
  639. (1 << OMAP2XXX_EN_DPLL_LPBYPASS) |
  640. (1 << OMAP2XXX_EN_DPLL_FRBYPASS);
  641. } else if (cpu_is_omap34xx()) {
  642. ti_clk_features.dpll_bypass_vals |=
  643. (1 << OMAP3XXX_EN_DPLL_LPBYPASS) |
  644. (1 << OMAP3XXX_EN_DPLL_FRBYPASS);
  645. } else if (soc_is_am33xx() || cpu_is_omap44xx() || soc_is_am43xx() ||
  646. soc_is_omap54xx() || soc_is_dra7xx()) {
  647. ti_clk_features.dpll_bypass_vals |=
  648. (1 << OMAP4XXX_EN_DPLL_LPBYPASS) |
  649. (1 << OMAP4XXX_EN_DPLL_FRBYPASS) |
  650. (1 << OMAP4XXX_EN_DPLL_MNBYPASS);
  651. }
  652. /* Jitter correction only available on OMAP343X */
  653. if (cpu_is_omap343x())
  654. ti_clk_features.flags |= TI_CLK_DPLL_HAS_FREQSEL;
  655. /* Idlest value for interface clocks.
  656. * 24xx uses 0 to indicate not ready, and 1 to indicate ready.
  657. * 34xx reverses this, just to keep us on our toes
  658. * AM35xx uses both, depending on the module.
  659. */
  660. if (cpu_is_omap24xx())
  661. ti_clk_features.cm_idlest_val = OMAP24XX_CM_IDLEST_VAL;
  662. else if (cpu_is_omap34xx())
  663. ti_clk_features.cm_idlest_val = OMAP34XX_CM_IDLEST_VAL;
  664. }