pxa3xx.c 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. /*
  2. * linux/arch/arm/mach-pxa/pxa3xx.c
  3. *
  4. * code specific to pxa3xx aka Monahans
  5. *
  6. * Copyright (C) 2006 Marvell International Ltd.
  7. *
  8. * 2007-09-02: eric miao <eric.miao@marvell.com>
  9. * initial version
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License version 2 as
  13. * published by the Free Software Foundation.
  14. */
  15. #include <linux/module.h>
  16. #include <linux/kernel.h>
  17. #include <linux/init.h>
  18. #include <linux/gpio-pxa.h>
  19. #include <linux/pm.h>
  20. #include <linux/platform_device.h>
  21. #include <linux/irq.h>
  22. #include <linux/io.h>
  23. #include <linux/of.h>
  24. #include <linux/syscore_ops.h>
  25. #include <linux/i2c/pxa-i2c.h>
  26. #include <asm/mach/map.h>
  27. #include <asm/suspend.h>
  28. #include <mach/hardware.h>
  29. #include <mach/pxa3xx-regs.h>
  30. #include <mach/reset.h>
  31. #include <linux/platform_data/usb-ohci-pxa27x.h>
  32. #include <mach/pm.h>
  33. #include <mach/dma.h>
  34. #include <mach/smemc.h>
  35. #include <mach/irqs.h>
  36. #include "generic.h"
  37. #include "devices.h"
  38. #define PECR_IE(n) ((1 << ((n) * 2)) << 28)
  39. #define PECR_IS(n) ((1 << ((n) * 2)) << 29)
  40. extern void __init pxa_dt_irq_init(int (*fn)(struct irq_data *, unsigned int));
  41. #ifdef CONFIG_PM
  42. #define ISRAM_START 0x5c000000
  43. #define ISRAM_SIZE SZ_256K
  44. static void __iomem *sram;
  45. static unsigned long wakeup_src;
  46. /*
  47. * Enter a standby mode (S0D1C2 or S0D2C2). Upon wakeup, the dynamic
  48. * memory controller has to be reinitialised, so we place some code
  49. * in the SRAM to perform this function.
  50. *
  51. * We disable FIQs across the standby - otherwise, we might receive a
  52. * FIQ while the SDRAM is unavailable.
  53. */
  54. static void pxa3xx_cpu_standby(unsigned int pwrmode)
  55. {
  56. extern const char pm_enter_standby_start[], pm_enter_standby_end[];
  57. void (*fn)(unsigned int) = (void __force *)(sram + 0x8000);
  58. memcpy_toio(sram + 0x8000, pm_enter_standby_start,
  59. pm_enter_standby_end - pm_enter_standby_start);
  60. AD2D0SR = ~0;
  61. AD2D1SR = ~0;
  62. AD2D0ER = wakeup_src;
  63. AD2D1ER = 0;
  64. ASCR = ASCR;
  65. ARSR = ARSR;
  66. local_fiq_disable();
  67. fn(pwrmode);
  68. local_fiq_enable();
  69. AD2D0ER = 0;
  70. AD2D1ER = 0;
  71. }
  72. /*
  73. * NOTE: currently, the OBM (OEM Boot Module) binary comes along with
  74. * PXA3xx development kits assumes that the resuming process continues
  75. * with the address stored within the first 4 bytes of SDRAM. The PSPR
  76. * register is used privately by BootROM and OBM, and _must_ be set to
  77. * 0x5c014000 for the moment.
  78. */
  79. static void pxa3xx_cpu_pm_suspend(void)
  80. {
  81. volatile unsigned long *p = (volatile void *)0xc0000000;
  82. unsigned long saved_data = *p;
  83. #ifndef CONFIG_IWMMXT
  84. u64 acc0;
  85. asm volatile("mra %Q0, %R0, acc0" : "=r" (acc0));
  86. #endif
  87. extern int pxa3xx_finish_suspend(unsigned long);
  88. /* resuming from D2 requires the HSIO2/BOOT/TPM clocks enabled */
  89. CKENA |= (1 << CKEN_BOOT) | (1 << CKEN_TPM);
  90. CKENB |= 1 << (CKEN_HSIO2 & 0x1f);
  91. /* clear and setup wakeup source */
  92. AD3SR = ~0;
  93. AD3ER = wakeup_src;
  94. ASCR = ASCR;
  95. ARSR = ARSR;
  96. PCFR |= (1u << 13); /* L1_DIS */
  97. PCFR &= ~((1u << 12) | (1u << 1)); /* L0_EN | SL_ROD */
  98. PSPR = 0x5c014000;
  99. /* overwrite with the resume address */
  100. *p = virt_to_phys(cpu_resume);
  101. cpu_suspend(0, pxa3xx_finish_suspend);
  102. *p = saved_data;
  103. AD3ER = 0;
  104. #ifndef CONFIG_IWMMXT
  105. asm volatile("mar acc0, %Q0, %R0" : "=r" (acc0));
  106. #endif
  107. }
  108. static void pxa3xx_cpu_pm_enter(suspend_state_t state)
  109. {
  110. /*
  111. * Don't sleep if no wakeup sources are defined
  112. */
  113. if (wakeup_src == 0) {
  114. printk(KERN_ERR "Not suspending: no wakeup sources\n");
  115. return;
  116. }
  117. switch (state) {
  118. case PM_SUSPEND_STANDBY:
  119. pxa3xx_cpu_standby(PXA3xx_PM_S0D2C2);
  120. break;
  121. case PM_SUSPEND_MEM:
  122. pxa3xx_cpu_pm_suspend();
  123. break;
  124. }
  125. }
  126. static int pxa3xx_cpu_pm_valid(suspend_state_t state)
  127. {
  128. return state == PM_SUSPEND_MEM || state == PM_SUSPEND_STANDBY;
  129. }
  130. static struct pxa_cpu_pm_fns pxa3xx_cpu_pm_fns = {
  131. .valid = pxa3xx_cpu_pm_valid,
  132. .enter = pxa3xx_cpu_pm_enter,
  133. };
  134. static void __init pxa3xx_init_pm(void)
  135. {
  136. sram = ioremap(ISRAM_START, ISRAM_SIZE);
  137. if (!sram) {
  138. printk(KERN_ERR "Unable to map ISRAM: disabling standby/suspend\n");
  139. return;
  140. }
  141. /*
  142. * Since we copy wakeup code into the SRAM, we need to ensure
  143. * that it is preserved over the low power modes. Note: bit 8
  144. * is undocumented in the developer manual, but must be set.
  145. */
  146. AD1R |= ADXR_L2 | ADXR_R0;
  147. AD2R |= ADXR_L2 | ADXR_R0;
  148. AD3R |= ADXR_L2 | ADXR_R0;
  149. /*
  150. * Clear the resume enable registers.
  151. */
  152. AD1D0ER = 0;
  153. AD2D0ER = 0;
  154. AD2D1ER = 0;
  155. AD3ER = 0;
  156. pxa_cpu_pm_fns = &pxa3xx_cpu_pm_fns;
  157. }
  158. static int pxa3xx_set_wake(struct irq_data *d, unsigned int on)
  159. {
  160. unsigned long flags, mask = 0;
  161. switch (d->irq) {
  162. case IRQ_SSP3:
  163. mask = ADXER_MFP_WSSP3;
  164. break;
  165. case IRQ_MSL:
  166. mask = ADXER_WMSL0;
  167. break;
  168. case IRQ_USBH2:
  169. case IRQ_USBH1:
  170. mask = ADXER_WUSBH;
  171. break;
  172. case IRQ_KEYPAD:
  173. mask = ADXER_WKP;
  174. break;
  175. case IRQ_AC97:
  176. mask = ADXER_MFP_WAC97;
  177. break;
  178. case IRQ_USIM:
  179. mask = ADXER_WUSIM0;
  180. break;
  181. case IRQ_SSP2:
  182. mask = ADXER_MFP_WSSP2;
  183. break;
  184. case IRQ_I2C:
  185. mask = ADXER_MFP_WI2C;
  186. break;
  187. case IRQ_STUART:
  188. mask = ADXER_MFP_WUART3;
  189. break;
  190. case IRQ_BTUART:
  191. mask = ADXER_MFP_WUART2;
  192. break;
  193. case IRQ_FFUART:
  194. mask = ADXER_MFP_WUART1;
  195. break;
  196. case IRQ_MMC:
  197. mask = ADXER_MFP_WMMC1;
  198. break;
  199. case IRQ_SSP:
  200. mask = ADXER_MFP_WSSP1;
  201. break;
  202. case IRQ_RTCAlrm:
  203. mask = ADXER_WRTC;
  204. break;
  205. case IRQ_SSP4:
  206. mask = ADXER_MFP_WSSP4;
  207. break;
  208. case IRQ_TSI:
  209. mask = ADXER_WTSI;
  210. break;
  211. case IRQ_USIM2:
  212. mask = ADXER_WUSIM1;
  213. break;
  214. case IRQ_MMC2:
  215. mask = ADXER_MFP_WMMC2;
  216. break;
  217. case IRQ_NAND:
  218. mask = ADXER_MFP_WFLASH;
  219. break;
  220. case IRQ_USB2:
  221. mask = ADXER_WUSB2;
  222. break;
  223. case IRQ_WAKEUP0:
  224. mask = ADXER_WEXTWAKE0;
  225. break;
  226. case IRQ_WAKEUP1:
  227. mask = ADXER_WEXTWAKE1;
  228. break;
  229. case IRQ_MMC3:
  230. mask = ADXER_MFP_GEN12;
  231. break;
  232. default:
  233. return -EINVAL;
  234. }
  235. local_irq_save(flags);
  236. if (on)
  237. wakeup_src |= mask;
  238. else
  239. wakeup_src &= ~mask;
  240. local_irq_restore(flags);
  241. return 0;
  242. }
  243. #else
  244. static inline void pxa3xx_init_pm(void) {}
  245. #define pxa3xx_set_wake NULL
  246. #endif
  247. static void pxa_ack_ext_wakeup(struct irq_data *d)
  248. {
  249. PECR |= PECR_IS(d->irq - IRQ_WAKEUP0);
  250. }
  251. static void pxa_mask_ext_wakeup(struct irq_data *d)
  252. {
  253. pxa_mask_irq(d);
  254. PECR &= ~PECR_IE(d->irq - IRQ_WAKEUP0);
  255. }
  256. static void pxa_unmask_ext_wakeup(struct irq_data *d)
  257. {
  258. pxa_unmask_irq(d);
  259. PECR |= PECR_IE(d->irq - IRQ_WAKEUP0);
  260. }
  261. static int pxa_set_ext_wakeup_type(struct irq_data *d, unsigned int flow_type)
  262. {
  263. if (flow_type & IRQ_TYPE_EDGE_RISING)
  264. PWER |= 1 << (d->irq - IRQ_WAKEUP0);
  265. if (flow_type & IRQ_TYPE_EDGE_FALLING)
  266. PWER |= 1 << (d->irq - IRQ_WAKEUP0 + 2);
  267. return 0;
  268. }
  269. static struct irq_chip pxa_ext_wakeup_chip = {
  270. .name = "WAKEUP",
  271. .irq_ack = pxa_ack_ext_wakeup,
  272. .irq_mask = pxa_mask_ext_wakeup,
  273. .irq_unmask = pxa_unmask_ext_wakeup,
  274. .irq_set_type = pxa_set_ext_wakeup_type,
  275. };
  276. static void __init pxa_init_ext_wakeup_irq(int (*fn)(struct irq_data *,
  277. unsigned int))
  278. {
  279. int irq;
  280. for (irq = IRQ_WAKEUP0; irq <= IRQ_WAKEUP1; irq++) {
  281. irq_set_chip_and_handler(irq, &pxa_ext_wakeup_chip,
  282. handle_edge_irq);
  283. set_irq_flags(irq, IRQF_VALID);
  284. }
  285. pxa_ext_wakeup_chip.irq_set_wake = fn;
  286. }
  287. static void __init __pxa3xx_init_irq(void)
  288. {
  289. /* enable CP6 access */
  290. u32 value;
  291. __asm__ __volatile__("mrc p15, 0, %0, c15, c1, 0\n": "=r"(value));
  292. value |= (1 << 6);
  293. __asm__ __volatile__("mcr p15, 0, %0, c15, c1, 0\n": :"r"(value));
  294. pxa_init_ext_wakeup_irq(pxa3xx_set_wake);
  295. }
  296. void __init pxa3xx_init_irq(void)
  297. {
  298. __pxa3xx_init_irq();
  299. pxa_init_irq(56, pxa3xx_set_wake);
  300. }
  301. #ifdef CONFIG_OF
  302. void __init pxa3xx_dt_init_irq(void)
  303. {
  304. __pxa3xx_init_irq();
  305. pxa_dt_irq_init(pxa3xx_set_wake);
  306. }
  307. #endif /* CONFIG_OF */
  308. static struct map_desc pxa3xx_io_desc[] __initdata = {
  309. { /* Mem Ctl */
  310. .virtual = (unsigned long)SMEMC_VIRT,
  311. .pfn = __phys_to_pfn(PXA3XX_SMEMC_BASE),
  312. .length = SMEMC_SIZE,
  313. .type = MT_DEVICE
  314. }
  315. };
  316. void __init pxa3xx_map_io(void)
  317. {
  318. pxa_map_io();
  319. iotable_init(ARRAY_AND_SIZE(pxa3xx_io_desc));
  320. pxa3xx_get_clk_frequency_khz(1);
  321. }
  322. /*
  323. * device registration specific to PXA3xx.
  324. */
  325. void __init pxa3xx_set_i2c_power_info(struct i2c_pxa_platform_data *info)
  326. {
  327. pxa_register_device(&pxa3xx_device_i2c_power, info);
  328. }
  329. static struct pxa_gpio_platform_data pxa3xx_gpio_pdata = {
  330. .irq_base = PXA_GPIO_TO_IRQ(0),
  331. };
  332. static struct platform_device *devices[] __initdata = {
  333. &pxa27x_device_udc,
  334. &pxa_device_pmu,
  335. &pxa_device_i2s,
  336. &pxa_device_asoc_ssp1,
  337. &pxa_device_asoc_ssp2,
  338. &pxa_device_asoc_ssp3,
  339. &pxa_device_asoc_ssp4,
  340. &pxa_device_asoc_platform,
  341. &sa1100_device_rtc,
  342. &pxa_device_rtc,
  343. &pxa3xx_device_ssp1,
  344. &pxa3xx_device_ssp2,
  345. &pxa3xx_device_ssp3,
  346. &pxa3xx_device_ssp4,
  347. &pxa27x_device_pwm0,
  348. &pxa27x_device_pwm1,
  349. };
  350. static int __init pxa3xx_init(void)
  351. {
  352. int ret = 0;
  353. if (cpu_is_pxa3xx()) {
  354. reset_status = ARSR;
  355. /*
  356. * clear RDH bit every time after reset
  357. *
  358. * Note: the last 3 bits DxS are write-1-to-clear so carefully
  359. * preserve them here in case they will be referenced later
  360. */
  361. ASCR &= ~(ASCR_RDH | ASCR_D1S | ASCR_D2S | ASCR_D3S);
  362. if ((ret = pxa_init_dma(IRQ_DMA, 32)))
  363. return ret;
  364. pxa3xx_init_pm();
  365. register_syscore_ops(&pxa_irq_syscore_ops);
  366. register_syscore_ops(&pxa3xx_mfp_syscore_ops);
  367. if (of_have_populated_dt())
  368. return 0;
  369. ret = platform_add_devices(devices, ARRAY_SIZE(devices));
  370. if (ret)
  371. return ret;
  372. if (cpu_is_pxa300() || cpu_is_pxa310() || cpu_is_pxa320()) {
  373. platform_device_add_data(&pxa3xx_device_gpio,
  374. &pxa3xx_gpio_pdata,
  375. sizeof(pxa3xx_gpio_pdata));
  376. ret = platform_device_register(&pxa3xx_device_gpio);
  377. }
  378. }
  379. return ret;
  380. }
  381. postcore_initcall(pxa3xx_init);