clock-pxa3xx.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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 <linux/io.h>
  12. #include <linux/syscore_ops.h>
  13. #include <mach/smemc.h>
  14. #include <mach/pxa3xx-regs.h>
  15. #include "clock.h"
  16. /* Crystal clock: 13MHz */
  17. #define BASE_CLK 13000000
  18. /* Ring Oscillator Clock: 60MHz */
  19. #define RO_CLK 60000000
  20. #define ACCR_D0CS (1 << 26)
  21. #define ACCR_PCCE (1 << 11)
  22. /* crystal frequency to HSIO bus frequency multiplier (HSS) */
  23. static unsigned char hss_mult[4] = { 8, 12, 16, 24 };
  24. /*
  25. * Get the clock frequency as reflected by CCSR and the turbo flag.
  26. * We assume these values have been applied via a fcs.
  27. * If info is not 0 we also display the current settings.
  28. */
  29. unsigned int pxa3xx_get_clk_frequency_khz(int info)
  30. {
  31. unsigned long acsr, xclkcfg;
  32. unsigned int t, xl, xn, hss, ro, XL, XN, CLK, HSS;
  33. /* Read XCLKCFG register turbo bit */
  34. __asm__ __volatile__("mrc\tp14, 0, %0, c6, c0, 0" : "=r"(xclkcfg));
  35. t = xclkcfg & 0x1;
  36. acsr = ACSR;
  37. xl = acsr & 0x1f;
  38. xn = (acsr >> 8) & 0x7;
  39. hss = (acsr >> 14) & 0x3;
  40. XL = xl * BASE_CLK;
  41. XN = xn * XL;
  42. ro = acsr & ACCR_D0CS;
  43. CLK = (ro) ? RO_CLK : ((t) ? XN : XL);
  44. HSS = (ro) ? RO_CLK : hss_mult[hss] * BASE_CLK;
  45. if (info) {
  46. pr_info("RO Mode clock: %d.%02dMHz (%sactive)\n",
  47. RO_CLK / 1000000, (RO_CLK % 1000000) / 10000,
  48. (ro) ? "" : "in");
  49. pr_info("Run Mode clock: %d.%02dMHz (*%d)\n",
  50. XL / 1000000, (XL % 1000000) / 10000, xl);
  51. pr_info("Turbo Mode clock: %d.%02dMHz (*%d, %sactive)\n",
  52. XN / 1000000, (XN % 1000000) / 10000, xn,
  53. (t) ? "" : "in");
  54. pr_info("HSIO bus clock: %d.%02dMHz\n",
  55. HSS / 1000000, (HSS % 1000000) / 10000);
  56. }
  57. return CLK / 1000;
  58. }
  59. /*
  60. * Return the current AC97 clock frequency.
  61. */
  62. static unsigned long clk_pxa3xx_ac97_getrate(struct clk *clk)
  63. {
  64. unsigned long rate = 312000000;
  65. unsigned long ac97_div;
  66. ac97_div = AC97_DIV;
  67. /* This may loose precision for some rates but won't for the
  68. * standard 24.576MHz.
  69. */
  70. rate /= (ac97_div >> 12) & 0x7fff;
  71. rate *= (ac97_div & 0xfff);
  72. return rate;
  73. }
  74. /*
  75. * Return the current HSIO bus clock frequency
  76. */
  77. static unsigned long clk_pxa3xx_hsio_getrate(struct clk *clk)
  78. {
  79. unsigned long acsr;
  80. unsigned int hss, hsio_clk;
  81. acsr = ACSR;
  82. hss = (acsr >> 14) & 0x3;
  83. hsio_clk = (acsr & ACCR_D0CS) ? RO_CLK : hss_mult[hss] * BASE_CLK;
  84. return hsio_clk;
  85. }
  86. /* crystal frequency to static memory controller multiplier (SMCFS) */
  87. static unsigned int smcfs_mult[8] = { 6, 0, 8, 0, 0, 16, };
  88. static unsigned int df_clkdiv[4] = { 1, 2, 4, 1 };
  89. static unsigned long clk_pxa3xx_smemc_getrate(struct clk *clk)
  90. {
  91. unsigned long acsr = ACSR;
  92. unsigned long memclkcfg = __raw_readl(MEMCLKCFG);
  93. return BASE_CLK * smcfs_mult[(acsr >> 23) & 0x7] /
  94. df_clkdiv[(memclkcfg >> 16) & 0x3];
  95. }
  96. void clk_pxa3xx_cken_enable(struct clk *clk)
  97. {
  98. unsigned long mask = 1ul << (clk->cken & 0x1f);
  99. if (clk->cken < 32)
  100. CKENA |= mask;
  101. else
  102. CKENB |= mask;
  103. }
  104. void clk_pxa3xx_cken_disable(struct clk *clk)
  105. {
  106. unsigned long mask = 1ul << (clk->cken & 0x1f);
  107. if (clk->cken < 32)
  108. CKENA &= ~mask;
  109. else
  110. CKENB &= ~mask;
  111. }
  112. const struct clkops clk_pxa3xx_cken_ops = {
  113. .enable = clk_pxa3xx_cken_enable,
  114. .disable = clk_pxa3xx_cken_disable,
  115. };
  116. const struct clkops clk_pxa3xx_hsio_ops = {
  117. .enable = clk_pxa3xx_cken_enable,
  118. .disable = clk_pxa3xx_cken_disable,
  119. .getrate = clk_pxa3xx_hsio_getrate,
  120. };
  121. const struct clkops clk_pxa3xx_ac97_ops = {
  122. .enable = clk_pxa3xx_cken_enable,
  123. .disable = clk_pxa3xx_cken_disable,
  124. .getrate = clk_pxa3xx_ac97_getrate,
  125. };
  126. const struct clkops clk_pxa3xx_smemc_ops = {
  127. .enable = clk_pxa3xx_cken_enable,
  128. .disable = clk_pxa3xx_cken_disable,
  129. .getrate = clk_pxa3xx_smemc_getrate,
  130. };
  131. static void clk_pout_enable(struct clk *clk)
  132. {
  133. OSCC |= OSCC_PEN;
  134. }
  135. static void clk_pout_disable(struct clk *clk)
  136. {
  137. OSCC &= ~OSCC_PEN;
  138. }
  139. const struct clkops clk_pxa3xx_pout_ops = {
  140. .enable = clk_pout_enable,
  141. .disable = clk_pout_disable,
  142. };
  143. #ifdef CONFIG_PM
  144. static uint32_t cken[2];
  145. static uint32_t accr;
  146. static int pxa3xx_clock_suspend(void)
  147. {
  148. cken[0] = CKENA;
  149. cken[1] = CKENB;
  150. accr = ACCR;
  151. return 0;
  152. }
  153. static void pxa3xx_clock_resume(void)
  154. {
  155. ACCR = accr;
  156. CKENA = cken[0];
  157. CKENB = cken[1];
  158. }
  159. #else
  160. #define pxa3xx_clock_suspend NULL
  161. #define pxa3xx_clock_resume NULL
  162. #endif
  163. struct syscore_ops pxa3xx_clock_syscore_ops = {
  164. .suspend = pxa3xx_clock_suspend,
  165. .resume = pxa3xx_clock_resume,
  166. };