pxa27x.c 7.0 KB

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