pxa3xx.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  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 <asm/hardware.h>
  23. #include <asm/arch/pxa3xx-regs.h>
  24. #include <asm/arch/ohci.h>
  25. #include <asm/arch/pm.h>
  26. #include <asm/arch/dma.h>
  27. #include <asm/arch/ssp.h>
  28. #include "generic.h"
  29. #include "devices.h"
  30. #include "clock.h"
  31. /* Crystal clock: 13MHz */
  32. #define BASE_CLK 13000000
  33. /* Ring Oscillator Clock: 60MHz */
  34. #define RO_CLK 60000000
  35. #define ACCR_D0CS (1 << 26)
  36. /* crystal frequency to static memory controller multiplier (SMCFS) */
  37. static unsigned char smcfs_mult[8] = { 6, 0, 8, 0, 0, 16, };
  38. /* crystal frequency to HSIO bus frequency multiplier (HSS) */
  39. static unsigned char hss_mult[4] = { 8, 12, 16, 0 };
  40. /*
  41. * Get the clock frequency as reflected by CCSR and the turbo flag.
  42. * We assume these values have been applied via a fcs.
  43. * If info is not 0 we also display the current settings.
  44. */
  45. unsigned int pxa3xx_get_clk_frequency_khz(int info)
  46. {
  47. unsigned long acsr, xclkcfg;
  48. unsigned int t, xl, xn, hss, ro, XL, XN, CLK, HSS;
  49. /* Read XCLKCFG register turbo bit */
  50. __asm__ __volatile__("mrc\tp14, 0, %0, c6, c0, 0" : "=r"(xclkcfg));
  51. t = xclkcfg & 0x1;
  52. acsr = ACSR;
  53. xl = acsr & 0x1f;
  54. xn = (acsr >> 8) & 0x7;
  55. hss = (acsr >> 14) & 0x3;
  56. XL = xl * BASE_CLK;
  57. XN = xn * XL;
  58. ro = acsr & ACCR_D0CS;
  59. CLK = (ro) ? RO_CLK : ((t) ? XN : XL);
  60. HSS = (ro) ? RO_CLK : hss_mult[hss] * BASE_CLK;
  61. if (info) {
  62. pr_info("RO Mode clock: %d.%02dMHz (%sactive)\n",
  63. RO_CLK / 1000000, (RO_CLK % 1000000) / 10000,
  64. (ro) ? "" : "in");
  65. pr_info("Run Mode clock: %d.%02dMHz (*%d)\n",
  66. XL / 1000000, (XL % 1000000) / 10000, xl);
  67. pr_info("Turbo Mode clock: %d.%02dMHz (*%d, %sactive)\n",
  68. XN / 1000000, (XN % 1000000) / 10000, xn,
  69. (t) ? "" : "in");
  70. pr_info("HSIO bus clock: %d.%02dMHz\n",
  71. HSS / 1000000, (HSS % 1000000) / 10000);
  72. }
  73. return CLK / 1000;
  74. }
  75. /*
  76. * Return the current static memory controller clock frequency
  77. * in units of 10kHz
  78. */
  79. unsigned int pxa3xx_get_memclk_frequency_10khz(void)
  80. {
  81. unsigned long acsr;
  82. unsigned int smcfs, clk = 0;
  83. acsr = ACSR;
  84. smcfs = (acsr >> 23) & 0x7;
  85. clk = (acsr & ACCR_D0CS) ? RO_CLK : smcfs_mult[smcfs] * BASE_CLK;
  86. return (clk / 10000);
  87. }
  88. /*
  89. * Return the current HSIO bus clock frequency
  90. */
  91. static unsigned long clk_pxa3xx_hsio_getrate(struct clk *clk)
  92. {
  93. unsigned long acsr;
  94. unsigned int hss, hsio_clk;
  95. acsr = ACSR;
  96. hss = (acsr >> 14) & 0x3;
  97. hsio_clk = (acsr & ACCR_D0CS) ? RO_CLK : hss_mult[hss] * BASE_CLK;
  98. return hsio_clk;
  99. }
  100. static void clk_pxa3xx_cken_enable(struct clk *clk)
  101. {
  102. unsigned long mask = 1ul << (clk->cken & 0x1f);
  103. local_irq_disable();
  104. if (clk->cken < 32)
  105. CKENA |= mask;
  106. else
  107. CKENB |= mask;
  108. local_irq_enable();
  109. }
  110. static void clk_pxa3xx_cken_disable(struct clk *clk)
  111. {
  112. unsigned long mask = 1ul << (clk->cken & 0x1f);
  113. local_irq_disable();
  114. if (clk->cken < 32)
  115. CKENA &= ~mask;
  116. else
  117. CKENB &= ~mask;
  118. local_irq_enable();
  119. }
  120. static const struct clkops clk_pxa3xx_cken_ops = {
  121. .enable = clk_pxa3xx_cken_enable,
  122. .disable = clk_pxa3xx_cken_disable,
  123. };
  124. static const struct clkops clk_pxa3xx_hsio_ops = {
  125. .enable = clk_pxa3xx_cken_enable,
  126. .disable = clk_pxa3xx_cken_disable,
  127. .getrate = clk_pxa3xx_hsio_getrate,
  128. };
  129. #define PXA3xx_CKEN(_name, _cken, _rate, _delay, _dev) \
  130. { \
  131. .name = _name, \
  132. .dev = _dev, \
  133. .ops = &clk_pxa3xx_cken_ops, \
  134. .rate = _rate, \
  135. .cken = CKEN_##_cken, \
  136. .delay = _delay, \
  137. }
  138. #define PXA3xx_CK(_name, _cken, _ops, _dev) \
  139. { \
  140. .name = _name, \
  141. .dev = _dev, \
  142. .ops = _ops, \
  143. .cken = CKEN_##_cken, \
  144. }
  145. static struct clk pxa3xx_clks[] = {
  146. PXA3xx_CK("LCDCLK", LCD, &clk_pxa3xx_hsio_ops, &pxa_device_fb.dev),
  147. PXA3xx_CK("CAMCLK", CAMERA, &clk_pxa3xx_hsio_ops, NULL),
  148. PXA3xx_CKEN("UARTCLK", FFUART, 14857000, 1, &pxa_device_ffuart.dev),
  149. PXA3xx_CKEN("UARTCLK", BTUART, 14857000, 1, &pxa_device_btuart.dev),
  150. PXA3xx_CKEN("UARTCLK", STUART, 14857000, 1, NULL),
  151. PXA3xx_CKEN("I2CCLK", I2C, 32842000, 0, &pxa_device_i2c.dev),
  152. PXA3xx_CKEN("UDCCLK", UDC, 48000000, 5, &pxa_device_udc.dev),
  153. PXA3xx_CKEN("USBCLK", USBH, 48000000, 0, &pxa27x_device_ohci.dev),
  154. PXA3xx_CKEN("SSPCLK", SSP1, 13000000, 0, &pxa27x_device_ssp1.dev),
  155. PXA3xx_CKEN("SSPCLK", SSP2, 13000000, 0, &pxa27x_device_ssp2.dev),
  156. PXA3xx_CKEN("SSPCLK", SSP3, 13000000, 0, &pxa27x_device_ssp3.dev),
  157. PXA3xx_CKEN("SSPCLK", SSP4, 13000000, 0, &pxa3xx_device_ssp4.dev),
  158. PXA3xx_CKEN("MMCCLK", MMC1, 19500000, 0, &pxa_device_mci.dev),
  159. PXA3xx_CKEN("MMCCLK", MMC2, 19500000, 0, &pxa3xx_device_mci2.dev),
  160. PXA3xx_CKEN("MMCCLK", MMC3, 19500000, 0, &pxa3xx_device_mci3.dev),
  161. };
  162. #ifdef CONFIG_PM
  163. #define SLEEP_SAVE_SIZE 4
  164. #define ISRAM_START 0x5c000000
  165. #define ISRAM_SIZE SZ_256K
  166. static void __iomem *sram;
  167. static unsigned long wakeup_src;
  168. static void pxa3xx_cpu_pm_save(unsigned long *sleep_save)
  169. {
  170. pr_debug("PM: CKENA=%08x CKENB=%08x\n", CKENA, CKENB);
  171. if (CKENA & (1 << CKEN_USBH)) {
  172. printk(KERN_ERR "PM: USB host clock not stopped?\n");
  173. CKENA &= ~(1 << CKEN_USBH);
  174. }
  175. // CKENA |= 1 << (CKEN_ISC & 31);
  176. /*
  177. * Low power modes require the HSIO2 clock to be enabled.
  178. */
  179. CKENB |= 1 << (CKEN_HSIO2 & 31);
  180. }
  181. static void pxa3xx_cpu_pm_restore(unsigned long *sleep_save)
  182. {
  183. CKENB &= ~(1 << (CKEN_HSIO2 & 31));
  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. printk("PM: AD2D0SR=%08x ASCR=%08x\n", AD2D0SR, ASCR);
  211. }
  212. static void pxa3xx_cpu_pm_enter(suspend_state_t state)
  213. {
  214. /*
  215. * Don't sleep if no wakeup sources are defined
  216. */
  217. if (wakeup_src == 0)
  218. return;
  219. switch (state) {
  220. case PM_SUSPEND_STANDBY:
  221. pxa3xx_cpu_standby(PXA3xx_PM_S0D2C2);
  222. break;
  223. case PM_SUSPEND_MEM:
  224. break;
  225. }
  226. }
  227. static int pxa3xx_cpu_pm_valid(suspend_state_t state)
  228. {
  229. return state == PM_SUSPEND_MEM || state == PM_SUSPEND_STANDBY;
  230. }
  231. static struct pxa_cpu_pm_fns pxa3xx_cpu_pm_fns = {
  232. .save_size = SLEEP_SAVE_SIZE,
  233. .save = pxa3xx_cpu_pm_save,
  234. .restore = pxa3xx_cpu_pm_restore,
  235. .valid = pxa3xx_cpu_pm_valid,
  236. .enter = pxa3xx_cpu_pm_enter,
  237. };
  238. static void __init pxa3xx_init_pm(void)
  239. {
  240. sram = ioremap(ISRAM_START, ISRAM_SIZE);
  241. if (!sram) {
  242. printk(KERN_ERR "Unable to map ISRAM: disabling standby/suspend\n");
  243. return;
  244. }
  245. /*
  246. * Since we copy wakeup code into the SRAM, we need to ensure
  247. * that it is preserved over the low power modes. Note: bit 8
  248. * is undocumented in the developer manual, but must be set.
  249. */
  250. AD1R |= ADXR_L2 | ADXR_R0;
  251. AD2R |= ADXR_L2 | ADXR_R0;
  252. AD3R |= ADXR_L2 | ADXR_R0;
  253. /*
  254. * Clear the resume enable registers.
  255. */
  256. AD1D0ER = 0;
  257. AD2D0ER = 0;
  258. AD2D1ER = 0;
  259. AD3ER = 0;
  260. pxa_cpu_pm_fns = &pxa3xx_cpu_pm_fns;
  261. }
  262. static int pxa3xx_set_wake(unsigned int irq, unsigned int on)
  263. {
  264. unsigned long flags, mask = 0;
  265. switch (irq) {
  266. case IRQ_SSP3:
  267. mask = ADXER_MFP_WSSP3;
  268. break;
  269. case IRQ_MSL:
  270. mask = ADXER_WMSL0;
  271. break;
  272. case IRQ_USBH2:
  273. case IRQ_USBH1:
  274. mask = ADXER_WUSBH;
  275. break;
  276. case IRQ_KEYPAD:
  277. mask = ADXER_WKP;
  278. break;
  279. case IRQ_AC97:
  280. mask = ADXER_MFP_WAC97;
  281. break;
  282. case IRQ_USIM:
  283. mask = ADXER_WUSIM0;
  284. break;
  285. case IRQ_SSP2:
  286. mask = ADXER_MFP_WSSP2;
  287. break;
  288. case IRQ_I2C:
  289. mask = ADXER_MFP_WI2C;
  290. break;
  291. case IRQ_STUART:
  292. mask = ADXER_MFP_WUART3;
  293. break;
  294. case IRQ_BTUART:
  295. mask = ADXER_MFP_WUART2;
  296. break;
  297. case IRQ_FFUART:
  298. mask = ADXER_MFP_WUART1;
  299. break;
  300. case IRQ_MMC:
  301. mask = ADXER_MFP_WMMC1;
  302. break;
  303. case IRQ_SSP:
  304. mask = ADXER_MFP_WSSP1;
  305. break;
  306. case IRQ_RTCAlrm:
  307. mask = ADXER_WRTC;
  308. break;
  309. case IRQ_SSP4:
  310. mask = ADXER_MFP_WSSP4;
  311. break;
  312. case IRQ_TSI:
  313. mask = ADXER_WTSI;
  314. break;
  315. case IRQ_USIM2:
  316. mask = ADXER_WUSIM1;
  317. break;
  318. case IRQ_MMC2:
  319. mask = ADXER_MFP_WMMC2;
  320. break;
  321. case IRQ_NAND:
  322. mask = ADXER_MFP_WFLASH;
  323. break;
  324. case IRQ_USB2:
  325. mask = ADXER_WUSB2;
  326. break;
  327. case IRQ_WAKEUP0:
  328. mask = ADXER_WEXTWAKE0;
  329. break;
  330. case IRQ_WAKEUP1:
  331. mask = ADXER_WEXTWAKE1;
  332. break;
  333. case IRQ_MMC3:
  334. mask = ADXER_MFP_GEN12;
  335. break;
  336. }
  337. local_irq_save(flags);
  338. if (on)
  339. wakeup_src |= mask;
  340. else
  341. wakeup_src &= ~mask;
  342. local_irq_restore(flags);
  343. return 0;
  344. }
  345. static void pxa3xx_init_irq_pm(void)
  346. {
  347. pxa_init_irq_set_wake(pxa3xx_set_wake);
  348. }
  349. #else
  350. static inline void pxa3xx_init_pm(void) {}
  351. static inline void pxa3xx_init_irq_pm(void) {}
  352. #endif
  353. void __init pxa3xx_init_irq(void)
  354. {
  355. /* enable CP6 access */
  356. u32 value;
  357. __asm__ __volatile__("mrc p15, 0, %0, c15, c1, 0\n": "=r"(value));
  358. value |= (1 << 6);
  359. __asm__ __volatile__("mcr p15, 0, %0, c15, c1, 0\n": :"r"(value));
  360. pxa_init_irq_low();
  361. pxa_init_irq_high();
  362. pxa_init_irq_gpio(128);
  363. pxa3xx_init_irq_pm();
  364. }
  365. /*
  366. * device registration specific to PXA3xx.
  367. */
  368. static struct platform_device *devices[] __initdata = {
  369. &pxa_device_udc,
  370. &pxa_device_ffuart,
  371. &pxa_device_btuart,
  372. &pxa_device_stuart,
  373. &pxa_device_i2s,
  374. &pxa_device_rtc,
  375. &pxa27x_device_ssp1,
  376. &pxa27x_device_ssp2,
  377. &pxa27x_device_ssp3,
  378. &pxa3xx_device_ssp4,
  379. };
  380. static int __init pxa3xx_init(void)
  381. {
  382. int ret = 0;
  383. if (cpu_is_pxa3xx()) {
  384. clks_register(pxa3xx_clks, ARRAY_SIZE(pxa3xx_clks));
  385. if ((ret = pxa_init_dma(32)))
  386. return ret;
  387. pxa3xx_init_pm();
  388. return platform_add_devices(devices, ARRAY_SIZE(devices));
  389. }
  390. return 0;
  391. }
  392. subsys_initcall(pxa3xx_init);