pxa3xx.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /*
  2. * linux/arch/arm/mach-pxa/pxa3xx.c
  3. *
  4. * code specific to pxa3xx aka Monahans
  5. *
  6. * Copyright (C) 2006 Marvell International Ltd.
  7. *
  8. * 2007-09-02: eric miao <eric.y.miao@gmail.com>
  9. * initial version
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License version 2 as
  13. * published by the Free Software Foundation.
  14. */
  15. #include <linux/module.h>
  16. #include <linux/kernel.h>
  17. #include <linux/init.h>
  18. #include <linux/pm.h>
  19. #include <linux/platform_device.h>
  20. #include <linux/irq.h>
  21. #include <asm/hardware.h>
  22. #include <asm/arch/pxa3xx-regs.h>
  23. #include <asm/arch/ohci.h>
  24. #include <asm/arch/pm.h>
  25. #include <asm/arch/dma.h>
  26. #include <asm/arch/ssp.h>
  27. #include "generic.h"
  28. #include "devices.h"
  29. #include "clock.h"
  30. /* Crystal clock: 13MHz */
  31. #define BASE_CLK 13000000
  32. /* Ring Oscillator Clock: 60MHz */
  33. #define RO_CLK 60000000
  34. #define ACCR_D0CS (1 << 26)
  35. /* crystal frequency to static memory controller multiplier (SMCFS) */
  36. static unsigned char smcfs_mult[8] = { 6, 0, 8, 0, 0, 16, };
  37. /* crystal frequency to HSIO bus frequency multiplier (HSS) */
  38. static unsigned char hss_mult[4] = { 8, 12, 16, 0 };
  39. /*
  40. * Get the clock frequency as reflected by CCSR and the turbo flag.
  41. * We assume these values have been applied via a fcs.
  42. * If info is not 0 we also display the current settings.
  43. */
  44. unsigned int pxa3xx_get_clk_frequency_khz(int info)
  45. {
  46. unsigned long acsr, xclkcfg;
  47. unsigned int t, xl, xn, hss, ro, XL, XN, CLK, HSS;
  48. /* Read XCLKCFG register turbo bit */
  49. __asm__ __volatile__("mrc\tp14, 0, %0, c6, c0, 0" : "=r"(xclkcfg));
  50. t = xclkcfg & 0x1;
  51. acsr = ACSR;
  52. xl = acsr & 0x1f;
  53. xn = (acsr >> 8) & 0x7;
  54. hss = (acsr >> 14) & 0x3;
  55. XL = xl * BASE_CLK;
  56. XN = xn * XL;
  57. ro = acsr & ACCR_D0CS;
  58. CLK = (ro) ? RO_CLK : ((t) ? XN : XL);
  59. HSS = (ro) ? RO_CLK : hss_mult[hss] * BASE_CLK;
  60. if (info) {
  61. pr_info("RO Mode clock: %d.%02dMHz (%sactive)\n",
  62. RO_CLK / 1000000, (RO_CLK % 1000000) / 10000,
  63. (ro) ? "" : "in");
  64. pr_info("Run Mode clock: %d.%02dMHz (*%d)\n",
  65. XL / 1000000, (XL % 1000000) / 10000, xl);
  66. pr_info("Turbo Mode clock: %d.%02dMHz (*%d, %sactive)\n",
  67. XN / 1000000, (XN % 1000000) / 10000, xn,
  68. (t) ? "" : "in");
  69. pr_info("HSIO bus clock: %d.%02dMHz\n",
  70. HSS / 1000000, (HSS % 1000000) / 10000);
  71. }
  72. return CLK;
  73. }
  74. /*
  75. * Return the current static memory controller clock frequency
  76. * in units of 10kHz
  77. */
  78. unsigned int pxa3xx_get_memclk_frequency_10khz(void)
  79. {
  80. unsigned long acsr;
  81. unsigned int smcfs, clk = 0;
  82. acsr = ACSR;
  83. smcfs = (acsr >> 23) & 0x7;
  84. clk = (acsr & ACCR_D0CS) ? RO_CLK : smcfs_mult[smcfs] * BASE_CLK;
  85. return (clk / 10000);
  86. }
  87. /*
  88. * Return the current HSIO bus clock frequency
  89. */
  90. static unsigned long clk_pxa3xx_hsio_getrate(struct clk *clk)
  91. {
  92. unsigned long acsr;
  93. unsigned int hss, hsio_clk;
  94. acsr = ACSR;
  95. hss = (acsr >> 14) & 0x3;
  96. hsio_clk = (acsr & ACCR_D0CS) ? RO_CLK : hss_mult[hss] * BASE_CLK;
  97. return hsio_clk;
  98. }
  99. static void clk_pxa3xx_cken_enable(struct clk *clk)
  100. {
  101. unsigned long mask = 1ul << (clk->cken & 0x1f);
  102. local_irq_disable();
  103. if (clk->cken < 32)
  104. CKENA |= mask;
  105. else
  106. CKENB |= mask;
  107. local_irq_enable();
  108. }
  109. static void clk_pxa3xx_cken_disable(struct clk *clk)
  110. {
  111. unsigned long mask = 1ul << (clk->cken & 0x1f);
  112. local_irq_disable();
  113. if (clk->cken < 32)
  114. CKENA &= ~mask;
  115. else
  116. CKENB &= ~mask;
  117. local_irq_enable();
  118. }
  119. static const struct clkops clk_pxa3xx_hsio_ops = {
  120. .enable = clk_pxa3xx_cken_enable,
  121. .disable = clk_pxa3xx_cken_disable,
  122. .getrate = clk_pxa3xx_hsio_getrate,
  123. };
  124. static struct clk pxa3xx_clks[] = {
  125. INIT_CK("LCDCLK", LCD, &clk_pxa3xx_hsio_ops, &pxa_device_fb.dev),
  126. INIT_CK("CAMCLK", CAMERA, &clk_pxa3xx_hsio_ops, NULL),
  127. INIT_CKEN("UARTCLK", FFUART, 14857000, 1, &pxa_device_ffuart.dev),
  128. INIT_CKEN("UARTCLK", BTUART, 14857000, 1, &pxa_device_btuart.dev),
  129. INIT_CKEN("UARTCLK", STUART, 14857000, 1, NULL),
  130. INIT_CKEN("I2CCLK", I2C, 32842000, 0, &pxa_device_i2c.dev),
  131. INIT_CKEN("UDCCLK", UDC, 48000000, 5, &pxa_device_udc.dev),
  132. };
  133. void __init pxa3xx_init_irq(void)
  134. {
  135. /* enable CP6 access */
  136. u32 value;
  137. __asm__ __volatile__("mrc p15, 0, %0, c15, c1, 0\n": "=r"(value));
  138. value |= (1 << 6);
  139. __asm__ __volatile__("mcr p15, 0, %0, c15, c1, 0\n": :"r"(value));
  140. pxa_init_irq_low();
  141. pxa_init_irq_high();
  142. pxa_init_irq_gpio(128);
  143. }
  144. /*
  145. * device registration specific to PXA3xx.
  146. */
  147. static struct platform_device *devices[] __initdata = {
  148. &pxa_device_mci,
  149. &pxa_device_udc,
  150. &pxa_device_fb,
  151. &pxa_device_ffuart,
  152. &pxa_device_btuart,
  153. &pxa_device_stuart,
  154. &pxa_device_i2c,
  155. &pxa_device_i2s,
  156. &pxa_device_ficp,
  157. &pxa_device_rtc,
  158. };
  159. static int __init pxa3xx_init(void)
  160. {
  161. int ret = 0;
  162. if (cpu_is_pxa3xx()) {
  163. clks_register(pxa3xx_clks, ARRAY_SIZE(pxa3xx_clks));
  164. if ((ret = pxa_init_dma(32)))
  165. return ret;
  166. return platform_add_devices(devices, ARRAY_SIZE(devices));
  167. }
  168. return 0;
  169. }
  170. subsys_initcall(pxa3xx_init);