pxa3xx.c 12 KB

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