pxa3xx.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  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/hardware.h>
  24. #include <asm/arch/pxa3xx-regs.h>
  25. #include <asm/arch/ohci.h>
  26. #include <asm/arch/pm.h>
  27. #include <asm/arch/dma.h>
  28. #include <asm/arch/ssp.h>
  29. #include "generic.h"
  30. #include "devices.h"
  31. #include "clock.h"
  32. /* Crystal clock: 13MHz */
  33. #define BASE_CLK 13000000
  34. /* Ring Oscillator Clock: 60MHz */
  35. #define RO_CLK 60000000
  36. #define ACCR_D0CS (1 << 26)
  37. #define ACCR_PCCE (1 << 11)
  38. /* crystal frequency to static memory controller multiplier (SMCFS) */
  39. static unsigned char smcfs_mult[8] = { 6, 0, 8, 0, 0, 16, };
  40. /* crystal frequency to HSIO bus frequency multiplier (HSS) */
  41. static unsigned char hss_mult[4] = { 8, 12, 16, 0 };
  42. /*
  43. * Get the clock frequency as reflected by CCSR and the turbo flag.
  44. * We assume these values have been applied via a fcs.
  45. * If info is not 0 we also display the current settings.
  46. */
  47. unsigned int pxa3xx_get_clk_frequency_khz(int info)
  48. {
  49. unsigned long acsr, xclkcfg;
  50. unsigned int t, xl, xn, hss, ro, XL, XN, CLK, HSS;
  51. /* Read XCLKCFG register turbo bit */
  52. __asm__ __volatile__("mrc\tp14, 0, %0, c6, c0, 0" : "=r"(xclkcfg));
  53. t = xclkcfg & 0x1;
  54. acsr = ACSR;
  55. xl = acsr & 0x1f;
  56. xn = (acsr >> 8) & 0x7;
  57. hss = (acsr >> 14) & 0x3;
  58. XL = xl * BASE_CLK;
  59. XN = xn * XL;
  60. ro = acsr & ACCR_D0CS;
  61. CLK = (ro) ? RO_CLK : ((t) ? XN : XL);
  62. HSS = (ro) ? RO_CLK : hss_mult[hss] * BASE_CLK;
  63. if (info) {
  64. pr_info("RO Mode clock: %d.%02dMHz (%sactive)\n",
  65. RO_CLK / 1000000, (RO_CLK % 1000000) / 10000,
  66. (ro) ? "" : "in");
  67. pr_info("Run Mode clock: %d.%02dMHz (*%d)\n",
  68. XL / 1000000, (XL % 1000000) / 10000, xl);
  69. pr_info("Turbo Mode clock: %d.%02dMHz (*%d, %sactive)\n",
  70. XN / 1000000, (XN % 1000000) / 10000, xn,
  71. (t) ? "" : "in");
  72. pr_info("HSIO bus clock: %d.%02dMHz\n",
  73. HSS / 1000000, (HSS % 1000000) / 10000);
  74. }
  75. return CLK / 1000;
  76. }
  77. /*
  78. * Return the current static memory controller clock frequency
  79. * in units of 10kHz
  80. */
  81. unsigned int pxa3xx_get_memclk_frequency_10khz(void)
  82. {
  83. unsigned long acsr;
  84. unsigned int smcfs, clk = 0;
  85. acsr = ACSR;
  86. smcfs = (acsr >> 23) & 0x7;
  87. clk = (acsr & ACCR_D0CS) ? RO_CLK : smcfs_mult[smcfs] * BASE_CLK;
  88. return (clk / 10000);
  89. }
  90. /*
  91. * Return the current HSIO bus clock frequency
  92. */
  93. static unsigned long clk_pxa3xx_hsio_getrate(struct clk *clk)
  94. {
  95. unsigned long acsr;
  96. unsigned int hss, hsio_clk;
  97. acsr = ACSR;
  98. hss = (acsr >> 14) & 0x3;
  99. hsio_clk = (acsr & ACCR_D0CS) ? RO_CLK : hss_mult[hss] * BASE_CLK;
  100. return hsio_clk;
  101. }
  102. static void clk_pxa3xx_cken_enable(struct clk *clk)
  103. {
  104. unsigned long mask = 1ul << (clk->cken & 0x1f);
  105. local_irq_disable();
  106. if (clk->cken < 32)
  107. CKENA |= mask;
  108. else
  109. CKENB |= mask;
  110. local_irq_enable();
  111. }
  112. static void clk_pxa3xx_cken_disable(struct clk *clk)
  113. {
  114. unsigned long mask = 1ul << (clk->cken & 0x1f);
  115. local_irq_disable();
  116. if (clk->cken < 32)
  117. CKENA &= ~mask;
  118. else
  119. CKENB &= ~mask;
  120. local_irq_enable();
  121. }
  122. static const struct clkops clk_pxa3xx_cken_ops = {
  123. .enable = clk_pxa3xx_cken_enable,
  124. .disable = clk_pxa3xx_cken_disable,
  125. };
  126. static const struct clkops clk_pxa3xx_hsio_ops = {
  127. .enable = clk_pxa3xx_cken_enable,
  128. .disable = clk_pxa3xx_cken_disable,
  129. .getrate = clk_pxa3xx_hsio_getrate,
  130. };
  131. #define PXA3xx_CKEN(_name, _cken, _rate, _delay, _dev) \
  132. { \
  133. .name = _name, \
  134. .dev = _dev, \
  135. .ops = &clk_pxa3xx_cken_ops, \
  136. .rate = _rate, \
  137. .cken = CKEN_##_cken, \
  138. .delay = _delay, \
  139. }
  140. #define PXA3xx_CK(_name, _cken, _ops, _dev) \
  141. { \
  142. .name = _name, \
  143. .dev = _dev, \
  144. .ops = _ops, \
  145. .cken = CKEN_##_cken, \
  146. }
  147. static struct clk pxa3xx_clks[] = {
  148. PXA3xx_CK("LCDCLK", LCD, &clk_pxa3xx_hsio_ops, &pxa_device_fb.dev),
  149. PXA3xx_CK("CAMCLK", CAMERA, &clk_pxa3xx_hsio_ops, NULL),
  150. PXA3xx_CKEN("UARTCLK", FFUART, 14857000, 1, &pxa_device_ffuart.dev),
  151. PXA3xx_CKEN("UARTCLK", BTUART, 14857000, 1, &pxa_device_btuart.dev),
  152. PXA3xx_CKEN("UARTCLK", STUART, 14857000, 1, NULL),
  153. PXA3xx_CKEN("I2CCLK", I2C, 32842000, 0, &pxa_device_i2c.dev),
  154. PXA3xx_CKEN("UDCCLK", UDC, 48000000, 5, &pxa_device_udc.dev),
  155. PXA3xx_CKEN("USBCLK", USBH, 48000000, 0, &pxa27x_device_ohci.dev),
  156. PXA3xx_CKEN("SSPCLK", SSP1, 13000000, 0, &pxa27x_device_ssp1.dev),
  157. PXA3xx_CKEN("SSPCLK", SSP2, 13000000, 0, &pxa27x_device_ssp2.dev),
  158. PXA3xx_CKEN("SSPCLK", SSP3, 13000000, 0, &pxa27x_device_ssp3.dev),
  159. PXA3xx_CKEN("SSPCLK", SSP4, 13000000, 0, &pxa3xx_device_ssp4.dev),
  160. PXA3xx_CKEN("MMCCLK", MMC1, 19500000, 0, &pxa_device_mci.dev),
  161. PXA3xx_CKEN("MMCCLK", MMC2, 19500000, 0, &pxa3xx_device_mci2.dev),
  162. PXA3xx_CKEN("MMCCLK", MMC3, 19500000, 0, &pxa3xx_device_mci3.dev),
  163. };
  164. #ifdef CONFIG_PM
  165. #define ISRAM_START 0x5c000000
  166. #define ISRAM_SIZE SZ_256K
  167. static void __iomem *sram;
  168. static unsigned long wakeup_src;
  169. #define SAVE(x) sleep_save[SLEEP_SAVE_##x] = x
  170. #define RESTORE(x) x = sleep_save[SLEEP_SAVE_##x]
  171. enum { SLEEP_SAVE_START = 0,
  172. SLEEP_SAVE_CKENA,
  173. SLEEP_SAVE_CKENB,
  174. SLEEP_SAVE_ACCR,
  175. SLEEP_SAVE_SIZE,
  176. };
  177. static void pxa3xx_cpu_pm_save(unsigned long *sleep_save)
  178. {
  179. SAVE(CKENA);
  180. SAVE(CKENB);
  181. SAVE(ACCR);
  182. }
  183. static void pxa3xx_cpu_pm_restore(unsigned long *sleep_save)
  184. {
  185. RESTORE(ACCR);
  186. RESTORE(CKENA);
  187. RESTORE(CKENB);
  188. }
  189. /*
  190. * Enter a standby mode (S0D1C2 or S0D2C2). Upon wakeup, the dynamic
  191. * memory controller has to be reinitialised, so we place some code
  192. * in the SRAM to perform this function.
  193. *
  194. * We disable FIQs across the standby - otherwise, we might receive a
  195. * FIQ while the SDRAM is unavailable.
  196. */
  197. static void pxa3xx_cpu_standby(unsigned int pwrmode)
  198. {
  199. extern const char pm_enter_standby_start[], pm_enter_standby_end[];
  200. void (*fn)(unsigned int) = (void __force *)(sram + 0x8000);
  201. memcpy_toio(sram + 0x8000, pm_enter_standby_start,
  202. pm_enter_standby_end - pm_enter_standby_start);
  203. AD2D0SR = ~0;
  204. AD2D1SR = ~0;
  205. AD2D0ER = wakeup_src;
  206. AD2D1ER = 0;
  207. ASCR = ASCR;
  208. ARSR = ARSR;
  209. local_fiq_disable();
  210. fn(pwrmode);
  211. local_fiq_enable();
  212. AD2D0ER = 0;
  213. AD2D1ER = 0;
  214. }
  215. /*
  216. * NOTE: currently, the OBM (OEM Boot Module) binary comes along with
  217. * PXA3xx development kits assumes that the resuming process continues
  218. * with the address stored within the first 4 bytes of SDRAM. The PSPR
  219. * register is used privately by BootROM and OBM, and _must_ be set to
  220. * 0x5c014000 for the moment.
  221. */
  222. static void pxa3xx_cpu_pm_suspend(void)
  223. {
  224. volatile unsigned long *p = (volatile void *)0xc0000000;
  225. unsigned long saved_data = *p;
  226. extern void pxa3xx_cpu_suspend(void);
  227. extern void pxa3xx_cpu_resume(void);
  228. /* resuming from D2 requires the HSIO2/BOOT/TPM clocks enabled */
  229. CKENA |= (1 << CKEN_BOOT) | (1 << CKEN_TPM);
  230. CKENB |= 1 << (CKEN_HSIO2 & 0x1f);
  231. /* clear and setup wakeup source */
  232. AD3SR = ~0;
  233. AD3ER = wakeup_src;
  234. ASCR = ASCR;
  235. ARSR = ARSR;
  236. PCFR |= (1u << 13); /* L1_DIS */
  237. PCFR &= ~((1u << 12) | (1u << 1)); /* L0_EN | SL_ROD */
  238. PSPR = 0x5c014000;
  239. /* overwrite with the resume address */
  240. *p = virt_to_phys(pxa3xx_cpu_resume);
  241. pxa3xx_cpu_suspend();
  242. *p = saved_data;
  243. AD3ER = 0;
  244. }
  245. static void pxa3xx_cpu_pm_enter(suspend_state_t state)
  246. {
  247. /*
  248. * Don't sleep if no wakeup sources are defined
  249. */
  250. if (wakeup_src == 0)
  251. return;
  252. switch (state) {
  253. case PM_SUSPEND_STANDBY:
  254. pxa3xx_cpu_standby(PXA3xx_PM_S0D2C2);
  255. break;
  256. case PM_SUSPEND_MEM:
  257. pxa3xx_cpu_pm_suspend();
  258. break;
  259. }
  260. }
  261. static int pxa3xx_cpu_pm_valid(suspend_state_t state)
  262. {
  263. return state == PM_SUSPEND_MEM || state == PM_SUSPEND_STANDBY;
  264. }
  265. static struct pxa_cpu_pm_fns pxa3xx_cpu_pm_fns = {
  266. .save_size = SLEEP_SAVE_SIZE,
  267. .save = pxa3xx_cpu_pm_save,
  268. .restore = pxa3xx_cpu_pm_restore,
  269. .valid = pxa3xx_cpu_pm_valid,
  270. .enter = pxa3xx_cpu_pm_enter,
  271. };
  272. static void __init pxa3xx_init_pm(void)
  273. {
  274. sram = ioremap(ISRAM_START, ISRAM_SIZE);
  275. if (!sram) {
  276. printk(KERN_ERR "Unable to map ISRAM: disabling standby/suspend\n");
  277. return;
  278. }
  279. /*
  280. * Since we copy wakeup code into the SRAM, we need to ensure
  281. * that it is preserved over the low power modes. Note: bit 8
  282. * is undocumented in the developer manual, but must be set.
  283. */
  284. AD1R |= ADXR_L2 | ADXR_R0;
  285. AD2R |= ADXR_L2 | ADXR_R0;
  286. AD3R |= ADXR_L2 | ADXR_R0;
  287. /*
  288. * Clear the resume enable registers.
  289. */
  290. AD1D0ER = 0;
  291. AD2D0ER = 0;
  292. AD2D1ER = 0;
  293. AD3ER = 0;
  294. pxa_cpu_pm_fns = &pxa3xx_cpu_pm_fns;
  295. }
  296. static int pxa3xx_set_wake(unsigned int irq, unsigned int on)
  297. {
  298. unsigned long flags, mask = 0;
  299. switch (irq) {
  300. case IRQ_SSP3:
  301. mask = ADXER_MFP_WSSP3;
  302. break;
  303. case IRQ_MSL:
  304. mask = ADXER_WMSL0;
  305. break;
  306. case IRQ_USBH2:
  307. case IRQ_USBH1:
  308. mask = ADXER_WUSBH;
  309. break;
  310. case IRQ_KEYPAD:
  311. mask = ADXER_WKP;
  312. break;
  313. case IRQ_AC97:
  314. mask = ADXER_MFP_WAC97;
  315. break;
  316. case IRQ_USIM:
  317. mask = ADXER_WUSIM0;
  318. break;
  319. case IRQ_SSP2:
  320. mask = ADXER_MFP_WSSP2;
  321. break;
  322. case IRQ_I2C:
  323. mask = ADXER_MFP_WI2C;
  324. break;
  325. case IRQ_STUART:
  326. mask = ADXER_MFP_WUART3;
  327. break;
  328. case IRQ_BTUART:
  329. mask = ADXER_MFP_WUART2;
  330. break;
  331. case IRQ_FFUART:
  332. mask = ADXER_MFP_WUART1;
  333. break;
  334. case IRQ_MMC:
  335. mask = ADXER_MFP_WMMC1;
  336. break;
  337. case IRQ_SSP:
  338. mask = ADXER_MFP_WSSP1;
  339. break;
  340. case IRQ_RTCAlrm:
  341. mask = ADXER_WRTC;
  342. break;
  343. case IRQ_SSP4:
  344. mask = ADXER_MFP_WSSP4;
  345. break;
  346. case IRQ_TSI:
  347. mask = ADXER_WTSI;
  348. break;
  349. case IRQ_USIM2:
  350. mask = ADXER_WUSIM1;
  351. break;
  352. case IRQ_MMC2:
  353. mask = ADXER_MFP_WMMC2;
  354. break;
  355. case IRQ_NAND:
  356. mask = ADXER_MFP_WFLASH;
  357. break;
  358. case IRQ_USB2:
  359. mask = ADXER_WUSB2;
  360. break;
  361. case IRQ_WAKEUP0:
  362. mask = ADXER_WEXTWAKE0;
  363. break;
  364. case IRQ_WAKEUP1:
  365. mask = ADXER_WEXTWAKE1;
  366. break;
  367. case IRQ_MMC3:
  368. mask = ADXER_MFP_GEN12;
  369. break;
  370. }
  371. local_irq_save(flags);
  372. if (on)
  373. wakeup_src |= mask;
  374. else
  375. wakeup_src &= ~mask;
  376. local_irq_restore(flags);
  377. return 0;
  378. }
  379. static void pxa3xx_init_irq_pm(void)
  380. {
  381. pxa_init_irq_set_wake(pxa3xx_set_wake);
  382. }
  383. #else
  384. static inline void pxa3xx_init_pm(void) {}
  385. static inline void pxa3xx_init_irq_pm(void) {}
  386. #endif
  387. void __init pxa3xx_init_irq(void)
  388. {
  389. /* enable CP6 access */
  390. u32 value;
  391. __asm__ __volatile__("mrc p15, 0, %0, c15, c1, 0\n": "=r"(value));
  392. value |= (1 << 6);
  393. __asm__ __volatile__("mcr p15, 0, %0, c15, c1, 0\n": :"r"(value));
  394. pxa_init_irq_low();
  395. pxa_init_irq_high();
  396. pxa_init_irq_gpio(128);
  397. pxa3xx_init_irq_pm();
  398. }
  399. /*
  400. * device registration specific to PXA3xx.
  401. */
  402. static struct platform_device *devices[] __initdata = {
  403. &pxa_device_udc,
  404. &pxa_device_ffuart,
  405. &pxa_device_btuart,
  406. &pxa_device_stuart,
  407. &pxa_device_i2s,
  408. &pxa_device_rtc,
  409. &pxa27x_device_ssp1,
  410. &pxa27x_device_ssp2,
  411. &pxa27x_device_ssp3,
  412. &pxa3xx_device_ssp4,
  413. };
  414. static struct sys_device pxa3xx_sysdev[] = {
  415. {
  416. .id = 0,
  417. .cls = &pxa_irq_sysclass,
  418. }, {
  419. .id = 1,
  420. .cls = &pxa_irq_sysclass,
  421. }, {
  422. .cls = &pxa_gpio_sysclass,
  423. },
  424. };
  425. static int __init pxa3xx_init(void)
  426. {
  427. int i, ret = 0;
  428. if (cpu_is_pxa3xx()) {
  429. /*
  430. * clear RDH bit every time after reset
  431. *
  432. * Note: the last 3 bits DxS are write-1-to-clear so carefully
  433. * preserve them here in case they will be referenced later
  434. */
  435. ASCR &= ~(ASCR_RDH | ASCR_D1S | ASCR_D2S | ASCR_D3S);
  436. clks_register(pxa3xx_clks, ARRAY_SIZE(pxa3xx_clks));
  437. if ((ret = pxa_init_dma(32)))
  438. return ret;
  439. pxa3xx_init_pm();
  440. for (i = 0; i < ARRAY_SIZE(pxa3xx_sysdev); i++) {
  441. ret = sysdev_register(&pxa3xx_sysdev[i]);
  442. if (ret)
  443. pr_err("failed to register sysdev[%d]\n", i);
  444. }
  445. ret = platform_add_devices(devices, ARRAY_SIZE(devices));
  446. }
  447. return ret;
  448. }
  449. subsys_initcall(pxa3xx_init);