pxa3xx.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  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/pm.h>
  19. #include <linux/platform_device.h>
  20. #include <linux/irq.h>
  21. #include <linux/io.h>
  22. #include <linux/sysdev.h>
  23. #include <asm/mach/map.h>
  24. #include <mach/hardware.h>
  25. #include <mach/gpio.h>
  26. #include <mach/pxa3xx-regs.h>
  27. #include <mach/reset.h>
  28. #include <mach/ohci.h>
  29. #include <mach/pm.h>
  30. #include <mach/dma.h>
  31. #include <mach/regs-intc.h>
  32. #include <mach/smemc.h>
  33. #include <plat/i2c.h>
  34. #include "generic.h"
  35. #include "devices.h"
  36. #include "clock.h"
  37. #define PECR_IE(n) ((1 << ((n) * 2)) << 28)
  38. #define PECR_IS(n) ((1 << ((n) * 2)) << 29)
  39. void pxa3xx_clear_reset_status(unsigned int mask)
  40. {
  41. /* RESET_STATUS_* has a 1:1 mapping with ARSR */
  42. ARSR = mask;
  43. }
  44. static DEFINE_PXA3_CKEN(pxa3xx_ffuart, FFUART, 14857000, 1);
  45. static DEFINE_PXA3_CKEN(pxa3xx_btuart, BTUART, 14857000, 1);
  46. static DEFINE_PXA3_CKEN(pxa3xx_stuart, STUART, 14857000, 1);
  47. static DEFINE_PXA3_CKEN(pxa3xx_i2c, I2C, 32842000, 0);
  48. static DEFINE_PXA3_CKEN(pxa3xx_udc, UDC, 48000000, 5);
  49. static DEFINE_PXA3_CKEN(pxa3xx_usbh, USBH, 48000000, 0);
  50. static DEFINE_PXA3_CKEN(pxa3xx_u2d, USB2, 48000000, 0);
  51. static DEFINE_PXA3_CKEN(pxa3xx_keypad, KEYPAD, 32768, 0);
  52. static DEFINE_PXA3_CKEN(pxa3xx_ssp1, SSP1, 13000000, 0);
  53. static DEFINE_PXA3_CKEN(pxa3xx_ssp2, SSP2, 13000000, 0);
  54. static DEFINE_PXA3_CKEN(pxa3xx_ssp3, SSP3, 13000000, 0);
  55. static DEFINE_PXA3_CKEN(pxa3xx_ssp4, SSP4, 13000000, 0);
  56. static DEFINE_PXA3_CKEN(pxa3xx_pwm0, PWM0, 13000000, 0);
  57. static DEFINE_PXA3_CKEN(pxa3xx_pwm1, PWM1, 13000000, 0);
  58. static DEFINE_PXA3_CKEN(pxa3xx_mmc1, MMC1, 19500000, 0);
  59. static DEFINE_PXA3_CKEN(pxa3xx_mmc2, MMC2, 19500000, 0);
  60. static DEFINE_CK(pxa3xx_lcd, LCD, &clk_pxa3xx_hsio_ops);
  61. static DEFINE_CK(pxa3xx_camera, CAMERA, &clk_pxa3xx_hsio_ops);
  62. static DEFINE_CK(pxa3xx_ac97, AC97, &clk_pxa3xx_ac97_ops);
  63. static DEFINE_CLK(pxa3xx_pout, &clk_pxa3xx_pout_ops, 13000000, 70);
  64. static struct clk_lookup pxa3xx_clkregs[] = {
  65. INIT_CLKREG(&clk_pxa3xx_pout, NULL, "CLK_POUT"),
  66. /* Power I2C clock is always on */
  67. INIT_CLKREG(&clk_dummy, "pxa3xx-pwri2c.1", NULL),
  68. INIT_CLKREG(&clk_pxa3xx_lcd, "pxa2xx-fb", NULL),
  69. INIT_CLKREG(&clk_pxa3xx_camera, NULL, "CAMCLK"),
  70. INIT_CLKREG(&clk_pxa3xx_ac97, NULL, "AC97CLK"),
  71. INIT_CLKREG(&clk_pxa3xx_ffuart, "pxa2xx-uart.0", NULL),
  72. INIT_CLKREG(&clk_pxa3xx_btuart, "pxa2xx-uart.1", NULL),
  73. INIT_CLKREG(&clk_pxa3xx_stuart, "pxa2xx-uart.2", NULL),
  74. INIT_CLKREG(&clk_pxa3xx_stuart, "pxa2xx-ir", "UARTCLK"),
  75. INIT_CLKREG(&clk_pxa3xx_i2c, "pxa2xx-i2c.0", NULL),
  76. INIT_CLKREG(&clk_pxa3xx_udc, "pxa27x-udc", NULL),
  77. INIT_CLKREG(&clk_pxa3xx_usbh, "pxa27x-ohci", NULL),
  78. INIT_CLKREG(&clk_pxa3xx_u2d, "pxa3xx-u2d", NULL),
  79. INIT_CLKREG(&clk_pxa3xx_keypad, "pxa27x-keypad", NULL),
  80. INIT_CLKREG(&clk_pxa3xx_ssp1, "pxa27x-ssp.0", NULL),
  81. INIT_CLKREG(&clk_pxa3xx_ssp2, "pxa27x-ssp.1", NULL),
  82. INIT_CLKREG(&clk_pxa3xx_ssp3, "pxa27x-ssp.2", NULL),
  83. INIT_CLKREG(&clk_pxa3xx_ssp4, "pxa27x-ssp.3", NULL),
  84. INIT_CLKREG(&clk_pxa3xx_pwm0, "pxa27x-pwm.0", NULL),
  85. INIT_CLKREG(&clk_pxa3xx_pwm1, "pxa27x-pwm.1", NULL),
  86. INIT_CLKREG(&clk_pxa3xx_mmc1, "pxa2xx-mci.0", NULL),
  87. INIT_CLKREG(&clk_pxa3xx_mmc2, "pxa2xx-mci.1", NULL),
  88. };
  89. #ifdef CONFIG_PM
  90. #define ISRAM_START 0x5c000000
  91. #define ISRAM_SIZE SZ_256K
  92. static void __iomem *sram;
  93. static unsigned long wakeup_src;
  94. #define SAVE(x) sleep_save[SLEEP_SAVE_##x] = x
  95. #define RESTORE(x) x = sleep_save[SLEEP_SAVE_##x]
  96. enum { SLEEP_SAVE_CKENA,
  97. SLEEP_SAVE_CKENB,
  98. SLEEP_SAVE_ACCR,
  99. SLEEP_SAVE_COUNT,
  100. };
  101. static void pxa3xx_cpu_pm_save(unsigned long *sleep_save)
  102. {
  103. SAVE(CKENA);
  104. SAVE(CKENB);
  105. SAVE(ACCR);
  106. }
  107. static void pxa3xx_cpu_pm_restore(unsigned long *sleep_save)
  108. {
  109. RESTORE(ACCR);
  110. RESTORE(CKENA);
  111. RESTORE(CKENB);
  112. }
  113. /*
  114. * Enter a standby mode (S0D1C2 or S0D2C2). Upon wakeup, the dynamic
  115. * memory controller has to be reinitialised, so we place some code
  116. * in the SRAM to perform this function.
  117. *
  118. * We disable FIQs across the standby - otherwise, we might receive a
  119. * FIQ while the SDRAM is unavailable.
  120. */
  121. static void pxa3xx_cpu_standby(unsigned int pwrmode)
  122. {
  123. extern const char pm_enter_standby_start[], pm_enter_standby_end[];
  124. void (*fn)(unsigned int) = (void __force *)(sram + 0x8000);
  125. memcpy_toio(sram + 0x8000, pm_enter_standby_start,
  126. pm_enter_standby_end - pm_enter_standby_start);
  127. AD2D0SR = ~0;
  128. AD2D1SR = ~0;
  129. AD2D0ER = wakeup_src;
  130. AD2D1ER = 0;
  131. ASCR = ASCR;
  132. ARSR = ARSR;
  133. local_fiq_disable();
  134. fn(pwrmode);
  135. local_fiq_enable();
  136. AD2D0ER = 0;
  137. AD2D1ER = 0;
  138. }
  139. /*
  140. * NOTE: currently, the OBM (OEM Boot Module) binary comes along with
  141. * PXA3xx development kits assumes that the resuming process continues
  142. * with the address stored within the first 4 bytes of SDRAM. The PSPR
  143. * register is used privately by BootROM and OBM, and _must_ be set to
  144. * 0x5c014000 for the moment.
  145. */
  146. static void pxa3xx_cpu_pm_suspend(void)
  147. {
  148. volatile unsigned long *p = (volatile void *)0xc0000000;
  149. unsigned long saved_data = *p;
  150. extern void pxa3xx_cpu_suspend(void);
  151. extern void pxa3xx_cpu_resume(void);
  152. /* resuming from D2 requires the HSIO2/BOOT/TPM clocks enabled */
  153. CKENA |= (1 << CKEN_BOOT) | (1 << CKEN_TPM);
  154. CKENB |= 1 << (CKEN_HSIO2 & 0x1f);
  155. /* clear and setup wakeup source */
  156. AD3SR = ~0;
  157. AD3ER = wakeup_src;
  158. ASCR = ASCR;
  159. ARSR = ARSR;
  160. PCFR |= (1u << 13); /* L1_DIS */
  161. PCFR &= ~((1u << 12) | (1u << 1)); /* L0_EN | SL_ROD */
  162. PSPR = 0x5c014000;
  163. /* overwrite with the resume address */
  164. *p = virt_to_phys(pxa3xx_cpu_resume);
  165. pxa3xx_cpu_suspend();
  166. *p = saved_data;
  167. AD3ER = 0;
  168. }
  169. static void pxa3xx_cpu_pm_enter(suspend_state_t state)
  170. {
  171. /*
  172. * Don't sleep if no wakeup sources are defined
  173. */
  174. if (wakeup_src == 0) {
  175. printk(KERN_ERR "Not suspending: no wakeup sources\n");
  176. return;
  177. }
  178. switch (state) {
  179. case PM_SUSPEND_STANDBY:
  180. pxa3xx_cpu_standby(PXA3xx_PM_S0D2C2);
  181. break;
  182. case PM_SUSPEND_MEM:
  183. pxa3xx_cpu_pm_suspend();
  184. break;
  185. }
  186. }
  187. static int pxa3xx_cpu_pm_valid(suspend_state_t state)
  188. {
  189. return state == PM_SUSPEND_MEM || state == PM_SUSPEND_STANDBY;
  190. }
  191. static struct pxa_cpu_pm_fns pxa3xx_cpu_pm_fns = {
  192. .save_count = SLEEP_SAVE_COUNT,
  193. .save = pxa3xx_cpu_pm_save,
  194. .restore = pxa3xx_cpu_pm_restore,
  195. .valid = pxa3xx_cpu_pm_valid,
  196. .enter = pxa3xx_cpu_pm_enter,
  197. };
  198. static void __init pxa3xx_init_pm(void)
  199. {
  200. sram = ioremap(ISRAM_START, ISRAM_SIZE);
  201. if (!sram) {
  202. printk(KERN_ERR "Unable to map ISRAM: disabling standby/suspend\n");
  203. return;
  204. }
  205. /*
  206. * Since we copy wakeup code into the SRAM, we need to ensure
  207. * that it is preserved over the low power modes. Note: bit 8
  208. * is undocumented in the developer manual, but must be set.
  209. */
  210. AD1R |= ADXR_L2 | ADXR_R0;
  211. AD2R |= ADXR_L2 | ADXR_R0;
  212. AD3R |= ADXR_L2 | ADXR_R0;
  213. /*
  214. * Clear the resume enable registers.
  215. */
  216. AD1D0ER = 0;
  217. AD2D0ER = 0;
  218. AD2D1ER = 0;
  219. AD3ER = 0;
  220. pxa_cpu_pm_fns = &pxa3xx_cpu_pm_fns;
  221. }
  222. static int pxa3xx_set_wake(unsigned int irq, unsigned int on)
  223. {
  224. unsigned long flags, mask = 0;
  225. switch (irq) {
  226. case IRQ_SSP3:
  227. mask = ADXER_MFP_WSSP3;
  228. break;
  229. case IRQ_MSL:
  230. mask = ADXER_WMSL0;
  231. break;
  232. case IRQ_USBH2:
  233. case IRQ_USBH1:
  234. mask = ADXER_WUSBH;
  235. break;
  236. case IRQ_KEYPAD:
  237. mask = ADXER_WKP;
  238. break;
  239. case IRQ_AC97:
  240. mask = ADXER_MFP_WAC97;
  241. break;
  242. case IRQ_USIM:
  243. mask = ADXER_WUSIM0;
  244. break;
  245. case IRQ_SSP2:
  246. mask = ADXER_MFP_WSSP2;
  247. break;
  248. case IRQ_I2C:
  249. mask = ADXER_MFP_WI2C;
  250. break;
  251. case IRQ_STUART:
  252. mask = ADXER_MFP_WUART3;
  253. break;
  254. case IRQ_BTUART:
  255. mask = ADXER_MFP_WUART2;
  256. break;
  257. case IRQ_FFUART:
  258. mask = ADXER_MFP_WUART1;
  259. break;
  260. case IRQ_MMC:
  261. mask = ADXER_MFP_WMMC1;
  262. break;
  263. case IRQ_SSP:
  264. mask = ADXER_MFP_WSSP1;
  265. break;
  266. case IRQ_RTCAlrm:
  267. mask = ADXER_WRTC;
  268. break;
  269. case IRQ_SSP4:
  270. mask = ADXER_MFP_WSSP4;
  271. break;
  272. case IRQ_TSI:
  273. mask = ADXER_WTSI;
  274. break;
  275. case IRQ_USIM2:
  276. mask = ADXER_WUSIM1;
  277. break;
  278. case IRQ_MMC2:
  279. mask = ADXER_MFP_WMMC2;
  280. break;
  281. case IRQ_NAND:
  282. mask = ADXER_MFP_WFLASH;
  283. break;
  284. case IRQ_USB2:
  285. mask = ADXER_WUSB2;
  286. break;
  287. case IRQ_WAKEUP0:
  288. mask = ADXER_WEXTWAKE0;
  289. break;
  290. case IRQ_WAKEUP1:
  291. mask = ADXER_WEXTWAKE1;
  292. break;
  293. case IRQ_MMC3:
  294. mask = ADXER_MFP_GEN12;
  295. break;
  296. default:
  297. return -EINVAL;
  298. }
  299. local_irq_save(flags);
  300. if (on)
  301. wakeup_src |= mask;
  302. else
  303. wakeup_src &= ~mask;
  304. local_irq_restore(flags);
  305. return 0;
  306. }
  307. #else
  308. static inline void pxa3xx_init_pm(void) {}
  309. #define pxa3xx_set_wake NULL
  310. #endif
  311. static void pxa_ack_ext_wakeup(unsigned int irq)
  312. {
  313. PECR |= PECR_IS(irq - IRQ_WAKEUP0);
  314. }
  315. static void pxa_mask_ext_wakeup(unsigned int irq)
  316. {
  317. ICMR2 &= ~(1 << ((irq - PXA_IRQ(0)) & 0x1f));
  318. PECR &= ~PECR_IE(irq - IRQ_WAKEUP0);
  319. }
  320. static void pxa_unmask_ext_wakeup(unsigned int irq)
  321. {
  322. ICMR2 |= 1 << ((irq - PXA_IRQ(0)) & 0x1f);
  323. PECR |= PECR_IE(irq - IRQ_WAKEUP0);
  324. }
  325. static int pxa_set_ext_wakeup_type(unsigned int irq, unsigned int flow_type)
  326. {
  327. if (flow_type & IRQ_TYPE_EDGE_RISING)
  328. PWER |= 1 << (irq - IRQ_WAKEUP0);
  329. if (flow_type & IRQ_TYPE_EDGE_FALLING)
  330. PWER |= 1 << (irq - IRQ_WAKEUP0 + 2);
  331. return 0;
  332. }
  333. static struct irq_chip pxa_ext_wakeup_chip = {
  334. .name = "WAKEUP",
  335. .ack = pxa_ack_ext_wakeup,
  336. .mask = pxa_mask_ext_wakeup,
  337. .unmask = pxa_unmask_ext_wakeup,
  338. .set_type = pxa_set_ext_wakeup_type,
  339. };
  340. static void __init pxa_init_ext_wakeup_irq(set_wake_t fn)
  341. {
  342. int irq;
  343. for (irq = IRQ_WAKEUP0; irq <= IRQ_WAKEUP1; irq++) {
  344. set_irq_chip(irq, &pxa_ext_wakeup_chip);
  345. set_irq_handler(irq, handle_edge_irq);
  346. set_irq_flags(irq, IRQF_VALID);
  347. }
  348. pxa_ext_wakeup_chip.set_wake = fn;
  349. }
  350. void __init pxa3xx_init_irq(void)
  351. {
  352. /* enable CP6 access */
  353. u32 value;
  354. __asm__ __volatile__("mrc p15, 0, %0, c15, c1, 0\n": "=r"(value));
  355. value |= (1 << 6);
  356. __asm__ __volatile__("mcr p15, 0, %0, c15, c1, 0\n": :"r"(value));
  357. pxa_init_irq(56, pxa3xx_set_wake);
  358. pxa_init_ext_wakeup_irq(pxa3xx_set_wake);
  359. pxa_init_gpio(IRQ_GPIO_2_x, 2, 127, NULL);
  360. }
  361. static struct map_desc pxa3xx_io_desc[] __initdata = {
  362. { /* Mem Ctl */
  363. .virtual = SMEMC_VIRT,
  364. .pfn = __phys_to_pfn(PXA3XX_SMEMC_BASE),
  365. .length = 0x00200000,
  366. .type = MT_DEVICE
  367. }
  368. };
  369. void __init pxa3xx_map_io(void)
  370. {
  371. pxa_map_io();
  372. iotable_init(ARRAY_AND_SIZE(pxa3xx_io_desc));
  373. pxa3xx_get_clk_frequency_khz(1);
  374. }
  375. /*
  376. * device registration specific to PXA3xx.
  377. */
  378. void __init pxa3xx_set_i2c_power_info(struct i2c_pxa_platform_data *info)
  379. {
  380. pxa_register_device(&pxa3xx_device_i2c_power, info);
  381. }
  382. static struct platform_device *devices[] __initdata = {
  383. &pxa27x_device_udc,
  384. &pxa_device_pmu,
  385. &pxa_device_i2s,
  386. &pxa_device_asoc_ssp1,
  387. &pxa_device_asoc_ssp2,
  388. &pxa_device_asoc_ssp3,
  389. &pxa_device_asoc_ssp4,
  390. &pxa_device_asoc_platform,
  391. &sa1100_device_rtc,
  392. &pxa_device_rtc,
  393. &pxa27x_device_ssp1,
  394. &pxa27x_device_ssp2,
  395. &pxa27x_device_ssp3,
  396. &pxa3xx_device_ssp4,
  397. &pxa27x_device_pwm0,
  398. &pxa27x_device_pwm1,
  399. };
  400. static struct sys_device pxa3xx_sysdev[] = {
  401. {
  402. .cls = &pxa_irq_sysclass,
  403. }, {
  404. .cls = &pxa3xx_mfp_sysclass,
  405. }, {
  406. .cls = &pxa_gpio_sysclass,
  407. },
  408. };
  409. static int __init pxa3xx_init(void)
  410. {
  411. int i, ret = 0;
  412. if (cpu_is_pxa3xx()) {
  413. reset_status = ARSR;
  414. /*
  415. * clear RDH bit every time after reset
  416. *
  417. * Note: the last 3 bits DxS are write-1-to-clear so carefully
  418. * preserve them here in case they will be referenced later
  419. */
  420. ASCR &= ~(ASCR_RDH | ASCR_D1S | ASCR_D2S | ASCR_D3S);
  421. clkdev_add_table(pxa3xx_clkregs, ARRAY_SIZE(pxa3xx_clkregs));
  422. if ((ret = pxa_init_dma(IRQ_DMA, 32)))
  423. return ret;
  424. pxa3xx_init_pm();
  425. for (i = 0; i < ARRAY_SIZE(pxa3xx_sysdev); i++) {
  426. ret = sysdev_register(&pxa3xx_sysdev[i]);
  427. if (ret)
  428. pr_err("failed to register sysdev[%d]\n", i);
  429. }
  430. ret = platform_add_devices(devices, ARRAY_SIZE(devices));
  431. }
  432. return ret;
  433. }
  434. postcore_initcall(pxa3xx_init);