pxa27x.c 11 KB

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