clkt2xxx_apll.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 "cm.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 = 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. 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. /* Stop APLL */
  65. static void omap2_clk_apll_disable(struct clk *clk)
  66. {
  67. u32 cval;
  68. cval = cm_read_mod_reg(PLL_MOD, CM_CLKEN);
  69. cval &= ~(EN_APLL_LOCKED << clk->enable_bit);
  70. cm_write_mod_reg(cval, PLL_MOD, CM_CLKEN);
  71. }
  72. /* Public data */
  73. const struct clkops clkops_apll96 = {
  74. .enable = omap2_clk_apll96_enable,
  75. .disable = omap2_clk_apll_disable,
  76. };
  77. const struct clkops clkops_apll54 = {
  78. .enable = omap2_clk_apll54_enable,
  79. .disable = omap2_clk_apll_disable,
  80. };
  81. /* Public functions */
  82. u32 omap2xxx_get_apll_clkin(void)
  83. {
  84. u32 aplls, srate = 0;
  85. aplls = cm_read_mod_reg(PLL_MOD, CM_CLKSEL1);
  86. aplls &= OMAP24XX_APLLS_CLKIN_MASK;
  87. aplls >>= OMAP24XX_APLLS_CLKIN_SHIFT;
  88. if (aplls == APLLS_CLKIN_19_2MHZ)
  89. srate = 19200000;
  90. else if (aplls == APLLS_CLKIN_13MHZ)
  91. srate = 13000000;
  92. else if (aplls == APLLS_CLKIN_12MHZ)
  93. srate = 12000000;
  94. return srate;
  95. }