pxa3xx.c 12 KB

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