pxa27x.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  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/gpio.h>
  15. #include <linux/gpio-pxa.h>
  16. #include <linux/module.h>
  17. #include <linux/kernel.h>
  18. #include <linux/init.h>
  19. #include <linux/suspend.h>
  20. #include <linux/platform_device.h>
  21. #include <linux/syscore_ops.h>
  22. #include <linux/io.h>
  23. #include <linux/irq.h>
  24. #include <linux/i2c/pxa-i2c.h>
  25. #include <asm/mach/map.h>
  26. #include <mach/hardware.h>
  27. #include <asm/irq.h>
  28. #include <asm/suspend.h>
  29. #include <mach/irqs.h>
  30. #include <mach/pxa27x.h>
  31. #include <mach/reset.h>
  32. #include <linux/platform_data/usb-ohci-pxa27x.h>
  33. #include <mach/pm.h>
  34. #include <mach/dma.h>
  35. #include <mach/smemc.h>
  36. #include "generic.h"
  37. #include "devices.h"
  38. #include <linux/clk-provider.h>
  39. #include <linux/clkdev.h>
  40. void pxa27x_clear_otgph(void)
  41. {
  42. if (cpu_is_pxa27x() && (PSSR & PSSR_OTGPH))
  43. PSSR |= PSSR_OTGPH;
  44. }
  45. EXPORT_SYMBOL(pxa27x_clear_otgph);
  46. static unsigned long ac97_reset_config[] = {
  47. GPIO113_AC97_nRESET_GPIO_HIGH,
  48. GPIO113_AC97_nRESET,
  49. GPIO95_AC97_nRESET_GPIO_HIGH,
  50. GPIO95_AC97_nRESET,
  51. };
  52. void pxa27x_configure_ac97reset(int reset_gpio, bool to_gpio)
  53. {
  54. /*
  55. * This helper function is used to work around a bug in the pxa27x's
  56. * ac97 controller during a warm reset. The configuration of the
  57. * reset_gpio is changed as follows:
  58. * to_gpio == true: configured to generic output gpio and driven high
  59. * to_gpio == false: configured to ac97 controller alt fn AC97_nRESET
  60. */
  61. if (reset_gpio == 113)
  62. pxa2xx_mfp_config(to_gpio ? &ac97_reset_config[0] :
  63. &ac97_reset_config[1], 1);
  64. if (reset_gpio == 95)
  65. pxa2xx_mfp_config(to_gpio ? &ac97_reset_config[2] :
  66. &ac97_reset_config[3], 1);
  67. }
  68. EXPORT_SYMBOL_GPL(pxa27x_configure_ac97reset);
  69. #ifdef CONFIG_PM
  70. #define SAVE(x) sleep_save[SLEEP_SAVE_##x] = x
  71. #define RESTORE(x) x = sleep_save[SLEEP_SAVE_##x]
  72. /*
  73. * allow platforms to override default PWRMODE setting used for PM_SUSPEND_MEM
  74. */
  75. static unsigned int pwrmode = PWRMODE_SLEEP;
  76. int __init pxa27x_set_pwrmode(unsigned int mode)
  77. {
  78. switch (mode) {
  79. case PWRMODE_SLEEP:
  80. case PWRMODE_DEEPSLEEP:
  81. pwrmode = mode;
  82. return 0;
  83. }
  84. return -EINVAL;
  85. }
  86. /*
  87. * List of global PXA peripheral registers to preserve.
  88. * More ones like CP and general purpose register values are preserved
  89. * with the stack pointer in sleep.S.
  90. */
  91. enum {
  92. SLEEP_SAVE_PSTR,
  93. SLEEP_SAVE_MDREFR,
  94. SLEEP_SAVE_PCFR,
  95. SLEEP_SAVE_COUNT
  96. };
  97. void pxa27x_cpu_pm_save(unsigned long *sleep_save)
  98. {
  99. sleep_save[SLEEP_SAVE_MDREFR] = __raw_readl(MDREFR);
  100. SAVE(PCFR);
  101. SAVE(PSTR);
  102. }
  103. void pxa27x_cpu_pm_restore(unsigned long *sleep_save)
  104. {
  105. __raw_writel(sleep_save[SLEEP_SAVE_MDREFR], MDREFR);
  106. RESTORE(PCFR);
  107. PSSR = PSSR_RDH | PSSR_PH;
  108. RESTORE(PSTR);
  109. }
  110. void pxa27x_cpu_pm_enter(suspend_state_t state)
  111. {
  112. extern void pxa_cpu_standby(void);
  113. #ifndef CONFIG_IWMMXT
  114. u64 acc0;
  115. asm volatile("mra %Q0, %R0, acc0" : "=r" (acc0));
  116. #endif
  117. /* ensure voltage-change sequencer not initiated, which hangs */
  118. PCFR &= ~PCFR_FVC;
  119. /* Clear edge-detect status register. */
  120. PEDR = 0xDF12FE1B;
  121. /* Clear reset status */
  122. RCSR = RCSR_HWR | RCSR_WDR | RCSR_SMR | RCSR_GPR;
  123. switch (state) {
  124. case PM_SUSPEND_STANDBY:
  125. pxa_cpu_standby();
  126. break;
  127. case PM_SUSPEND_MEM:
  128. cpu_suspend(pwrmode, pxa27x_finish_suspend);
  129. #ifndef CONFIG_IWMMXT
  130. asm volatile("mar acc0, %Q0, %R0" : "=r" (acc0));
  131. #endif
  132. break;
  133. }
  134. }
  135. static int pxa27x_cpu_pm_valid(suspend_state_t state)
  136. {
  137. return state == PM_SUSPEND_MEM || state == PM_SUSPEND_STANDBY;
  138. }
  139. static int pxa27x_cpu_pm_prepare(void)
  140. {
  141. /* set resume return address */
  142. PSPR = virt_to_phys(cpu_resume);
  143. return 0;
  144. }
  145. static void pxa27x_cpu_pm_finish(void)
  146. {
  147. /* ensure not to come back here if it wasn't intended */
  148. PSPR = 0;
  149. }
  150. static struct pxa_cpu_pm_fns pxa27x_cpu_pm_fns = {
  151. .save_count = SLEEP_SAVE_COUNT,
  152. .save = pxa27x_cpu_pm_save,
  153. .restore = pxa27x_cpu_pm_restore,
  154. .valid = pxa27x_cpu_pm_valid,
  155. .enter = pxa27x_cpu_pm_enter,
  156. .prepare = pxa27x_cpu_pm_prepare,
  157. .finish = pxa27x_cpu_pm_finish,
  158. };
  159. static void __init pxa27x_init_pm(void)
  160. {
  161. pxa_cpu_pm_fns = &pxa27x_cpu_pm_fns;
  162. }
  163. #else
  164. static inline void pxa27x_init_pm(void) {}
  165. #endif
  166. /* PXA27x: Various gpios can issue wakeup events. This logic only
  167. * handles the simple cases, not the WEMUX2 and WEMUX3 options
  168. */
  169. static int pxa27x_set_wake(struct irq_data *d, unsigned int on)
  170. {
  171. int gpio = pxa_irq_to_gpio(d->irq);
  172. uint32_t mask;
  173. if (gpio >= 0 && gpio < 128)
  174. return gpio_set_wake(gpio, on);
  175. if (d->irq == IRQ_KEYPAD)
  176. return keypad_set_wake(on);
  177. switch (d->irq) {
  178. case IRQ_RTCAlrm:
  179. mask = PWER_RTC;
  180. break;
  181. case IRQ_USB:
  182. mask = 1u << 26;
  183. break;
  184. default:
  185. return -EINVAL;
  186. }
  187. if (on)
  188. PWER |= mask;
  189. else
  190. PWER &=~mask;
  191. return 0;
  192. }
  193. void __init pxa27x_init_irq(void)
  194. {
  195. pxa_init_irq(34, pxa27x_set_wake);
  196. }
  197. void __init pxa27x_dt_init_irq(void)
  198. {
  199. if (IS_ENABLED(CONFIG_OF))
  200. pxa_dt_irq_init(pxa27x_set_wake);
  201. }
  202. static struct map_desc pxa27x_io_desc[] __initdata = {
  203. { /* Mem Ctl */
  204. .virtual = (unsigned long)SMEMC_VIRT,
  205. .pfn = __phys_to_pfn(PXA2XX_SMEMC_BASE),
  206. .length = SMEMC_SIZE,
  207. .type = MT_DEVICE
  208. }, { /* UNCACHED_PHYS_0 */
  209. .virtual = UNCACHED_PHYS_0,
  210. .pfn = __phys_to_pfn(0x00000000),
  211. .length = UNCACHED_PHYS_0_SIZE,
  212. .type = MT_DEVICE
  213. },
  214. };
  215. void __init pxa27x_map_io(void)
  216. {
  217. pxa_map_io();
  218. iotable_init(ARRAY_AND_SIZE(pxa27x_io_desc));
  219. pxa27x_get_clk_frequency_khz(1);
  220. }
  221. /*
  222. * device registration specific to PXA27x.
  223. */
  224. void __init pxa27x_set_i2c_power_info(struct i2c_pxa_platform_data *info)
  225. {
  226. local_irq_disable();
  227. PCFR |= PCFR_PI2CEN;
  228. local_irq_enable();
  229. pxa_register_device(&pxa27x_device_i2c_power, info);
  230. }
  231. static struct pxa_gpio_platform_data pxa27x_gpio_info __initdata = {
  232. .irq_base = PXA_GPIO_TO_IRQ(0),
  233. .gpio_set_wake = gpio_set_wake,
  234. };
  235. static struct platform_device *devices[] __initdata = {
  236. &pxa27x_device_udc,
  237. &pxa_device_pmu,
  238. &pxa_device_i2s,
  239. &pxa_device_asoc_ssp1,
  240. &pxa_device_asoc_ssp2,
  241. &pxa_device_asoc_ssp3,
  242. &pxa_device_asoc_platform,
  243. &pxa_device_rtc,
  244. &pxa27x_device_ssp1,
  245. &pxa27x_device_ssp2,
  246. &pxa27x_device_ssp3,
  247. &pxa27x_device_pwm0,
  248. &pxa27x_device_pwm1,
  249. };
  250. static int __init pxa27x_init(void)
  251. {
  252. int ret = 0;
  253. if (cpu_is_pxa27x()) {
  254. reset_status = RCSR;
  255. if ((ret = pxa_init_dma(IRQ_DMA, 32)))
  256. return ret;
  257. pxa27x_init_pm();
  258. register_syscore_ops(&pxa_irq_syscore_ops);
  259. register_syscore_ops(&pxa2xx_mfp_syscore_ops);
  260. if (!of_have_populated_dt()) {
  261. pxa_register_device(&pxa27x_device_gpio,
  262. &pxa27x_gpio_info);
  263. pxa2xx_set_dmac_info(32);
  264. ret = platform_add_devices(devices,
  265. ARRAY_SIZE(devices));
  266. }
  267. }
  268. return ret;
  269. }
  270. postcore_initcall(pxa27x_init);