dpll44xx.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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 "soc.h"
  17. #include "clock.h"
  18. #include "clock44xx.h"
  19. #include "cm-regbits-44xx.h"
  20. /* Supported only on OMAP4 */
  21. int omap4_dpllmx_gatectrl_read(struct clk_hw_omap *clk)
  22. {
  23. u32 v;
  24. u32 mask;
  25. if (!clk || !clk->clksel_reg || !cpu_is_omap44xx())
  26. return -EINVAL;
  27. mask = clk->flags & CLOCK_CLKOUTX2 ?
  28. OMAP4430_DPLL_CLKOUTX2_GATE_CTRL_MASK :
  29. OMAP4430_DPLL_CLKOUT_GATE_CTRL_MASK;
  30. v = __raw_readl(clk->clksel_reg);
  31. v &= mask;
  32. v >>= __ffs(mask);
  33. return v;
  34. }
  35. void omap4_dpllmx_allow_gatectrl(struct clk_hw_omap *clk)
  36. {
  37. u32 v;
  38. u32 mask;
  39. if (!clk || !clk->clksel_reg || !cpu_is_omap44xx())
  40. return;
  41. mask = clk->flags & CLOCK_CLKOUTX2 ?
  42. OMAP4430_DPLL_CLKOUTX2_GATE_CTRL_MASK :
  43. OMAP4430_DPLL_CLKOUT_GATE_CTRL_MASK;
  44. v = __raw_readl(clk->clksel_reg);
  45. /* Clear the bit to allow gatectrl */
  46. v &= ~mask;
  47. __raw_writel(v, clk->clksel_reg);
  48. }
  49. void omap4_dpllmx_deny_gatectrl(struct clk_hw_omap *clk)
  50. {
  51. u32 v;
  52. u32 mask;
  53. if (!clk || !clk->clksel_reg || !cpu_is_omap44xx())
  54. return;
  55. mask = clk->flags & CLOCK_CLKOUTX2 ?
  56. OMAP4430_DPLL_CLKOUTX2_GATE_CTRL_MASK :
  57. OMAP4430_DPLL_CLKOUT_GATE_CTRL_MASK;
  58. v = __raw_readl(clk->clksel_reg);
  59. /* Set the bit to deny gatectrl */
  60. v |= mask;
  61. __raw_writel(v, clk->clksel_reg);
  62. }
  63. const struct clk_hw_omap_ops clkhwops_omap4_dpllmx = {
  64. .allow_idle = omap4_dpllmx_allow_gatectrl,
  65. .deny_idle = omap4_dpllmx_deny_gatectrl,
  66. };
  67. /**
  68. * omap4_dpll_regm4xen_recalc - compute DPLL rate, considering REGM4XEN bit
  69. * @clk: struct clk * of the DPLL to compute the rate for
  70. *
  71. * Compute the output rate for the OMAP4 DPLL represented by @clk.
  72. * Takes the REGM4XEN bit into consideration, which is needed for the
  73. * OMAP4 ABE DPLL. Returns the DPLL's output rate (before M-dividers)
  74. * upon success, or 0 upon error.
  75. */
  76. unsigned long omap4_dpll_regm4xen_recalc(struct clk_hw *hw,
  77. unsigned long parent_rate)
  78. {
  79. struct clk_hw_omap *clk = to_clk_hw_omap(hw);
  80. u32 v;
  81. unsigned long rate;
  82. struct dpll_data *dd;
  83. if (!clk || !clk->dpll_data)
  84. return 0;
  85. dd = clk->dpll_data;
  86. rate = omap2_get_dpll_rate(clk);
  87. /* regm4xen adds a multiplier of 4 to DPLL calculations */
  88. v = __raw_readl(dd->control_reg);
  89. if (v & OMAP4430_DPLL_REGM4XEN_MASK)
  90. rate *= OMAP4430_REGM4XEN_MULT;
  91. return rate;
  92. }
  93. /**
  94. * omap4_dpll_regm4xen_round_rate - round DPLL rate, considering REGM4XEN bit
  95. * @clk: struct clk * of the DPLL to round a rate for
  96. * @target_rate: the desired rate of the DPLL
  97. *
  98. * Compute the rate that would be programmed into the DPLL hardware
  99. * for @clk if set_rate() were to be provided with the rate
  100. * @target_rate. Takes the REGM4XEN bit into consideration, which is
  101. * needed for the OMAP4 ABE DPLL. Returns the rounded rate (before
  102. * M-dividers) upon success, -EINVAL if @clk is null or not a DPLL, or
  103. * ~0 if an error occurred in omap2_dpll_round_rate().
  104. */
  105. long omap4_dpll_regm4xen_round_rate(struct clk_hw *hw,
  106. unsigned long target_rate,
  107. unsigned long *parent_rate)
  108. {
  109. struct clk_hw_omap *clk = to_clk_hw_omap(hw);
  110. u32 v;
  111. struct dpll_data *dd;
  112. long r;
  113. if (!clk || !clk->dpll_data)
  114. return -EINVAL;
  115. dd = clk->dpll_data;
  116. /* regm4xen adds a multiplier of 4 to DPLL calculations */
  117. v = __raw_readl(dd->control_reg) & OMAP4430_DPLL_REGM4XEN_MASK;
  118. if (v)
  119. target_rate = target_rate / OMAP4430_REGM4XEN_MULT;
  120. r = omap2_dpll_round_rate(hw, target_rate, NULL);
  121. if (r == ~0)
  122. return r;
  123. if (v)
  124. clk->dpll_data->last_rounded_rate *= OMAP4430_REGM4XEN_MULT;
  125. return clk->dpll_data->last_rounded_rate;
  126. }