dpll44xx.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. * OMAP4-specific DPLL control functions
  3. *
  4. * Copyright (C) 2011 Texas Instruments, Inc.
  5. * Rajendra Nayak
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/errno.h>
  13. #include <linux/clk.h>
  14. #include <linux/io.h>
  15. #include <linux/bitops.h>
  16. #include <plat/cpu.h>
  17. #include <plat/clock.h>
  18. #include "clock.h"
  19. #include "clock44xx.h"
  20. #include "cm-regbits-44xx.h"
  21. /* Supported only on OMAP4 */
  22. int omap4_dpllmx_gatectrl_read(struct clk *clk)
  23. {
  24. u32 v;
  25. u32 mask;
  26. if (!clk || !clk->clksel_reg || !cpu_is_omap44xx())
  27. return -EINVAL;
  28. mask = clk->flags & CLOCK_CLKOUTX2 ?
  29. OMAP4430_DPLL_CLKOUTX2_GATE_CTRL_MASK :
  30. OMAP4430_DPLL_CLKOUT_GATE_CTRL_MASK;
  31. v = __raw_readl(clk->clksel_reg);
  32. v &= mask;
  33. v >>= __ffs(mask);
  34. return v;
  35. }
  36. void omap4_dpllmx_allow_gatectrl(struct clk *clk)
  37. {
  38. u32 v;
  39. u32 mask;
  40. if (!clk || !clk->clksel_reg || !cpu_is_omap44xx())
  41. return;
  42. mask = clk->flags & CLOCK_CLKOUTX2 ?
  43. OMAP4430_DPLL_CLKOUTX2_GATE_CTRL_MASK :
  44. OMAP4430_DPLL_CLKOUT_GATE_CTRL_MASK;
  45. v = __raw_readl(clk->clksel_reg);
  46. /* Clear the bit to allow gatectrl */
  47. v &= ~mask;
  48. __raw_writel(v, clk->clksel_reg);
  49. }
  50. void omap4_dpllmx_deny_gatectrl(struct clk *clk)
  51. {
  52. u32 v;
  53. u32 mask;
  54. if (!clk || !clk->clksel_reg || !cpu_is_omap44xx())
  55. return;
  56. mask = clk->flags & CLOCK_CLKOUTX2 ?
  57. OMAP4430_DPLL_CLKOUTX2_GATE_CTRL_MASK :
  58. OMAP4430_DPLL_CLKOUT_GATE_CTRL_MASK;
  59. v = __raw_readl(clk->clksel_reg);
  60. /* Set the bit to deny gatectrl */
  61. v |= mask;
  62. __raw_writel(v, clk->clksel_reg);
  63. }
  64. const struct clkops clkops_omap4_dpllmx_ops = {
  65. .allow_idle = omap4_dpllmx_allow_gatectrl,
  66. .deny_idle = omap4_dpllmx_deny_gatectrl,
  67. };
  68. /**
  69. * omap4_dpll_regm4xen_recalc - compute DPLL rate, considering REGM4XEN bit
  70. * @clk: struct clk * of the DPLL to compute the rate for
  71. *
  72. * Compute the output rate for the OMAP4 DPLL represented by @clk.
  73. * Takes the REGM4XEN bit into consideration, which is needed for the
  74. * OMAP4 ABE DPLL. Returns the DPLL's output rate (before M-dividers)
  75. * upon success, or 0 upon error.
  76. */
  77. unsigned long omap4_dpll_regm4xen_recalc(struct clk *clk)
  78. {
  79. u32 v;
  80. unsigned long rate;
  81. struct dpll_data *dd;
  82. if (!clk || !clk->dpll_data)
  83. return 0;
  84. dd = clk->dpll_data;
  85. rate = omap2_get_dpll_rate(clk);
  86. /* regm4xen adds a multiplier of 4 to DPLL calculations */
  87. v = __raw_readl(dd->control_reg);
  88. if (v & OMAP4430_DPLL_REGM4XEN_MASK)
  89. rate *= OMAP4430_REGM4XEN_MULT;
  90. return rate;
  91. }
  92. /**
  93. * omap4_dpll_regm4xen_round_rate - round DPLL rate, considering REGM4XEN bit
  94. * @clk: struct clk * of the DPLL to round a rate for
  95. * @target_rate: the desired rate of the DPLL
  96. *
  97. * Compute the rate that would be programmed into the DPLL hardware
  98. * for @clk if set_rate() were to be provided with the rate
  99. * @target_rate. Takes the REGM4XEN bit into consideration, which is
  100. * needed for the OMAP4 ABE DPLL. Returns the rounded rate (before
  101. * M-dividers) upon success, -EINVAL if @clk is null or not a DPLL, or
  102. * ~0 if an error occurred in omap2_dpll_round_rate().
  103. */
  104. long omap4_dpll_regm4xen_round_rate(struct clk *clk, unsigned long target_rate)
  105. {
  106. u32 v;
  107. struct dpll_data *dd;
  108. long r;
  109. if (!clk || !clk->dpll_data)
  110. return -EINVAL;
  111. dd = clk->dpll_data;
  112. /* regm4xen adds a multiplier of 4 to DPLL calculations */
  113. v = __raw_readl(dd->control_reg) & OMAP4430_DPLL_REGM4XEN_MASK;
  114. if (v)
  115. target_rate = target_rate / OMAP4430_REGM4XEN_MULT;
  116. r = omap2_dpll_round_rate(clk, target_rate);
  117. if (r == ~0)
  118. return r;
  119. if (v)
  120. clk->dpll_data->last_rounded_rate *= OMAP4430_REGM4XEN_MULT;
  121. return clk->dpll_data->last_rounded_rate;
  122. }