pxa27x.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  1. /*
  2. * linux/arch/arm/mach-pxa/pxa27x.c
  3. *
  4. * Author: Nicolas Pitre
  5. * Created: Nov 05, 2002
  6. * Copyright: MontaVista Software Inc.
  7. *
  8. * Code specific to PXA27x aka Bulverde.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. */
  14. #include <linux/module.h>
  15. #include <linux/kernel.h>
  16. #include <linux/init.h>
  17. #include <linux/suspend.h>
  18. #include <linux/platform_device.h>
  19. #include <linux/syscore_ops.h>
  20. #include <linux/io.h>
  21. #include <linux/irq.h>
  22. #include <linux/i2c/pxa-i2c.h>
  23. #include <asm/mach/map.h>
  24. #include <mach/hardware.h>
  25. #include <asm/irq.h>
  26. #include <asm/suspend.h>
  27. #include <mach/irqs.h>
  28. #include <mach/gpio.h>
  29. #include <mach/pxa27x.h>
  30. #include <mach/reset.h>
  31. #include <mach/ohci.h>
  32. #include <mach/pm.h>
  33. #include <mach/dma.h>
  34. #include <mach/smemc.h>
  35. #include "generic.h"
  36. #include "devices.h"
  37. #include "clock.h"
  38. void pxa27x_clear_otgph(void)
  39. {
  40. if (cpu_is_pxa27x() && (PSSR & PSSR_OTGPH))
  41. PSSR |= PSSR_OTGPH;
  42. }
  43. EXPORT_SYMBOL(pxa27x_clear_otgph);
  44. static unsigned long ac97_reset_config[] = {
  45. GPIO113_GPIO,
  46. GPIO113_AC97_nRESET,
  47. GPIO95_GPIO,
  48. GPIO95_AC97_nRESET,
  49. };
  50. void pxa27x_assert_ac97reset(int reset_gpio, int on)
  51. {
  52. if (reset_gpio == 113)
  53. pxa2xx_mfp_config(on ? &ac97_reset_config[0] :
  54. &ac97_reset_config[1], 1);
  55. if (reset_gpio == 95)
  56. pxa2xx_mfp_config(on ? &ac97_reset_config[2] :
  57. &ac97_reset_config[3], 1);
  58. }
  59. EXPORT_SYMBOL_GPL(pxa27x_assert_ac97reset);
  60. /* Crystal clock: 13MHz */
  61. #define BASE_CLK 13000000
  62. /*
  63. * Get the clock frequency as reflected by CCSR and the turbo flag.
  64. * We assume these values have been applied via a fcs.
  65. * If info is not 0 we also display the current settings.
  66. */
  67. unsigned int pxa27x_get_clk_frequency_khz(int info)
  68. {
  69. unsigned long ccsr, clkcfg;
  70. unsigned int l, L, m, M, n2, N, S;
  71. int cccr_a, t, ht, b;
  72. ccsr = CCSR;
  73. cccr_a = CCCR & (1 << 25);
  74. /* Read clkcfg register: it has turbo, b, half-turbo (and f) */
  75. asm( "mrc\tp14, 0, %0, c6, c0, 0" : "=r" (clkcfg) );
  76. t = clkcfg & (1 << 0);
  77. ht = clkcfg & (1 << 2);
  78. b = clkcfg & (1 << 3);
  79. l = ccsr & 0x1f;
  80. n2 = (ccsr>>7) & 0xf;
  81. m = (l <= 10) ? 1 : (l <= 20) ? 2 : 4;
  82. L = l * BASE_CLK;
  83. N = (L * n2) / 2;
  84. M = (!cccr_a) ? (L/m) : ((b) ? L : (L/2));
  85. S = (b) ? L : (L/2);
  86. if (info) {
  87. printk( KERN_INFO "Run Mode clock: %d.%02dMHz (*%d)\n",
  88. L / 1000000, (L % 1000000) / 10000, l );
  89. printk( KERN_INFO "Turbo Mode clock: %d.%02dMHz (*%d.%d, %sactive)\n",
  90. N / 1000000, (N % 1000000)/10000, n2 / 2, (n2 % 2)*5,
  91. (t) ? "" : "in" );
  92. printk( KERN_INFO "Memory clock: %d.%02dMHz (/%d)\n",
  93. M / 1000000, (M % 1000000) / 10000, m );
  94. printk( KERN_INFO "System bus clock: %d.%02dMHz \n",
  95. S / 1000000, (S % 1000000) / 10000 );
  96. }
  97. return (t) ? (N/1000) : (L/1000);
  98. }
  99. /*
  100. * Return the current mem clock frequency as reflected by CCCR[A], B, and L
  101. */
  102. static unsigned long clk_pxa27x_mem_getrate(struct clk *clk)
  103. {
  104. unsigned long ccsr, clkcfg;
  105. unsigned int l, L, m, M;
  106. int cccr_a, b;
  107. ccsr = CCSR;
  108. cccr_a = CCCR & (1 << 25);
  109. /* Read clkcfg register: it has turbo, b, half-turbo (and f) */
  110. asm( "mrc\tp14, 0, %0, c6, c0, 0" : "=r" (clkcfg) );
  111. b = clkcfg & (1 << 3);
  112. l = ccsr & 0x1f;
  113. m = (l <= 10) ? 1 : (l <= 20) ? 2 : 4;
  114. L = l * BASE_CLK;
  115. M = (!cccr_a) ? (L/m) : ((b) ? L : (L/2));
  116. return M;
  117. }
  118. static const struct clkops clk_pxa27x_mem_ops = {
  119. .enable = clk_dummy_enable,
  120. .disable = clk_dummy_disable,
  121. .getrate = clk_pxa27x_mem_getrate,
  122. };
  123. /*
  124. * Return the current LCD clock frequency in units of 10kHz as
  125. */
  126. static unsigned int pxa27x_get_lcdclk_frequency_10khz(void)
  127. {
  128. unsigned long ccsr;
  129. unsigned int l, L, k, K;
  130. ccsr = CCSR;
  131. l = ccsr & 0x1f;
  132. k = (l <= 7) ? 1 : (l <= 16) ? 2 : 4;
  133. L = l * BASE_CLK;
  134. K = L / k;
  135. return (K / 10000);
  136. }
  137. static unsigned long clk_pxa27x_lcd_getrate(struct clk *clk)
  138. {
  139. return pxa27x_get_lcdclk_frequency_10khz() * 10000;
  140. }
  141. static const struct clkops clk_pxa27x_lcd_ops = {
  142. .enable = clk_pxa2xx_cken_enable,
  143. .disable = clk_pxa2xx_cken_disable,
  144. .getrate = clk_pxa27x_lcd_getrate,
  145. };
  146. static DEFINE_PXA2_CKEN(pxa27x_ffuart, FFUART, 14857000, 1);
  147. static DEFINE_PXA2_CKEN(pxa27x_btuart, BTUART, 14857000, 1);
  148. static DEFINE_PXA2_CKEN(pxa27x_stuart, STUART, 14857000, 1);
  149. static DEFINE_PXA2_CKEN(pxa27x_i2s, I2S, 14682000, 0);
  150. static DEFINE_PXA2_CKEN(pxa27x_i2c, I2C, 32842000, 0);
  151. static DEFINE_PXA2_CKEN(pxa27x_usb, USB, 48000000, 5);
  152. static DEFINE_PXA2_CKEN(pxa27x_mmc, MMC, 19500000, 0);
  153. static DEFINE_PXA2_CKEN(pxa27x_ficp, FICP, 48000000, 0);
  154. static DEFINE_PXA2_CKEN(pxa27x_usbhost, USBHOST, 48000000, 0);
  155. static DEFINE_PXA2_CKEN(pxa27x_pwri2c, PWRI2C, 13000000, 0);
  156. static DEFINE_PXA2_CKEN(pxa27x_keypad, KEYPAD, 32768, 0);
  157. static DEFINE_PXA2_CKEN(pxa27x_ssp1, SSP1, 13000000, 0);
  158. static DEFINE_PXA2_CKEN(pxa27x_ssp2, SSP2, 13000000, 0);
  159. static DEFINE_PXA2_CKEN(pxa27x_ssp3, SSP3, 13000000, 0);
  160. static DEFINE_PXA2_CKEN(pxa27x_pwm0, PWM0, 13000000, 0);
  161. static DEFINE_PXA2_CKEN(pxa27x_pwm1, PWM1, 13000000, 0);
  162. static DEFINE_PXA2_CKEN(pxa27x_ac97, AC97, 24576000, 0);
  163. static DEFINE_PXA2_CKEN(pxa27x_ac97conf, AC97CONF, 24576000, 0);
  164. static DEFINE_PXA2_CKEN(pxa27x_msl, MSL, 48000000, 0);
  165. static DEFINE_PXA2_CKEN(pxa27x_usim, USIM, 48000000, 0);
  166. static DEFINE_PXA2_CKEN(pxa27x_memstk, MEMSTK, 19500000, 0);
  167. static DEFINE_PXA2_CKEN(pxa27x_im, IM, 0, 0);
  168. static DEFINE_PXA2_CKEN(pxa27x_memc, MEMC, 0, 0);
  169. static DEFINE_CK(pxa27x_lcd, LCD, &clk_pxa27x_lcd_ops);
  170. static DEFINE_CK(pxa27x_camera, CAMERA, &clk_pxa27x_lcd_ops);
  171. static DEFINE_CLK(pxa27x_mem, &clk_pxa27x_mem_ops, 0, 0);
  172. static struct clk_lookup pxa27x_clkregs[] = {
  173. INIT_CLKREG(&clk_pxa27x_lcd, "pxa2xx-fb", NULL),
  174. INIT_CLKREG(&clk_pxa27x_camera, "pxa27x-camera.0", NULL),
  175. INIT_CLKREG(&clk_pxa27x_ffuart, "pxa2xx-uart.0", NULL),
  176. INIT_CLKREG(&clk_pxa27x_btuart, "pxa2xx-uart.1", NULL),
  177. INIT_CLKREG(&clk_pxa27x_stuart, "pxa2xx-uart.2", NULL),
  178. INIT_CLKREG(&clk_pxa27x_i2s, "pxa2xx-i2s", NULL),
  179. INIT_CLKREG(&clk_pxa27x_i2c, "pxa2xx-i2c.0", NULL),
  180. INIT_CLKREG(&clk_pxa27x_usb, "pxa27x-udc", NULL),
  181. INIT_CLKREG(&clk_pxa27x_mmc, "pxa2xx-mci.0", NULL),
  182. INIT_CLKREG(&clk_pxa27x_stuart, "pxa2xx-ir", "UARTCLK"),
  183. INIT_CLKREG(&clk_pxa27x_ficp, "pxa2xx-ir", "FICPCLK"),
  184. INIT_CLKREG(&clk_pxa27x_usbhost, "pxa27x-ohci", NULL),
  185. INIT_CLKREG(&clk_pxa27x_pwri2c, "pxa2xx-i2c.1", NULL),
  186. INIT_CLKREG(&clk_pxa27x_keypad, "pxa27x-keypad", NULL),
  187. INIT_CLKREG(&clk_pxa27x_ssp1, "pxa27x-ssp.0", NULL),
  188. INIT_CLKREG(&clk_pxa27x_ssp2, "pxa27x-ssp.1", NULL),
  189. INIT_CLKREG(&clk_pxa27x_ssp3, "pxa27x-ssp.2", NULL),
  190. INIT_CLKREG(&clk_pxa27x_pwm0, "pxa27x-pwm.0", NULL),
  191. INIT_CLKREG(&clk_pxa27x_pwm1, "pxa27x-pwm.1", NULL),
  192. INIT_CLKREG(&clk_pxa27x_ac97, NULL, "AC97CLK"),
  193. INIT_CLKREG(&clk_pxa27x_ac97conf, NULL, "AC97CONFCLK"),
  194. INIT_CLKREG(&clk_pxa27x_msl, NULL, "MSLCLK"),
  195. INIT_CLKREG(&clk_pxa27x_usim, NULL, "USIMCLK"),
  196. INIT_CLKREG(&clk_pxa27x_memstk, NULL, "MSTKCLK"),
  197. INIT_CLKREG(&clk_pxa27x_im, NULL, "IMCLK"),
  198. INIT_CLKREG(&clk_pxa27x_memc, NULL, "MEMCLK"),
  199. INIT_CLKREG(&clk_pxa27x_mem, "pxa2xx-pcmcia", NULL),
  200. };
  201. #ifdef CONFIG_PM
  202. #define SAVE(x) sleep_save[SLEEP_SAVE_##x] = x
  203. #define RESTORE(x) x = sleep_save[SLEEP_SAVE_##x]
  204. /*
  205. * allow platforms to override default PWRMODE setting used for PM_SUSPEND_MEM
  206. */
  207. static unsigned int pwrmode = PWRMODE_SLEEP;
  208. int __init pxa27x_set_pwrmode(unsigned int mode)
  209. {
  210. switch (mode) {
  211. case PWRMODE_SLEEP:
  212. case PWRMODE_DEEPSLEEP:
  213. pwrmode = mode;
  214. return 0;
  215. }
  216. return -EINVAL;
  217. }
  218. /*
  219. * List of global PXA peripheral registers to preserve.
  220. * More ones like CP and general purpose register values are preserved
  221. * with the stack pointer in sleep.S.
  222. */
  223. enum {
  224. SLEEP_SAVE_PSTR,
  225. SLEEP_SAVE_MDREFR,
  226. SLEEP_SAVE_PCFR,
  227. SLEEP_SAVE_COUNT
  228. };
  229. void pxa27x_cpu_pm_save(unsigned long *sleep_save)
  230. {
  231. sleep_save[SLEEP_SAVE_MDREFR] = __raw_readl(MDREFR);
  232. SAVE(PCFR);
  233. SAVE(PSTR);
  234. }
  235. void pxa27x_cpu_pm_restore(unsigned long *sleep_save)
  236. {
  237. __raw_writel(sleep_save[SLEEP_SAVE_MDREFR], MDREFR);
  238. RESTORE(PCFR);
  239. PSSR = PSSR_RDH | PSSR_PH;
  240. RESTORE(PSTR);
  241. }
  242. void pxa27x_cpu_pm_enter(suspend_state_t state)
  243. {
  244. extern void pxa_cpu_standby(void);
  245. #ifndef CONFIG_IWMMXT
  246. u64 acc0;
  247. asm volatile("mra %Q0, %R0, acc0" : "=r" (acc0));
  248. #endif
  249. /* ensure voltage-change sequencer not initiated, which hangs */
  250. PCFR &= ~PCFR_FVC;
  251. /* Clear edge-detect status register. */
  252. PEDR = 0xDF12FE1B;
  253. /* Clear reset status */
  254. RCSR = RCSR_HWR | RCSR_WDR | RCSR_SMR | RCSR_GPR;
  255. switch (state) {
  256. case PM_SUSPEND_STANDBY:
  257. pxa_cpu_standby();
  258. break;
  259. case PM_SUSPEND_MEM:
  260. cpu_suspend(pwrmode, pxa27x_finish_suspend);
  261. #ifndef CONFIG_IWMMXT
  262. asm volatile("mar acc0, %Q0, %R0" : "=r" (acc0));
  263. #endif
  264. break;
  265. }
  266. }
  267. static int pxa27x_cpu_pm_valid(suspend_state_t state)
  268. {
  269. return state == PM_SUSPEND_MEM || state == PM_SUSPEND_STANDBY;
  270. }
  271. static int pxa27x_cpu_pm_prepare(void)
  272. {
  273. /* set resume return address */
  274. PSPR = virt_to_phys(cpu_resume);
  275. return 0;
  276. }
  277. static void pxa27x_cpu_pm_finish(void)
  278. {
  279. /* ensure not to come back here if it wasn't intended */
  280. PSPR = 0;
  281. }
  282. static struct pxa_cpu_pm_fns pxa27x_cpu_pm_fns = {
  283. .save_count = SLEEP_SAVE_COUNT,
  284. .save = pxa27x_cpu_pm_save,
  285. .restore = pxa27x_cpu_pm_restore,
  286. .valid = pxa27x_cpu_pm_valid,
  287. .enter = pxa27x_cpu_pm_enter,
  288. .prepare = pxa27x_cpu_pm_prepare,
  289. .finish = pxa27x_cpu_pm_finish,
  290. };
  291. static void __init pxa27x_init_pm(void)
  292. {
  293. pxa_cpu_pm_fns = &pxa27x_cpu_pm_fns;
  294. }
  295. #else
  296. static inline void pxa27x_init_pm(void) {}
  297. #endif
  298. /* PXA27x: Various gpios can issue wakeup events. This logic only
  299. * handles the simple cases, not the WEMUX2 and WEMUX3 options
  300. */
  301. static int pxa27x_set_wake(struct irq_data *d, unsigned int on)
  302. {
  303. int gpio = irq_to_gpio(d->irq);
  304. uint32_t mask;
  305. if (gpio >= 0 && gpio < 128)
  306. return gpio_set_wake(gpio, on);
  307. if (d->irq == IRQ_KEYPAD)
  308. return keypad_set_wake(on);
  309. switch (d->irq) {
  310. case IRQ_RTCAlrm:
  311. mask = PWER_RTC;
  312. break;
  313. case IRQ_USB:
  314. mask = 1u << 26;
  315. break;
  316. default:
  317. return -EINVAL;
  318. }
  319. if (on)
  320. PWER |= mask;
  321. else
  322. PWER &=~mask;
  323. return 0;
  324. }
  325. void __init pxa27x_init_irq(void)
  326. {
  327. pxa_init_irq(34, pxa27x_set_wake);
  328. pxa_init_gpio(IRQ_GPIO_2_x, 2, 120, pxa27x_set_wake);
  329. }
  330. static struct map_desc pxa27x_io_desc[] __initdata = {
  331. { /* Mem Ctl */
  332. .virtual = SMEMC_VIRT,
  333. .pfn = __phys_to_pfn(PXA2XX_SMEMC_BASE),
  334. .length = 0x00200000,
  335. .type = MT_DEVICE
  336. }, { /* IMem ctl */
  337. .virtual = 0xfe000000,
  338. .pfn = __phys_to_pfn(0x58000000),
  339. .length = 0x00100000,
  340. .type = MT_DEVICE
  341. },
  342. };
  343. void __init pxa27x_map_io(void)
  344. {
  345. pxa_map_io();
  346. iotable_init(ARRAY_AND_SIZE(pxa27x_io_desc));
  347. pxa27x_get_clk_frequency_khz(1);
  348. }
  349. /*
  350. * device registration specific to PXA27x.
  351. */
  352. void __init pxa27x_set_i2c_power_info(struct i2c_pxa_platform_data *info)
  353. {
  354. local_irq_disable();
  355. PCFR |= PCFR_PI2CEN;
  356. local_irq_enable();
  357. pxa_register_device(&pxa27x_device_i2c_power, info);
  358. }
  359. static struct platform_device *devices[] __initdata = {
  360. &pxa27x_device_udc,
  361. &pxa_device_pmu,
  362. &pxa_device_i2s,
  363. &pxa_device_asoc_ssp1,
  364. &pxa_device_asoc_ssp2,
  365. &pxa_device_asoc_ssp3,
  366. &pxa_device_asoc_platform,
  367. &sa1100_device_rtc,
  368. &pxa_device_rtc,
  369. &pxa27x_device_ssp1,
  370. &pxa27x_device_ssp2,
  371. &pxa27x_device_ssp3,
  372. &pxa27x_device_pwm0,
  373. &pxa27x_device_pwm1,
  374. };
  375. static int __init pxa27x_init(void)
  376. {
  377. int ret = 0;
  378. if (cpu_is_pxa27x()) {
  379. reset_status = RCSR;
  380. clkdev_add_table(pxa27x_clkregs, ARRAY_SIZE(pxa27x_clkregs));
  381. if ((ret = pxa_init_dma(IRQ_DMA, 32)))
  382. return ret;
  383. pxa27x_init_pm();
  384. register_syscore_ops(&pxa_irq_syscore_ops);
  385. register_syscore_ops(&pxa2xx_mfp_syscore_ops);
  386. register_syscore_ops(&pxa_gpio_syscore_ops);
  387. register_syscore_ops(&pxa2xx_clock_syscore_ops);
  388. ret = platform_add_devices(devices, ARRAY_SIZE(devices));
  389. }
  390. return ret;
  391. }
  392. postcore_initcall(pxa27x_init);