clock-pxa3xx.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * linux/arch/arm/mach-pxa/clock-pxa3xx.c
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. */
  8. #include <linux/module.h>
  9. #include <linux/kernel.h>
  10. #include <linux/init.h>
  11. #include <mach/pxa3xx-regs.h>
  12. #include "clock.h"
  13. /* Crystal clock: 13MHz */
  14. #define BASE_CLK 13000000
  15. /* Ring Oscillator Clock: 60MHz */
  16. #define RO_CLK 60000000
  17. #define ACCR_D0CS (1 << 26)
  18. #define ACCR_PCCE (1 << 11)
  19. /* crystal frequency to static memory controller multiplier (SMCFS) */
  20. static unsigned char smcfs_mult[8] = { 6, 0, 8, 0, 0, 16, };
  21. /* crystal frequency to HSIO bus frequency multiplier (HSS) */
  22. static unsigned char hss_mult[4] = { 8, 12, 16, 24 };
  23. /*
  24. * Get the clock frequency as reflected by CCSR and the turbo flag.
  25. * We assume these values have been applied via a fcs.
  26. * If info is not 0 we also display the current settings.
  27. */
  28. unsigned int pxa3xx_get_clk_frequency_khz(int info)
  29. {
  30. unsigned long acsr, xclkcfg;
  31. unsigned int t, xl, xn, hss, ro, XL, XN, CLK, HSS;
  32. /* Read XCLKCFG register turbo bit */
  33. __asm__ __volatile__("mrc\tp14, 0, %0, c6, c0, 0" : "=r"(xclkcfg));
  34. t = xclkcfg & 0x1;
  35. acsr = ACSR;
  36. xl = acsr & 0x1f;
  37. xn = (acsr >> 8) & 0x7;
  38. hss = (acsr >> 14) & 0x3;
  39. XL = xl * BASE_CLK;
  40. XN = xn * XL;
  41. ro = acsr & ACCR_D0CS;
  42. CLK = (ro) ? RO_CLK : ((t) ? XN : XL);
  43. HSS = (ro) ? RO_CLK : hss_mult[hss] * BASE_CLK;
  44. if (info) {
  45. pr_info("RO Mode clock: %d.%02dMHz (%sactive)\n",
  46. RO_CLK / 1000000, (RO_CLK % 1000000) / 10000,
  47. (ro) ? "" : "in");
  48. pr_info("Run Mode clock: %d.%02dMHz (*%d)\n",
  49. XL / 1000000, (XL % 1000000) / 10000, xl);
  50. pr_info("Turbo Mode clock: %d.%02dMHz (*%d, %sactive)\n",
  51. XN / 1000000, (XN % 1000000) / 10000, xn,
  52. (t) ? "" : "in");
  53. pr_info("HSIO bus clock: %d.%02dMHz\n",
  54. HSS / 1000000, (HSS % 1000000) / 10000);
  55. }
  56. return CLK / 1000;
  57. }
  58. /*
  59. * Return the current AC97 clock frequency.
  60. */
  61. static unsigned long clk_pxa3xx_ac97_getrate(struct clk *clk)
  62. {
  63. unsigned long rate = 312000000;
  64. unsigned long ac97_div;
  65. ac97_div = AC97_DIV;
  66. /* This may loose precision for some rates but won't for the
  67. * standard 24.576MHz.
  68. */
  69. rate /= (ac97_div >> 12) & 0x7fff;
  70. rate *= (ac97_div & 0xfff);
  71. return rate;
  72. }
  73. /*
  74. * Return the current HSIO bus clock frequency
  75. */
  76. static unsigned long clk_pxa3xx_hsio_getrate(struct clk *clk)
  77. {
  78. unsigned long acsr;
  79. unsigned int hss, hsio_clk;
  80. acsr = ACSR;
  81. hss = (acsr >> 14) & 0x3;
  82. hsio_clk = (acsr & ACCR_D0CS) ? RO_CLK : hss_mult[hss] * BASE_CLK;
  83. return hsio_clk;
  84. }
  85. void clk_pxa3xx_cken_enable(struct clk *clk)
  86. {
  87. unsigned long mask = 1ul << (clk->cken & 0x1f);
  88. if (clk->cken < 32)
  89. CKENA |= mask;
  90. else
  91. CKENB |= mask;
  92. }
  93. void clk_pxa3xx_cken_disable(struct clk *clk)
  94. {
  95. unsigned long mask = 1ul << (clk->cken & 0x1f);
  96. if (clk->cken < 32)
  97. CKENA &= ~mask;
  98. else
  99. CKENB &= ~mask;
  100. }
  101. const struct clkops clk_pxa3xx_cken_ops = {
  102. .enable = clk_pxa3xx_cken_enable,
  103. .disable = clk_pxa3xx_cken_disable,
  104. };
  105. const struct clkops clk_pxa3xx_hsio_ops = {
  106. .enable = clk_pxa3xx_cken_enable,
  107. .disable = clk_pxa3xx_cken_disable,
  108. .getrate = clk_pxa3xx_hsio_getrate,
  109. };
  110. const struct clkops clk_pxa3xx_ac97_ops = {
  111. .enable = clk_pxa3xx_cken_enable,
  112. .disable = clk_pxa3xx_cken_disable,
  113. .getrate = clk_pxa3xx_ac97_getrate,
  114. };
  115. static void clk_pout_enable(struct clk *clk)
  116. {
  117. OSCC |= OSCC_PEN;
  118. }
  119. static void clk_pout_disable(struct clk *clk)
  120. {
  121. OSCC &= ~OSCC_PEN;
  122. }
  123. const struct clkops clk_pxa3xx_pout_ops = {
  124. .enable = clk_pout_enable,
  125. .disable = clk_pout_disable,
  126. };