pxa27x.c 12 KB

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