pxa27x.c 12 KB

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