pxa3xx.c 12 KB

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