dataSynchronizationMemory.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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)