pxa27x.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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 "pxa27x.h"
  31. #include <mach/reset.h>
  32. #include <linux/platform_data/usb-ohci-pxa27x.h>
  33. #include "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 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(".arch_extension xscale\n\t"
  116. "mra %Q0, %R0, acc0" : "=r" (acc0));
  117. #endif
  118. /* ensure voltage-change sequencer not initiated, which hangs */
  119. PCFR &= ~PCFR_FVC;
  120. /* Clear edge-detect status register. */
  121. PEDR = 0xDF12FE1B;
  122. /* Clear reset status */
  123. RCSR = RCSR_HWR | RCSR_WDR | RCSR_SMR | RCSR_GPR;
  124. switch (state) {
  125. case PM_SUSPEND_STANDBY:
  126. pxa_cpu_standby();
  127. break;
  128. case PM_SUSPEND_MEM:
  129. cpu_suspend(pwrmode, pxa27x_finish_suspend);
  130. #ifndef CONFIG_IWMMXT
  131. asm volatile(".arch_extension xscale\n\t"
  132. "mar acc0, %Q0, %R0" : "=r" (acc0));
  133. #endif
  134. break;
  135. }
  136. }
  137. static int pxa27x_cpu_pm_valid(suspend_state_t state)
  138. {
  139. return state == PM_SUSPEND_MEM || state == PM_SUSPEND_STANDBY;
  140. }
  141. static int pxa27x_cpu_pm_prepare(void)
  142. {
  143. /* set resume return address */
  144. PSPR = virt_to_phys(cpu_resume);
  145. return 0;
  146. }
  147. static void pxa27x_cpu_pm_finish(void)
  148. {
  149. /* ensure not to come back here if it wasn't intended */
  150. PSPR = 0;
  151. }
  152. static struct pxa_cpu_pm_fns pxa27x_cpu_pm_fns = {
  153. .save_count = SLEEP_SAVE_COUNT,
  154. .save = pxa27x_cpu_pm_save,
  155. .restore = pxa27x_cpu_pm_restore,
  156. .valid = pxa27x_cpu_pm_valid,
  157. .enter = pxa27x_cpu_pm_enter,
  158. .prepare = pxa27x_cpu_pm_prepare,
  159. .finish = pxa27x_cpu_pm_finish,
  160. };
  161. static void __init pxa27x_init_pm(void)
  162. {
  163. pxa_cpu_pm_fns = &pxa27x_cpu_pm_fns;
  164. }
  165. #else
  166. static inline void pxa27x_init_pm(void) {}
  167. #endif
  168. /* PXA27x: Various gpios can issue wakeup events. This logic only
  169. * handles the simple cases, not the WEMUX2 and WEMUX3 options
  170. */
  171. static int pxa27x_set_wake(struct irq_data *d, unsigned int on)
  172. {
  173. int gpio = pxa_irq_to_gpio(d->irq);
  174. uint32_t mask;
  175. if (gpio >= 0 && gpio < 128)
  176. return gpio_set_wake(gpio, on);
  177. if (d->irq == IRQ_KEYPAD)
  178. return keypad_set_wake(on);
  179. switch (d->irq) {
  180. case IRQ_RTCAlrm:
  181. mask = PWER_RTC;
  182. break;
  183. case IRQ_USB:
  184. mask = 1u << 26;
  185. break;
  186. default:
  187. return -EINVAL;
  188. }
  189. if (on)
  190. PWER |= mask;
  191. else
  192. PWER &=~mask;
  193. return 0;
  194. }
  195. void __init pxa27x_init_irq(void)
  196. {
  197. pxa_init_irq(34, pxa27x_set_wake);
  198. }
  199. void __init pxa27x_dt_init_irq(void)
  200. {
  201. if (IS_ENABLED(CONFIG_OF))
  202. pxa_dt_irq_init(pxa27x_set_wake);
  203. }
  204. static struct map_desc pxa27x_io_desc[] __initdata = {
  205. { /* Mem Ctl */
  206. .virtual = (unsigned long)SMEMC_VIRT,
  207. .pfn = __phys_to_pfn(PXA2XX_SMEMC_BASE),
  208. .length = SMEMC_SIZE,
  209. .type = MT_DEVICE
  210. }, { /* UNCACHED_PHYS_0 */
  211. .virtual = UNCACHED_PHYS_0,
  212. .pfn = __phys_to_pfn(0x00000000),
  213. .length = UNCACHED_PHYS_0_SIZE,
  214. .type = MT_DEVICE
  215. },
  216. };
  217. void __init pxa27x_map_io(void)
  218. {
  219. pxa_map_io();
  220. iotable_init(ARRAY_AND_SIZE(pxa27x_io_desc));
  221. pxa27x_get_clk_frequency_khz(1);
  222. }
  223. /*
  224. * device registration specific to PXA27x.
  225. */
  226. void __init pxa27x_set_i2c_power_info(struct i2c_pxa_platform_data *info)
  227. {
  228. local_irq_disable();
  229. PCFR |= PCFR_PI2CEN;
  230. local_irq_enable();
  231. pxa_register_device(&pxa27x_device_i2c_power, info);
  232. }
  233. static struct pxa_gpio_platform_data pxa27x_gpio_info __initdata = {
  234. .irq_base = PXA_GPIO_TO_IRQ(0),
  235. .gpio_set_wake = gpio_set_wake,
  236. };
  237. static struct platform_device *devices[] __initdata = {
  238. &pxa27x_device_udc,
  239. &pxa_device_pmu,
  240. &pxa_device_i2s,
  241. &pxa_device_asoc_ssp1,
  242. &pxa_device_asoc_ssp2,
  243. &pxa_device_asoc_ssp3,
  244. &pxa_device_asoc_platform,
  245. &pxa_device_rtc,
  246. &pxa27x_device_ssp1,
  247. &pxa27x_device_ssp2,
  248. &pxa27x_device_ssp3,
  249. &pxa27x_device_pwm0,
  250. &pxa27x_device_pwm1,
  251. };
  252. static int __init pxa27x_init(void)
  253. {
  254. int ret = 0;
  255. if (cpu_is_pxa27x()) {
  256. reset_status = RCSR;
  257. if ((ret = pxa_init_dma(IRQ_DMA, 32)))
  258. return ret;
  259. pxa27x_init_pm();
  260. register_syscore_ops(&pxa_irq_syscore_ops);
  261. register_syscore_ops(&pxa2xx_mfp_syscore_ops);
  262. if (!of_have_populated_dt()) {
  263. pxa_register_device(&pxa27x_device_gpio,
  264. &pxa27x_gpio_info);
  265. pxa2xx_set_dmac_info(32, 75);
  266. ret = platform_add_devices(devices,
  267. ARRAY_SIZE(devices));
  268. }
  269. }
  270. return ret;
  271. }
  272. postcore_initcall(pxa27x_init);