pxa25x.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /*
  2. * linux/arch/arm/mach-pxa/pxa25x.c
  3. *
  4. * Author: Nicolas Pitre
  5. * Created: Jun 15, 2001
  6. * Copyright: MontaVista Software Inc.
  7. *
  8. * Code specific to PXA21x/25x/26x variants.
  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. * Since this file should be linked before any other machine specific file,
  15. * the __initcall() here will be executed first. This serves as default
  16. * initialization stuff for PXA machines which can be overridden later if
  17. * need be.
  18. */
  19. #include <linux/gpio.h>
  20. #include <linux/gpio-pxa.h>
  21. #include <linux/module.h>
  22. #include <linux/kernel.h>
  23. #include <linux/init.h>
  24. #include <linux/platform_device.h>
  25. #include <linux/suspend.h>
  26. #include <linux/syscore_ops.h>
  27. #include <linux/irq.h>
  28. #include <asm/mach/map.h>
  29. #include <asm/suspend.h>
  30. #include <mach/hardware.h>
  31. #include <mach/irqs.h>
  32. #include <mach/pxa25x.h>
  33. #include <mach/reset.h>
  34. #include <mach/pm.h>
  35. #include <mach/dma.h>
  36. #include <mach/smemc.h>
  37. #include "generic.h"
  38. #include "devices.h"
  39. /*
  40. * Various clock factors driven by the CCCR register.
  41. */
  42. #ifdef CONFIG_PM
  43. #define SAVE(x) sleep_save[SLEEP_SAVE_##x] = x
  44. #define RESTORE(x) x = sleep_save[SLEEP_SAVE_##x]
  45. /*
  46. * List of global PXA peripheral registers to preserve.
  47. * More ones like CP and general purpose register values are preserved
  48. * with the stack pointer in sleep.S.
  49. */
  50. enum {
  51. SLEEP_SAVE_PSTR,
  52. SLEEP_SAVE_COUNT
  53. };
  54. static void pxa25x_cpu_pm_save(unsigned long *sleep_save)
  55. {
  56. SAVE(PSTR);
  57. }
  58. static void pxa25x_cpu_pm_restore(unsigned long *sleep_save)
  59. {
  60. RESTORE(PSTR);
  61. }
  62. static void pxa25x_cpu_pm_enter(suspend_state_t state)
  63. {
  64. /* Clear reset status */
  65. RCSR = RCSR_HWR | RCSR_WDR | RCSR_SMR | RCSR_GPR;
  66. switch (state) {
  67. case PM_SUSPEND_MEM:
  68. cpu_suspend(PWRMODE_SLEEP, pxa25x_finish_suspend);
  69. break;
  70. }
  71. }
  72. static int pxa25x_cpu_pm_prepare(void)
  73. {
  74. /* set resume return address */
  75. PSPR = virt_to_phys(cpu_resume);
  76. return 0;
  77. }
  78. static void pxa25x_cpu_pm_finish(void)
  79. {
  80. /* ensure not to come back here if it wasn't intended */
  81. PSPR = 0;
  82. }
  83. static struct pxa_cpu_pm_fns pxa25x_cpu_pm_fns = {
  84. .save_count = SLEEP_SAVE_COUNT,
  85. .valid = suspend_valid_only_mem,
  86. .save = pxa25x_cpu_pm_save,
  87. .restore = pxa25x_cpu_pm_restore,
  88. .enter = pxa25x_cpu_pm_enter,
  89. .prepare = pxa25x_cpu_pm_prepare,
  90. .finish = pxa25x_cpu_pm_finish,
  91. };
  92. static void __init pxa25x_init_pm(void)
  93. {
  94. pxa_cpu_pm_fns = &pxa25x_cpu_pm_fns;
  95. }
  96. #else
  97. static inline void pxa25x_init_pm(void) {}
  98. #endif
  99. /* PXA25x: supports wakeup from GPIO0..GPIO15 and RTC alarm
  100. */
  101. static int pxa25x_set_wake(struct irq_data *d, unsigned int on)
  102. {
  103. int gpio = pxa_irq_to_gpio(d->irq);
  104. uint32_t mask = 0;
  105. if (gpio >= 0 && gpio < 85)
  106. return gpio_set_wake(gpio, on);
  107. if (d->irq == IRQ_RTCAlrm) {
  108. mask = PWER_RTC;
  109. goto set_pwer;
  110. }
  111. return -EINVAL;
  112. set_pwer:
  113. if (on)
  114. PWER |= mask;
  115. else
  116. PWER &=~mask;
  117. return 0;
  118. }
  119. void __init pxa25x_init_irq(void)
  120. {
  121. pxa_init_irq(32, pxa25x_set_wake);
  122. }
  123. #ifdef CONFIG_CPU_PXA26x
  124. void __init pxa26x_init_irq(void)
  125. {
  126. pxa_init_irq(32, pxa25x_set_wake);
  127. }
  128. #endif
  129. static struct map_desc pxa25x_io_desc[] __initdata = {
  130. { /* Mem Ctl */
  131. .virtual = (unsigned long)SMEMC_VIRT,
  132. .pfn = __phys_to_pfn(PXA2XX_SMEMC_BASE),
  133. .length = SMEMC_SIZE,
  134. .type = MT_DEVICE
  135. }, { /* UNCACHED_PHYS_0 */
  136. .virtual = UNCACHED_PHYS_0,
  137. .pfn = __phys_to_pfn(0x00000000),
  138. .length = UNCACHED_PHYS_0_SIZE,
  139. .type = MT_DEVICE
  140. },
  141. };
  142. void __init pxa25x_map_io(void)
  143. {
  144. pxa_map_io();
  145. iotable_init(ARRAY_AND_SIZE(pxa25x_io_desc));
  146. pxa25x_get_clk_frequency_khz(1);
  147. }
  148. static struct pxa_gpio_platform_data pxa25x_gpio_info __initdata = {
  149. .irq_base = PXA_GPIO_TO_IRQ(0),
  150. .gpio_set_wake = gpio_set_wake,
  151. };
  152. static struct platform_device *pxa25x_devices[] __initdata = {
  153. &pxa25x_device_udc,
  154. &pxa_device_pmu,
  155. &pxa_device_i2s,
  156. &sa1100_device_rtc,
  157. &pxa25x_device_ssp,
  158. &pxa25x_device_nssp,
  159. &pxa25x_device_assp,
  160. &pxa25x_device_pwm0,
  161. &pxa25x_device_pwm1,
  162. &pxa_device_asoc_platform,
  163. };
  164. static int __init pxa25x_init(void)
  165. {
  166. int ret = 0;
  167. if (cpu_is_pxa25x()) {
  168. reset_status = RCSR;
  169. if ((ret = pxa_init_dma(IRQ_DMA, 16)))
  170. return ret;
  171. pxa25x_init_pm();
  172. register_syscore_ops(&pxa_irq_syscore_ops);
  173. register_syscore_ops(&pxa2xx_mfp_syscore_ops);
  174. pxa2xx_set_dmac_info(16);
  175. pxa_register_device(&pxa25x_device_gpio, &pxa25x_gpio_info);
  176. ret = platform_add_devices(pxa25x_devices,
  177. ARRAY_SIZE(pxa25x_devices));
  178. if (ret)
  179. return ret;
  180. }
  181. return ret;
  182. }
  183. postcore_initcall(pxa25x_init);