dpll3xxx.c 17 KB

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