pxa3xx.c 10.0 KB

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