dpll3xxx.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756
  1. /*
  2. * OMAP3/4 - specific DPLL control functions
  3. *
  4. * Copyright (C) 2009-2010 Texas Instruments, Inc.
  5. * Copyright (C) 2009-2010 Nokia Corporation
  6. *
  7. * Written by Paul Walmsley
  8. * Testing and integration fixes by Jouni Högander
  9. *
  10. * 36xx support added by Vishwanath BS, Richard Woodruff, and Nishanth
  11. * Menon
  12. *
  13. * Parts of this code are based on code written by
  14. * Richard Woodruff, Tony Lindgren, Tuukka Tikkanen, Karthik Dasu
  15. *
  16. * This program is free software; you can redistribute it and/or modify
  17. * it under the terms of the GNU General Public License version 2 as
  18. * published by the Free Software Foundation.
  19. */
  20. #include <linux/kernel.h>
  21. #include <linux/device.h>
  22. #include <linux/list.h>
  23. #include <linux/errno.h>
  24. #include <linux/delay.h>
  25. #include <linux/clk.h>
  26. #include <linux/io.h>
  27. #include <linux/bitops.h>
  28. #include <linux/clkdev.h>
  29. #include "clockdomain.h"
  30. #include "clock.h"
  31. /* CM_AUTOIDLE_PLL*.AUTO_* bit values */
  32. #define DPLL_AUTOIDLE_DISABLE 0x0
  33. #define DPLL_AUTOIDLE_LOW_POWER_STOP 0x1
  34. #define MAX_DPLL_WAIT_TRIES 1000000
  35. /* Private functions */
  36. /* _omap3_dpll_write_clken - write clken_bits arg to a DPLL's enable bits */
  37. static void _omap3_dpll_write_clken(struct clk_hw_omap *clk, u8 clken_bits)
  38. {
  39. const struct dpll_data *dd;
  40. u32 v;
  41. dd = clk->dpll_data;
  42. v = omap2_clk_readl(clk, dd->control_reg);
  43. v &= ~dd->enable_mask;
  44. v |= clken_bits << __ffs(dd->enable_mask);
  45. omap2_clk_writel(v, clk, dd->control_reg);
  46. }
  47. /* _omap3_wait_dpll_status: wait for a DPLL to enter a specific state */
  48. static int _omap3_wait_dpll_status(struct clk_hw_omap *clk, u8 state)
  49. {
  50. const struct dpll_data *dd;
  51. int i = 0;
  52. int ret = -EINVAL;
  53. const char *clk_name;
  54. dd = clk->dpll_data;
  55. clk_name = __clk_get_name(clk->hw.clk);
  56. state <<= __ffs(dd->idlest_mask);
  57. while (((omap2_clk_readl(clk, dd->idlest_reg) & dd->idlest_mask)
  58. != state) && i < MAX_DPLL_WAIT_TRIES) {
  59. i++;
  60. udelay(1);
  61. }
  62. if (i == MAX_DPLL_WAIT_TRIES) {
  63. printk(KERN_ERR "clock: %s failed transition to '%s'\n",
  64. clk_name, (state) ? "locked" : "bypassed");
  65. } else {
  66. pr_debug("clock: %s transition to '%s' in %d loops\n",
  67. clk_name, (state) ? "locked" : "bypassed", i);
  68. ret = 0;
  69. }
  70. return ret;
  71. }
  72. /* From 3430 TRM ES2 4.7.6.2 */
  73. static u16 _omap3_dpll_compute_freqsel(struct clk_hw_omap *clk, u8 n)
  74. {
  75. unsigned long fint;
  76. u16 f = 0;
  77. fint = __clk_get_rate(clk->dpll_data->clk_ref) / n;
  78. pr_debug("clock: fint is %lu\n", fint);
  79. if (fint >= 750000 && fint <= 1000000)
  80. f = 0x3;
  81. else if (fint > 1000000 && fint <= 1250000)
  82. f = 0x4;
  83. else if (fint > 1250000 && fint <= 1500000)
  84. f = 0x5;
  85. else if (fint > 1500000 && fint <= 1750000)
  86. f = 0x6;
  87. else if (fint > 1750000 && fint <= 2100000)
  88. f = 0x7;
  89. else if (fint > 7500000 && fint <= 10000000)
  90. f = 0xB;
  91. else if (fint > 10000000 && fint <= 12500000)
  92. f = 0xC;
  93. else if (fint > 12500000 && fint <= 15000000)
  94. f = 0xD;
  95. else if (fint > 15000000 && fint <= 17500000)
  96. f = 0xE;
  97. else if (fint > 17500000 && fint <= 21000000)
  98. f = 0xF;
  99. else
  100. pr_debug("clock: unknown freqsel setting for %d\n", n);
  101. return f;
  102. }
  103. /*
  104. * _omap3_noncore_dpll_lock - instruct a DPLL to lock and wait for readiness
  105. * @clk: pointer to a DPLL struct clk
  106. *
  107. * Instructs a non-CORE DPLL to lock. Waits for the DPLL to report
  108. * readiness before returning. Will save and restore the DPLL's
  109. * autoidle state across the enable, per the CDP code. If the DPLL
  110. * locked successfully, return 0; if the DPLL did not lock in the time
  111. * allotted, or DPLL3 was passed in, return -EINVAL.
  112. */
  113. static int _omap3_noncore_dpll_lock(struct clk_hw_omap *clk)
  114. {
  115. const struct dpll_data *dd;
  116. u8 ai;
  117. u8 state = 1;
  118. int r = 0;
  119. pr_debug("clock: locking DPLL %s\n", __clk_get_name(clk->hw.clk));
  120. dd = clk->dpll_data;
  121. state <<= __ffs(dd->idlest_mask);
  122. /* Check if already locked */
  123. if ((omap2_clk_readl(clk, dd->idlest_reg) & dd->idlest_mask) == state)
  124. goto done;
  125. ai = omap3_dpll_autoidle_read(clk);
  126. if (ai)
  127. omap3_dpll_deny_idle(clk);
  128. _omap3_dpll_write_clken(clk, DPLL_LOCKED);
  129. r = _omap3_wait_dpll_status(clk, 1);
  130. if (ai)
  131. omap3_dpll_allow_idle(clk);
  132. done:
  133. return r;
  134. }
  135. /*
  136. * _omap3_noncore_dpll_bypass - instruct a DPLL to bypass and wait for readiness
  137. * @clk: pointer to a DPLL struct clk
  138. *
  139. * Instructs a non-CORE DPLL to enter low-power bypass mode. In
  140. * bypass mode, the DPLL's rate is set equal to its parent clock's
  141. * rate. Waits for the DPLL to report readiness before returning.
  142. * Will save and restore the DPLL's autoidle state across the enable,
  143. * per the CDP code. If the DPLL entered bypass mode successfully,
  144. * return 0; if the DPLL did not enter bypass in the time allotted, or
  145. * DPLL3 was passed in, or the DPLL does not support low-power bypass,
  146. * return -EINVAL.
  147. */
  148. static int _omap3_noncore_dpll_bypass(struct clk_hw_omap *clk)
  149. {
  150. int r;
  151. u8 ai;
  152. if (!(clk->dpll_data->modes & (1 << DPLL_LOW_POWER_BYPASS)))
  153. return -EINVAL;
  154. pr_debug("clock: configuring DPLL %s for low-power bypass\n",
  155. __clk_get_name(clk->hw.clk));
  156. ai = omap3_dpll_autoidle_read(clk);
  157. _omap3_dpll_write_clken(clk, DPLL_LOW_POWER_BYPASS);
  158. r = _omap3_wait_dpll_status(clk, 0);
  159. if (ai)
  160. omap3_dpll_allow_idle(clk);
  161. return r;
  162. }
  163. /*
  164. * _omap3_noncore_dpll_stop - instruct a DPLL to stop
  165. * @clk: pointer to a DPLL struct clk
  166. *
  167. * Instructs a non-CORE DPLL to enter low-power stop. Will save and
  168. * restore the DPLL's autoidle state across the stop, per the CDP
  169. * code. If DPLL3 was passed in, or the DPLL does not support
  170. * low-power stop, return -EINVAL; otherwise, return 0.
  171. */
  172. static int _omap3_noncore_dpll_stop(struct clk_hw_omap *clk)
  173. {
  174. u8 ai;
  175. if (!(clk->dpll_data->modes & (1 << DPLL_LOW_POWER_STOP)))
  176. return -EINVAL;
  177. pr_debug("clock: stopping DPLL %s\n", __clk_get_name(clk->hw.clk));
  178. ai = omap3_dpll_autoidle_read(clk);
  179. _omap3_dpll_write_clken(clk, DPLL_LOW_POWER_STOP);
  180. if (ai)
  181. omap3_dpll_allow_idle(clk);
  182. return 0;
  183. }
  184. /**
  185. * _lookup_dco - Lookup DCO used by j-type DPLL
  186. * @clk: pointer to a DPLL struct clk
  187. * @dco: digital control oscillator selector
  188. * @m: DPLL multiplier to set
  189. * @n: DPLL divider to set
  190. *
  191. * See 36xx TRM section 3.5.3.3.3.2 "Type B DPLL (Low-Jitter)"
  192. *
  193. * XXX This code is not needed for 3430/AM35xx; can it be optimized
  194. * out in non-multi-OMAP builds for those chips?
  195. */
  196. static void _lookup_dco(struct clk_hw_omap *clk, u8 *dco, u16 m, u8 n)
  197. {
  198. unsigned long fint, clkinp; /* watch out for overflow */
  199. clkinp = __clk_get_rate(__clk_get_parent(clk->hw.clk));
  200. fint = (clkinp / n) * m;
  201. if (fint < 1000000000)
  202. *dco = 2;
  203. else
  204. *dco = 4;
  205. }
  206. /**
  207. * _lookup_sddiv - Calculate sigma delta divider for j-type DPLL
  208. * @clk: pointer to a DPLL struct clk
  209. * @sd_div: target sigma-delta divider
  210. * @m: DPLL multiplier to set
  211. * @n: DPLL divider to set
  212. *
  213. * See 36xx TRM section 3.5.3.3.3.2 "Type B DPLL (Low-Jitter)"
  214. *
  215. * XXX This code is not needed for 3430/AM35xx; can it be optimized
  216. * out in non-multi-OMAP builds for those chips?
  217. */
  218. static void _lookup_sddiv(struct clk_hw_omap *clk, u8 *sd_div, u16 m, u8 n)
  219. {
  220. unsigned long clkinp, sd; /* watch out for overflow */
  221. int mod1, mod2;
  222. clkinp = __clk_get_rate(__clk_get_parent(clk->hw.clk));
  223. /*
  224. * target sigma-delta to near 250MHz
  225. * sd = ceil[(m/(n+1)) * (clkinp_MHz / 250)]
  226. */
  227. clkinp /= 100000; /* shift from MHz to 10*Hz for 38.4 and 19.2 */
  228. mod1 = (clkinp * m) % (250 * n);
  229. sd = (clkinp * m) / (250 * n);
  230. mod2 = sd % 10;
  231. sd /= 10;
  232. if (mod1 || mod2)
  233. sd++;
  234. *sd_div = sd;
  235. }
  236. /*
  237. * _omap3_noncore_dpll_program - set non-core DPLL M,N values directly
  238. * @clk: struct clk * of DPLL to set
  239. * @freqsel: FREQSEL value to set
  240. *
  241. * Program the DPLL with the last M, N values calculated, and wait for
  242. * the DPLL to lock. Returns -EINVAL upon error, or 0 upon success.
  243. */
  244. static int omap3_noncore_dpll_program(struct clk_hw_omap *clk, u16 freqsel)
  245. {
  246. struct dpll_data *dd = clk->dpll_data;
  247. u8 dco, sd_div;
  248. u32 v;
  249. /* 3430 ES2 TRM: 4.7.6.9 DPLL Programming Sequence */
  250. _omap3_noncore_dpll_bypass(clk);
  251. /*
  252. * Set jitter correction. Jitter correction applicable for OMAP343X
  253. * only since freqsel field is no longer present on other devices.
  254. */
  255. if (ti_clk_features.flags & TI_CLK_DPLL_HAS_FREQSEL) {
  256. v = omap2_clk_readl(clk, dd->control_reg);
  257. v &= ~dd->freqsel_mask;
  258. v |= freqsel << __ffs(dd->freqsel_mask);
  259. omap2_clk_writel(v, clk, dd->control_reg);
  260. }
  261. /* Set DPLL multiplier, divider */
  262. v = omap2_clk_readl(clk, dd->mult_div1_reg);
  263. /* Handle Duty Cycle Correction */
  264. if (dd->dcc_mask) {
  265. if (dd->last_rounded_rate >= dd->dcc_rate)
  266. v |= dd->dcc_mask; /* Enable DCC */
  267. else
  268. v &= ~dd->dcc_mask; /* Disable DCC */
  269. }
  270. v &= ~(dd->mult_mask | dd->div1_mask);
  271. v |= dd->last_rounded_m << __ffs(dd->mult_mask);
  272. v |= (dd->last_rounded_n - 1) << __ffs(dd->div1_mask);
  273. /* Configure dco and sd_div for dplls that have these fields */
  274. if (dd->dco_mask) {
  275. _lookup_dco(clk, &dco, dd->last_rounded_m, dd->last_rounded_n);
  276. v &= ~(dd->dco_mask);
  277. v |= dco << __ffs(dd->dco_mask);
  278. }
  279. if (dd->sddiv_mask) {
  280. _lookup_sddiv(clk, &sd_div, dd->last_rounded_m,
  281. dd->last_rounded_n);
  282. v &= ~(dd->sddiv_mask);
  283. v |= sd_div << __ffs(dd->sddiv_mask);
  284. }
  285. omap2_clk_writel(v, clk, dd->mult_div1_reg);
  286. /* Set 4X multiplier and low-power mode */
  287. if (dd->m4xen_mask || dd->lpmode_mask) {
  288. v = omap2_clk_readl(clk, dd->control_reg);
  289. if (dd->m4xen_mask) {
  290. if (dd->last_rounded_m4xen)
  291. v |= dd->m4xen_mask;
  292. else
  293. v &= ~dd->m4xen_mask;
  294. }
  295. if (dd->lpmode_mask) {
  296. if (dd->last_rounded_lpmode)
  297. v |= dd->lpmode_mask;
  298. else
  299. v &= ~dd->lpmode_mask;
  300. }
  301. omap2_clk_writel(v, clk, dd->control_reg);
  302. }
  303. /* We let the clock framework set the other output dividers later */
  304. /* REVISIT: Set ramp-up delay? */
  305. _omap3_noncore_dpll_lock(clk);
  306. return 0;
  307. }
  308. /* Public functions */
  309. /**
  310. * omap3_dpll_recalc - recalculate DPLL rate
  311. * @clk: DPLL struct clk
  312. *
  313. * Recalculate and propagate the DPLL rate.
  314. */
  315. unsigned long omap3_dpll_recalc(struct clk_hw *hw, unsigned long parent_rate)
  316. {
  317. struct clk_hw_omap *clk = to_clk_hw_omap(hw);
  318. return omap2_get_dpll_rate(clk);
  319. }
  320. /* Non-CORE DPLL (e.g., DPLLs that do not control SDRC) clock functions */
  321. /**
  322. * omap3_noncore_dpll_enable - instruct a DPLL to enter bypass or lock mode
  323. * @clk: pointer to a DPLL struct clk
  324. *
  325. * Instructs a non-CORE DPLL to enable, e.g., to enter bypass or lock.
  326. * The choice of modes depends on the DPLL's programmed rate: if it is
  327. * the same as the DPLL's parent clock, it will enter bypass;
  328. * otherwise, it will enter lock. This code will wait for the DPLL to
  329. * indicate readiness before returning, unless the DPLL takes too long
  330. * to enter the target state. Intended to be used as the struct clk's
  331. * enable function. If DPLL3 was passed in, or the DPLL does not
  332. * support low-power stop, or if the DPLL took too long to enter
  333. * bypass or lock, return -EINVAL; otherwise, return 0.
  334. */
  335. int omap3_noncore_dpll_enable(struct clk_hw *hw)
  336. {
  337. struct clk_hw_omap *clk = to_clk_hw_omap(hw);
  338. int r;
  339. struct dpll_data *dd;
  340. struct clk *parent;
  341. dd = clk->dpll_data;
  342. if (!dd)
  343. return -EINVAL;
  344. if (clk->clkdm) {
  345. r = clkdm_clk_enable(clk->clkdm, hw->clk);
  346. if (r) {
  347. WARN(1,
  348. "%s: could not enable %s's clockdomain %s: %d\n",
  349. __func__, __clk_get_name(hw->clk),
  350. clk->clkdm->name, r);
  351. return r;
  352. }
  353. }
  354. parent = __clk_get_parent(hw->clk);
  355. if (__clk_get_rate(hw->clk) == __clk_get_rate(dd->clk_bypass)) {
  356. WARN_ON(parent != dd->clk_bypass);
  357. r = _omap3_noncore_dpll_bypass(clk);
  358. } else {
  359. WARN_ON(parent != dd->clk_ref);
  360. r = _omap3_noncore_dpll_lock(clk);
  361. }
  362. return r;
  363. }
  364. /**
  365. * omap3_noncore_dpll_disable - instruct a DPLL to enter low-power stop
  366. * @clk: pointer to a DPLL struct clk
  367. *
  368. * Instructs a non-CORE DPLL to enter low-power stop. This function is
  369. * intended for use in struct clkops. No return value.
  370. */
  371. void omap3_noncore_dpll_disable(struct clk_hw *hw)
  372. {
  373. struct clk_hw_omap *clk = to_clk_hw_omap(hw);
  374. _omap3_noncore_dpll_stop(clk);
  375. if (clk->clkdm)
  376. clkdm_clk_disable(clk->clkdm, hw->clk);
  377. }
  378. /* Non-CORE DPLL rate set code */
  379. /**
  380. * omap3_noncore_dpll_set_rate - set non-core DPLL rate
  381. * @clk: struct clk * of DPLL to set
  382. * @rate: rounded target rate
  383. *
  384. * Set the DPLL CLKOUT to the target rate. If the DPLL can enter
  385. * low-power bypass, and the target rate is the bypass source clock
  386. * rate, then configure the DPLL for bypass. Otherwise, round the
  387. * target rate if it hasn't been done already, then program and lock
  388. * the DPLL. Returns -EINVAL upon error, or 0 upon success.
  389. */
  390. int omap3_noncore_dpll_set_rate(struct clk_hw *hw, unsigned long rate,
  391. unsigned long parent_rate)
  392. {
  393. struct clk_hw_omap *clk = to_clk_hw_omap(hw);
  394. struct clk *new_parent = NULL;
  395. unsigned long rrate;
  396. u16 freqsel = 0;
  397. struct dpll_data *dd;
  398. int ret;
  399. if (!hw || !rate)
  400. return -EINVAL;
  401. dd = clk->dpll_data;
  402. if (!dd)
  403. return -EINVAL;
  404. if (__clk_get_rate(dd->clk_bypass) == rate &&
  405. (dd->modes & (1 << DPLL_LOW_POWER_BYPASS))) {
  406. pr_debug("%s: %s: set rate: entering bypass.\n",
  407. __func__, __clk_get_name(hw->clk));
  408. __clk_prepare(dd->clk_bypass);
  409. clk_enable(dd->clk_bypass);
  410. ret = _omap3_noncore_dpll_bypass(clk);
  411. if (!ret)
  412. new_parent = dd->clk_bypass;
  413. clk_disable(dd->clk_bypass);
  414. __clk_unprepare(dd->clk_bypass);
  415. } else {
  416. __clk_prepare(dd->clk_ref);
  417. clk_enable(dd->clk_ref);
  418. /* XXX this check is probably pointless in the CCF context */
  419. if (dd->last_rounded_rate != rate) {
  420. rrate = __clk_round_rate(hw->clk, rate);
  421. if (rrate != rate) {
  422. pr_warn("%s: %s: final rate %lu does not match desired rate %lu\n",
  423. __func__, __clk_get_name(hw->clk),
  424. rrate, rate);
  425. rate = rrate;
  426. }
  427. }
  428. if (dd->last_rounded_rate == 0)
  429. return -EINVAL;
  430. /* Freqsel is available only on OMAP343X devices */
  431. if (ti_clk_features.flags & TI_CLK_DPLL_HAS_FREQSEL) {
  432. freqsel = _omap3_dpll_compute_freqsel(clk,
  433. dd->last_rounded_n);
  434. WARN_ON(!freqsel);
  435. }
  436. pr_debug("%s: %s: set rate: locking rate to %lu.\n",
  437. __func__, __clk_get_name(hw->clk), rate);
  438. ret = omap3_noncore_dpll_program(clk, freqsel);
  439. if (!ret)
  440. new_parent = dd->clk_ref;
  441. clk_disable(dd->clk_ref);
  442. __clk_unprepare(dd->clk_ref);
  443. }
  444. /*
  445. * FIXME - this is all wrong. common code handles reparenting and
  446. * migrating prepare/enable counts. dplls should be a multiplexer
  447. * clock and this should be a set_parent operation so that all of that
  448. * stuff is inherited for free
  449. */
  450. if (!ret && clk_get_parent(hw->clk) != new_parent)
  451. __clk_reparent(hw->clk, new_parent);
  452. return 0;
  453. }
  454. /* DPLL autoidle read/set code */
  455. /**
  456. * omap3_dpll_autoidle_read - read a DPLL's autoidle bits
  457. * @clk: struct clk * of the DPLL to read
  458. *
  459. * Return the DPLL's autoidle bits, shifted down to bit 0. Returns
  460. * -EINVAL if passed a null pointer or if the struct clk does not
  461. * appear to refer to a DPLL.
  462. */
  463. u32 omap3_dpll_autoidle_read(struct clk_hw_omap *clk)
  464. {
  465. const struct dpll_data *dd;
  466. u32 v;
  467. if (!clk || !clk->dpll_data)
  468. return -EINVAL;
  469. dd = clk->dpll_data;
  470. if (!dd->autoidle_reg)
  471. return -EINVAL;
  472. v = omap2_clk_readl(clk, dd->autoidle_reg);
  473. v &= dd->autoidle_mask;
  474. v >>= __ffs(dd->autoidle_mask);
  475. return v;
  476. }
  477. /**
  478. * omap3_dpll_allow_idle - enable DPLL autoidle bits
  479. * @clk: struct clk * of the DPLL to operate on
  480. *
  481. * Enable DPLL automatic idle control. This automatic idle mode
  482. * switching takes effect only when the DPLL is locked, at least on
  483. * OMAP3430. The DPLL will enter low-power stop when its downstream
  484. * clocks are gated. No return value.
  485. */
  486. void omap3_dpll_allow_idle(struct clk_hw_omap *clk)
  487. {
  488. const struct dpll_data *dd;
  489. u32 v;
  490. if (!clk || !clk->dpll_data)
  491. return;
  492. dd = clk->dpll_data;
  493. if (!dd->autoidle_reg)
  494. return;
  495. /*
  496. * REVISIT: CORE DPLL can optionally enter low-power bypass
  497. * by writing 0x5 instead of 0x1. Add some mechanism to
  498. * optionally enter this mode.
  499. */
  500. v = omap2_clk_readl(clk, dd->autoidle_reg);
  501. v &= ~dd->autoidle_mask;
  502. v |= DPLL_AUTOIDLE_LOW_POWER_STOP << __ffs(dd->autoidle_mask);
  503. omap2_clk_writel(v, clk, dd->autoidle_reg);
  504. }
  505. /**
  506. * omap3_dpll_deny_idle - prevent DPLL from automatically idling
  507. * @clk: struct clk * of the DPLL to operate on
  508. *
  509. * Disable DPLL automatic idle control. No return value.
  510. */
  511. void omap3_dpll_deny_idle(struct clk_hw_omap *clk)
  512. {
  513. const struct dpll_data *dd;
  514. u32 v;
  515. if (!clk || !clk->dpll_data)
  516. return;
  517. dd = clk->dpll_data;
  518. if (!dd->autoidle_reg)
  519. return;
  520. v = omap2_clk_readl(clk, dd->autoidle_reg);
  521. v &= ~dd->autoidle_mask;
  522. v |= DPLL_AUTOIDLE_DISABLE << __ffs(dd->autoidle_mask);
  523. omap2_clk_writel(v, clk, dd->autoidle_reg);
  524. }
  525. /* Clock control for DPLL outputs */
  526. /* Find the parent DPLL for the given clkoutx2 clock */
  527. static struct clk_hw_omap *omap3_find_clkoutx2_dpll(struct clk_hw *hw)
  528. {
  529. struct clk_hw_omap *pclk = NULL;
  530. struct clk *parent;
  531. /* Walk up the parents of clk, looking for a DPLL */
  532. do {
  533. do {
  534. parent = __clk_get_parent(hw->clk);
  535. hw = __clk_get_hw(parent);
  536. } while (hw && (__clk_get_flags(hw->clk) & CLK_IS_BASIC));
  537. if (!hw)
  538. break;
  539. pclk = to_clk_hw_omap(hw);
  540. } while (pclk && !pclk->dpll_data);
  541. /* clk does not have a DPLL as a parent? error in the clock data */
  542. if (!pclk) {
  543. WARN_ON(1);
  544. return NULL;
  545. }
  546. return pclk;
  547. }
  548. /**
  549. * omap3_clkoutx2_recalc - recalculate DPLL X2 output virtual clock rate
  550. * @clk: DPLL output struct clk
  551. *
  552. * Using parent clock DPLL data, look up DPLL state. If locked, set our
  553. * rate to the dpll_clk * 2; otherwise, just use dpll_clk.
  554. */
  555. unsigned long omap3_clkoutx2_recalc(struct clk_hw *hw,
  556. unsigned long parent_rate)
  557. {
  558. const struct dpll_data *dd;
  559. unsigned long rate;
  560. u32 v;
  561. struct clk_hw_omap *pclk = NULL;
  562. if (!parent_rate)
  563. return 0;
  564. pclk = omap3_find_clkoutx2_dpll(hw);
  565. if (!pclk)
  566. return 0;
  567. dd = pclk->dpll_data;
  568. WARN_ON(!dd->enable_mask);
  569. v = omap2_clk_readl(pclk, dd->control_reg) & dd->enable_mask;
  570. v >>= __ffs(dd->enable_mask);
  571. if ((v != OMAP3XXX_EN_DPLL_LOCKED) || (dd->flags & DPLL_J_TYPE))
  572. rate = parent_rate;
  573. else
  574. rate = parent_rate * 2;
  575. return rate;
  576. }
  577. int omap3_clkoutx2_set_rate(struct clk_hw *hw, unsigned long rate,
  578. unsigned long parent_rate)
  579. {
  580. return 0;
  581. }
  582. long omap3_clkoutx2_round_rate(struct clk_hw *hw, unsigned long rate,
  583. unsigned long *prate)
  584. {
  585. const struct dpll_data *dd;
  586. u32 v;
  587. struct clk_hw_omap *pclk = NULL;
  588. if (!*prate)
  589. return 0;
  590. pclk = omap3_find_clkoutx2_dpll(hw);
  591. if (!pclk)
  592. return 0;
  593. dd = pclk->dpll_data;
  594. /* TYPE J does not have a clkoutx2 */
  595. if (dd->flags & DPLL_J_TYPE) {
  596. *prate = __clk_round_rate(__clk_get_parent(pclk->hw.clk), rate);
  597. return *prate;
  598. }
  599. WARN_ON(!dd->enable_mask);
  600. v = omap2_clk_readl(pclk, dd->control_reg) & dd->enable_mask;
  601. v >>= __ffs(dd->enable_mask);
  602. /* If in bypass, the rate is fixed to the bypass rate*/
  603. if (v != OMAP3XXX_EN_DPLL_LOCKED)
  604. return *prate;
  605. if (__clk_get_flags(hw->clk) & CLK_SET_RATE_PARENT) {
  606. unsigned long best_parent;
  607. best_parent = (rate / 2);
  608. *prate = __clk_round_rate(__clk_get_parent(hw->clk),
  609. best_parent);
  610. }
  611. return *prate * 2;
  612. }
  613. /* OMAP3/4 non-CORE DPLL clkops */
  614. const struct clk_hw_omap_ops clkhwops_omap3_dpll = {
  615. .allow_idle = omap3_dpll_allow_idle,
  616. .deny_idle = omap3_dpll_deny_idle,
  617. };