clock.c 24 KB

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