clkt2xxx_apll.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 <plat/prcm.h>
  23. #include "clock.h"
  24. #include "clock2xxx.h"
  25. #include "cm2xxx_3xxx.h"
  26. #include "cm-regbits-24xx.h"
  27. /* CM_CLKEN_PLL.EN_{54,96}M_PLL options (24XX) */
  28. #define EN_APLL_STOPPED 0
  29. #define EN_APLL_LOCKED 3
  30. /* CM_CLKSEL1_PLL.APLLS_CLKIN options (24XX) */
  31. #define APLLS_CLKIN_19_2MHZ 0
  32. #define APLLS_CLKIN_13MHZ 2
  33. #define APLLS_CLKIN_12MHZ 3
  34. void __iomem *cm_idlest_pll;
  35. /* Private functions */
  36. /* Enable an APLL if off */
  37. static int omap2_clk_apll_enable(struct clk *clk, u32 status_mask)
  38. {
  39. u32 cval, apll_mask;
  40. apll_mask = EN_APLL_LOCKED << clk->enable_bit;
  41. cval = omap2_cm_read_mod_reg(PLL_MOD, CM_CLKEN);
  42. if ((cval & apll_mask) == apll_mask)
  43. return 0; /* apll already enabled */
  44. cval &= ~apll_mask;
  45. cval |= apll_mask;
  46. omap2_cm_write_mod_reg(cval, PLL_MOD, CM_CLKEN);
  47. omap2_cm_wait_idlest(cm_idlest_pll, status_mask,
  48. OMAP24XX_CM_IDLEST_VAL, __clk_get_name(clk));
  49. /*
  50. * REVISIT: Should we return an error code if omap2_wait_clock_ready()
  51. * fails?
  52. */
  53. return 0;
  54. }
  55. static int omap2_clk_apll96_enable(struct clk *clk)
  56. {
  57. return omap2_clk_apll_enable(clk, OMAP24XX_ST_96M_APLL_MASK);
  58. }
  59. static int omap2_clk_apll54_enable(struct clk *clk)
  60. {
  61. return omap2_clk_apll_enable(clk, OMAP24XX_ST_54M_APLL_MASK);
  62. }
  63. static void _apll96_allow_idle(struct clk *clk)
  64. {
  65. omap2xxx_cm_set_apll96_auto_low_power_stop();
  66. }
  67. static void _apll96_deny_idle(struct clk *clk)
  68. {
  69. omap2xxx_cm_set_apll96_disable_autoidle();
  70. }
  71. static void _apll54_allow_idle(struct clk *clk)
  72. {
  73. omap2xxx_cm_set_apll54_auto_low_power_stop();
  74. }
  75. static void _apll54_deny_idle(struct clk *clk)
  76. {
  77. omap2xxx_cm_set_apll54_disable_autoidle();
  78. }
  79. /* Stop APLL */
  80. static void omap2_clk_apll_disable(struct clk *clk)
  81. {
  82. u32 cval;
  83. cval = omap2_cm_read_mod_reg(PLL_MOD, CM_CLKEN);
  84. cval &= ~(EN_APLL_LOCKED << clk->enable_bit);
  85. omap2_cm_write_mod_reg(cval, PLL_MOD, CM_CLKEN);
  86. }
  87. /* Public data */
  88. const struct clkops clkops_apll96 = {
  89. .enable = omap2_clk_apll96_enable,
  90. .disable = omap2_clk_apll_disable,
  91. .allow_idle = _apll96_allow_idle,
  92. .deny_idle = _apll96_deny_idle,
  93. };
  94. const struct clkops clkops_apll54 = {
  95. .enable = omap2_clk_apll54_enable,
  96. .disable = omap2_clk_apll_disable,
  97. .allow_idle = _apll54_allow_idle,
  98. .deny_idle = _apll54_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. }