pxa3xx.c 13 KB

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