clock-pxa3xx.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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 <mach/smemc.h>
  13. #include <mach/pxa3xx-regs.h>
  14. #include "clock.h"
  15. /* Crystal clock: 13MHz */
  16. #define BASE_CLK 13000000
  17. /* Ring Oscillator Clock: 60MHz */
  18. #define RO_CLK 60000000
  19. #define ACCR_D0CS (1 << 26)
  20. #define ACCR_PCCE (1 << 11)
  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. /* crystal frequency to static memory controller multiplier (SMCFS) */
  86. static unsigned int smcfs_mult[8] = { 6, 0, 8, 0, 0, 16, };
  87. static unsigned int df_clkdiv[4] = { 1, 2, 4, 1 };
  88. static unsigned long clk_pxa3xx_smemc_getrate(struct clk *clk)
  89. {
  90. unsigned long acsr = ACSR;
  91. unsigned long memclkcfg = __raw_readl(MEMCLKCFG);
  92. return BASE_CLK * smcfs_mult[(acsr >> 23) & 0x7] /
  93. df_clkdiv[(memclkcfg >> 16) & 0x3];
  94. }
  95. void clk_pxa3xx_cken_enable(struct clk *clk)
  96. {
  97. unsigned long mask = 1ul << (clk->cken & 0x1f);
  98. if (clk->cken < 32)
  99. CKENA |= mask;
  100. else
  101. CKENB |= mask;
  102. }
  103. void clk_pxa3xx_cken_disable(struct clk *clk)
  104. {
  105. unsigned long mask = 1ul << (clk->cken & 0x1f);
  106. if (clk->cken < 32)
  107. CKENA &= ~mask;
  108. else
  109. CKENB &= ~mask;
  110. }
  111. const struct clkops clk_pxa3xx_cken_ops = {
  112. .enable = clk_pxa3xx_cken_enable,
  113. .disable = clk_pxa3xx_cken_disable,
  114. };
  115. const struct clkops clk_pxa3xx_hsio_ops = {
  116. .enable = clk_pxa3xx_cken_enable,
  117. .disable = clk_pxa3xx_cken_disable,
  118. .getrate = clk_pxa3xx_hsio_getrate,
  119. };
  120. const struct clkops clk_pxa3xx_ac97_ops = {
  121. .enable = clk_pxa3xx_cken_enable,
  122. .disable = clk_pxa3xx_cken_disable,
  123. .getrate = clk_pxa3xx_ac97_getrate,
  124. };
  125. const struct clkops clk_pxa3xx_smemc_ops = {
  126. .enable = clk_pxa3xx_cken_enable,
  127. .disable = clk_pxa3xx_cken_disable,
  128. .getrate = clk_pxa3xx_smemc_getrate,
  129. };
  130. static void clk_pout_enable(struct clk *clk)
  131. {
  132. OSCC |= OSCC_PEN;
  133. }
  134. static void clk_pout_disable(struct clk *clk)
  135. {
  136. OSCC &= ~OSCC_PEN;
  137. }
  138. const struct clkops clk_pxa3xx_pout_ops = {
  139. .enable = clk_pout_enable,
  140. .disable = clk_pout_disable,
  141. };
  142. #ifdef CONFIG_PM
  143. static uint32_t cken[2];
  144. static uint32_t accr;
  145. static int pxa3xx_clock_suspend(struct sys_device *d, pm_message_t state)
  146. {
  147. cken[0] = CKENA;
  148. cken[1] = CKENB;
  149. accr = ACCR;
  150. return 0;
  151. }
  152. static int pxa3xx_clock_resume(struct sys_device *d)
  153. {
  154. ACCR = accr;
  155. CKENA = cken[0];
  156. CKENB = cken[1];
  157. return 0;
  158. }
  159. #else
  160. #define pxa3xx_clock_suspend NULL
  161. #define pxa3xx_clock_resume NULL
  162. #endif
  163. struct sysdev_class pxa3xx_clock_sysclass = {
  164. .name = "pxa3xx-clock",
  165. .suspend = pxa3xx_clock_suspend,
  166. .resume = pxa3xx_clock_resume,
  167. };
  168. static int __init pxa3xx_clock_init(void)
  169. {
  170. if (cpu_is_pxa3xx() || cpu_is_pxa95x())
  171. return sysdev_class_register(&pxa3xx_clock_sysclass);
  172. return 0;
  173. }
  174. postcore_initcall(pxa3xx_clock_init);