pxa3xx.c 10 KB

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