clkt2xxx_apll.c 2.6 KB

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