pxa27x.c 12 KB

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