pxa3xx.c 13 KB

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