pxa3xx.c 9.3 KB

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