pxa27x.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /*
  2. * linux/arch/arm/mach-pxa/pxa27x.c
  3. *
  4. * Author: Nicolas Pitre
  5. * Created: Nov 05, 2002
  6. * Copyright: MontaVista Software Inc.
  7. *
  8. * Code specific to PXA27x aka Bulverde.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. */
  14. #include <linux/config.h>
  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 <asm/hardware.h>
  21. #include <asm/irq.h>
  22. #include <asm/arch/pxa-regs.h>
  23. #include <asm/arch/ohci.h>
  24. #include "generic.h"
  25. /* Crystal clock: 13MHz */
  26. #define BASE_CLK 13000000
  27. /*
  28. * Get the clock frequency as reflected by CCSR and the turbo flag.
  29. * We assume these values have been applied via a fcs.
  30. * If info is not 0 we also display the current settings.
  31. */
  32. unsigned int get_clk_frequency_khz( int info)
  33. {
  34. unsigned long ccsr, clkcfg;
  35. unsigned int l, L, m, M, n2, N, S;
  36. int cccr_a, t, ht, b;
  37. ccsr = CCSR;
  38. cccr_a = CCCR & (1 << 25);
  39. /* Read clkcfg register: it has turbo, b, half-turbo (and f) */
  40. asm( "mrc\tp14, 0, %0, c6, c0, 0" : "=r" (clkcfg) );
  41. t = clkcfg & (1 << 0);
  42. ht = clkcfg & (1 << 2);
  43. b = clkcfg & (1 << 3);
  44. l = ccsr & 0x1f;
  45. n2 = (ccsr>>7) & 0xf;
  46. m = (l <= 10) ? 1 : (l <= 20) ? 2 : 4;
  47. L = l * BASE_CLK;
  48. N = (L * n2) / 2;
  49. M = (!cccr_a) ? (L/m) : ((b) ? L : (L/2));
  50. S = (b) ? L : (L/2);
  51. if (info) {
  52. printk( KERN_INFO "Run Mode clock: %d.%02dMHz (*%d)\n",
  53. L / 1000000, (L % 1000000) / 10000, l );
  54. printk( KERN_INFO "Turbo Mode clock: %d.%02dMHz (*%d.%d, %sactive)\n",
  55. N / 1000000, (N % 1000000)/10000, n2 / 2, (n2 % 2)*5,
  56. (t) ? "" : "in" );
  57. printk( KERN_INFO "Memory clock: %d.%02dMHz (/%d)\n",
  58. M / 1000000, (M % 1000000) / 10000, m );
  59. printk( KERN_INFO "System bus clock: %d.%02dMHz \n",
  60. S / 1000000, (S % 1000000) / 10000 );
  61. }
  62. return (t) ? (N/1000) : (L/1000);
  63. }
  64. /*
  65. * Return the current mem clock frequency in units of 10kHz as
  66. * reflected by CCCR[A], B, and L
  67. */
  68. unsigned int get_memclk_frequency_10khz(void)
  69. {
  70. unsigned long ccsr, clkcfg;
  71. unsigned int l, L, m, M;
  72. int cccr_a, b;
  73. ccsr = CCSR;
  74. cccr_a = CCCR & (1 << 25);
  75. /* Read clkcfg register: it has turbo, b, half-turbo (and f) */
  76. asm( "mrc\tp14, 0, %0, c6, c0, 0" : "=r" (clkcfg) );
  77. b = clkcfg & (1 << 3);
  78. l = ccsr & 0x1f;
  79. m = (l <= 10) ? 1 : (l <= 20) ? 2 : 4;
  80. L = l * BASE_CLK;
  81. M = (!cccr_a) ? (L/m) : ((b) ? L : (L/2));
  82. return (M / 10000);
  83. }
  84. /*
  85. * Return the current LCD clock frequency in units of 10kHz as
  86. */
  87. unsigned int get_lcdclk_frequency_10khz(void)
  88. {
  89. unsigned long ccsr;
  90. unsigned int l, L, k, K;
  91. ccsr = CCSR;
  92. l = ccsr & 0x1f;
  93. k = (l <= 7) ? 1 : (l <= 16) ? 2 : 4;
  94. L = l * BASE_CLK;
  95. K = L / k;
  96. return (K / 10000);
  97. }
  98. EXPORT_SYMBOL(get_clk_frequency_khz);
  99. EXPORT_SYMBOL(get_memclk_frequency_10khz);
  100. EXPORT_SYMBOL(get_lcdclk_frequency_10khz);
  101. #ifdef CONFIG_PM
  102. int pxa_cpu_pm_prepare(suspend_state_t state)
  103. {
  104. switch (state) {
  105. case PM_SUSPEND_MEM:
  106. case PM_SUSPEND_STANDBY:
  107. return 0;
  108. default:
  109. return -EINVAL;
  110. }
  111. }
  112. void pxa_cpu_pm_enter(suspend_state_t state)
  113. {
  114. extern void pxa_cpu_standby(void);
  115. extern void pxa_cpu_suspend(unsigned int);
  116. extern void pxa_cpu_resume(void);
  117. if (state == PM_SUSPEND_STANDBY)
  118. CKEN = CKEN22_MEMC | CKEN9_OSTIMER | CKEN16_LCD |CKEN0_PWM0;
  119. else
  120. CKEN = CKEN22_MEMC | CKEN9_OSTIMER;
  121. /* ensure voltage-change sequencer not initiated, which hangs */
  122. PCFR &= ~PCFR_FVC;
  123. /* Clear edge-detect status register. */
  124. PEDR = 0xDF12FE1B;
  125. switch (state) {
  126. case PM_SUSPEND_STANDBY:
  127. pxa_cpu_standby();
  128. break;
  129. case PM_SUSPEND_MEM:
  130. /* set resume return address */
  131. PSPR = virt_to_phys(pxa_cpu_resume);
  132. pxa_cpu_suspend(PWRMODE_SLEEP);
  133. break;
  134. }
  135. }
  136. #endif
  137. /*
  138. * device registration specific to PXA27x.
  139. */
  140. static u64 pxa27x_dmamask = 0xffffffffUL;
  141. static struct resource pxa27x_ohci_resources[] = {
  142. [0] = {
  143. .start = 0x4C000000,
  144. .end = 0x4C00ff6f,
  145. .flags = IORESOURCE_MEM,
  146. },
  147. [1] = {
  148. .start = IRQ_USBH1,
  149. .end = IRQ_USBH1,
  150. .flags = IORESOURCE_IRQ,
  151. },
  152. };
  153. static struct platform_device ohci_device = {
  154. .name = "pxa27x-ohci",
  155. .id = -1,
  156. .dev = {
  157. .dma_mask = &pxa27x_dmamask,
  158. .coherent_dma_mask = 0xffffffff,
  159. },
  160. .num_resources = ARRAY_SIZE(pxa27x_ohci_resources),
  161. .resource = pxa27x_ohci_resources,
  162. };
  163. void __init pxa_set_ohci_info(struct pxaohci_platform_data *info)
  164. {
  165. ohci_device.dev.platform_data = info;
  166. }
  167. static struct platform_device *devices[] __initdata = {
  168. &ohci_device,
  169. };
  170. static int __init pxa27x_init(void)
  171. {
  172. return platform_add_devices(devices, ARRAY_SIZE(devices));
  173. }
  174. subsys_initcall(pxa27x_init);