clkt2xxx_apll.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. * OMAP2xxx APLL clock control functions
  3. *
  4. * Copyright (C) 2005-2008 Texas Instruments, Inc.
  5. * Copyright (C) 2004-2010 Nokia Corporation
  6. *
  7. * Contacts:
  8. * Richard Woodruff <r-woodruff2@ti.com>
  9. * Paul Walmsley
  10. *
  11. * Based on earlier work by Tuukka Tikkanen, Tony Lindgren,
  12. * Gordon McNutt and RidgeRun, Inc.
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License version 2 as
  16. * published by the Free Software Foundation.
  17. */
  18. #undef DEBUG
  19. #include <linux/kernel.h>
  20. #include <linux/clk.h>
  21. #include <linux/io.h>
  22. #include "clock.h"
  23. #include "clock2xxx.h"
  24. #include "cm2xxx.h"
  25. #include "cm-regbits-24xx.h"
  26. /* CM_CLKEN_PLL.EN_{54,96}M_PLL options (24XX) */
  27. #define EN_APLL_STOPPED 0
  28. #define EN_APLL_LOCKED 3
  29. /* CM_CLKSEL1_PLL.APLLS_CLKIN options (24XX) */
  30. #define APLLS_CLKIN_19_2MHZ 0
  31. #define APLLS_CLKIN_13MHZ 2
  32. #define APLLS_CLKIN_12MHZ 3
  33. /* Private functions */
  34. /**
  35. * omap2xxx_clk_apll_locked - is the APLL locked?
  36. * @hw: struct clk_hw * of the APLL to check
  37. *
  38. * If the APLL IP block referred to by @hw indicates that it's locked,
  39. * return true; otherwise, return false.
  40. */
  41. static bool omap2xxx_clk_apll_locked(struct clk_hw *hw)
  42. {
  43. struct clk_hw_omap *clk = to_clk_hw_omap(hw);
  44. u32 r, apll_mask;
  45. apll_mask = EN_APLL_LOCKED << clk->enable_bit;
  46. r = omap2_cm_read_mod_reg(PLL_MOD, CM_CLKEN);
  47. return ((r & apll_mask) == apll_mask) ? true : false;
  48. }
  49. int omap2_clk_apll96_enable(struct clk_hw *hw)
  50. {
  51. return omap2xxx_cm_apll96_enable();
  52. }
  53. int omap2_clk_apll54_enable(struct clk_hw *hw)
  54. {
  55. return omap2xxx_cm_apll54_enable();
  56. }
  57. static void _apll96_allow_idle(struct clk_hw_omap *clk)
  58. {
  59. omap2xxx_cm_set_apll96_auto_low_power_stop();
  60. }
  61. static void _apll96_deny_idle(struct clk_hw_omap *clk)
  62. {
  63. omap2xxx_cm_set_apll96_disable_autoidle();
  64. }
  65. static void _apll54_allow_idle(struct clk_hw_omap *clk)
  66. {
  67. omap2xxx_cm_set_apll54_auto_low_power_stop();
  68. }
  69. static void _apll54_deny_idle(struct clk_hw_omap *clk)
  70. {
  71. omap2xxx_cm_set_apll54_disable_autoidle();
  72. }
  73. void omap2_clk_apll96_disable(struct clk_hw *hw)
  74. {
  75. omap2xxx_cm_apll96_disable();
  76. }
  77. void omap2_clk_apll54_disable(struct clk_hw *hw)
  78. {
  79. omap2xxx_cm_apll54_disable();
  80. }
  81. unsigned long omap2_clk_apll54_recalc(struct clk_hw *hw,
  82. unsigned long parent_rate)
  83. {
  84. return (omap2xxx_clk_apll_locked(hw)) ? 54000000 : 0;
  85. }
  86. unsigned long omap2_clk_apll96_recalc(struct clk_hw *hw,
  87. unsigned long parent_rate)
  88. {
  89. return (omap2xxx_clk_apll_locked(hw)) ? 96000000 : 0;
  90. }
  91. /* Public data */
  92. const struct clk_hw_omap_ops clkhwops_apll54 = {
  93. .allow_idle = _apll54_allow_idle,
  94. .deny_idle = _apll54_deny_idle,
  95. };
  96. const struct clk_hw_omap_ops clkhwops_apll96 = {
  97. .allow_idle = _apll96_allow_idle,
  98. .deny_idle = _apll96_deny_idle,
  99. };
  100. /* Public functions */
  101. u32 omap2xxx_get_apll_clkin(void)
  102. {
  103. u32 aplls, srate = 0;
  104. aplls = omap2_cm_read_mod_reg(PLL_MOD, CM_CLKSEL1);
  105. aplls &= OMAP24XX_APLLS_CLKIN_MASK;
  106. aplls >>= OMAP24XX_APLLS_CLKIN_SHIFT;
  107. if (aplls == APLLS_CLKIN_19_2MHZ)
  108. srate = 19200000;
  109. else if (aplls == APLLS_CLKIN_13MHZ)
  110. srate = 13000000;
  111. else if (aplls == APLLS_CLKIN_12MHZ)
  112. srate = 12000000;
  113. return srate;
  114. }