pxa3xx.c 12 KB

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