clkt2xxx_apll.c 3.2 KB

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