pxa27x.c 11 KB

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