pxa3xx.c 10 KB

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