io.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  1. /*
  2. * linux/arch/arm/mach-omap2/io.c
  3. *
  4. * OMAP2 I/O mapping code
  5. *
  6. * Copyright (C) 2005 Nokia Corporation
  7. * Copyright (C) 2007-2009 Texas Instruments
  8. *
  9. * Author:
  10. * Juha Yrjola <juha.yrjola@nokia.com>
  11. * Syed Khasim <x0khasim@ti.com>
  12. *
  13. * Added OMAP4 support - Santosh Shilimkar <santosh.shilimkar@ti.com>
  14. *
  15. * This program is free software; you can redistribute it and/or modify
  16. * it under the terms of the GNU General Public License version 2 as
  17. * published by the Free Software Foundation.
  18. */
  19. #include <linux/module.h>
  20. #include <linux/kernel.h>
  21. #include <linux/init.h>
  22. #include <linux/io.h>
  23. #include <linux/clk.h>
  24. #include <linux/omapfb.h>
  25. #include <asm/tlb.h>
  26. #include <asm/mach/map.h>
  27. #include <plat/sram.h>
  28. #include <plat/sdrc.h>
  29. #include <plat/serial.h>
  30. #include "clock2xxx.h"
  31. #include "clock3xxx.h"
  32. #include "clock44xx.h"
  33. #include "io.h"
  34. #include <plat/omap-pm.h>
  35. #include "powerdomain.h"
  36. #include "clockdomain.h"
  37. #include <plat/omap_hwmod.h>
  38. #include <plat/multi.h>
  39. /*
  40. * The machine specific code may provide the extra mapping besides the
  41. * default mapping provided here.
  42. */
  43. #ifdef CONFIG_ARCH_OMAP2
  44. static struct map_desc omap24xx_io_desc[] __initdata = {
  45. {
  46. .virtual = L3_24XX_VIRT,
  47. .pfn = __phys_to_pfn(L3_24XX_PHYS),
  48. .length = L3_24XX_SIZE,
  49. .type = MT_DEVICE
  50. },
  51. {
  52. .virtual = L4_24XX_VIRT,
  53. .pfn = __phys_to_pfn(L4_24XX_PHYS),
  54. .length = L4_24XX_SIZE,
  55. .type = MT_DEVICE
  56. },
  57. };
  58. #ifdef CONFIG_SOC_OMAP2420
  59. static struct map_desc omap242x_io_desc[] __initdata = {
  60. {
  61. .virtual = DSP_MEM_2420_VIRT,
  62. .pfn = __phys_to_pfn(DSP_MEM_2420_PHYS),
  63. .length = DSP_MEM_2420_SIZE,
  64. .type = MT_DEVICE
  65. },
  66. {
  67. .virtual = DSP_IPI_2420_VIRT,
  68. .pfn = __phys_to_pfn(DSP_IPI_2420_PHYS),
  69. .length = DSP_IPI_2420_SIZE,
  70. .type = MT_DEVICE
  71. },
  72. {
  73. .virtual = DSP_MMU_2420_VIRT,
  74. .pfn = __phys_to_pfn(DSP_MMU_2420_PHYS),
  75. .length = DSP_MMU_2420_SIZE,
  76. .type = MT_DEVICE
  77. },
  78. };
  79. #endif
  80. #ifdef CONFIG_SOC_OMAP2430
  81. static struct map_desc omap243x_io_desc[] __initdata = {
  82. {
  83. .virtual = L4_WK_243X_VIRT,
  84. .pfn = __phys_to_pfn(L4_WK_243X_PHYS),
  85. .length = L4_WK_243X_SIZE,
  86. .type = MT_DEVICE
  87. },
  88. {
  89. .virtual = OMAP243X_GPMC_VIRT,
  90. .pfn = __phys_to_pfn(OMAP243X_GPMC_PHYS),
  91. .length = OMAP243X_GPMC_SIZE,
  92. .type = MT_DEVICE
  93. },
  94. {
  95. .virtual = OMAP243X_SDRC_VIRT,
  96. .pfn = __phys_to_pfn(OMAP243X_SDRC_PHYS),
  97. .length = OMAP243X_SDRC_SIZE,
  98. .type = MT_DEVICE
  99. },
  100. {
  101. .virtual = OMAP243X_SMS_VIRT,
  102. .pfn = __phys_to_pfn(OMAP243X_SMS_PHYS),
  103. .length = OMAP243X_SMS_SIZE,
  104. .type = MT_DEVICE
  105. },
  106. };
  107. #endif
  108. #endif
  109. #ifdef CONFIG_ARCH_OMAP3
  110. static struct map_desc omap34xx_io_desc[] __initdata = {
  111. {
  112. .virtual = L3_34XX_VIRT,
  113. .pfn = __phys_to_pfn(L3_34XX_PHYS),
  114. .length = L3_34XX_SIZE,
  115. .type = MT_DEVICE
  116. },
  117. {
  118. .virtual = L4_34XX_VIRT,
  119. .pfn = __phys_to_pfn(L4_34XX_PHYS),
  120. .length = L4_34XX_SIZE,
  121. .type = MT_DEVICE
  122. },
  123. {
  124. .virtual = OMAP34XX_GPMC_VIRT,
  125. .pfn = __phys_to_pfn(OMAP34XX_GPMC_PHYS),
  126. .length = OMAP34XX_GPMC_SIZE,
  127. .type = MT_DEVICE
  128. },
  129. {
  130. .virtual = OMAP343X_SMS_VIRT,
  131. .pfn = __phys_to_pfn(OMAP343X_SMS_PHYS),
  132. .length = OMAP343X_SMS_SIZE,
  133. .type = MT_DEVICE
  134. },
  135. {
  136. .virtual = OMAP343X_SDRC_VIRT,
  137. .pfn = __phys_to_pfn(OMAP343X_SDRC_PHYS),
  138. .length = OMAP343X_SDRC_SIZE,
  139. .type = MT_DEVICE
  140. },
  141. {
  142. .virtual = L4_PER_34XX_VIRT,
  143. .pfn = __phys_to_pfn(L4_PER_34XX_PHYS),
  144. .length = L4_PER_34XX_SIZE,
  145. .type = MT_DEVICE
  146. },
  147. {
  148. .virtual = L4_EMU_34XX_VIRT,
  149. .pfn = __phys_to_pfn(L4_EMU_34XX_PHYS),
  150. .length = L4_EMU_34XX_SIZE,
  151. .type = MT_DEVICE
  152. },
  153. #if defined(CONFIG_DEBUG_LL) && \
  154. (defined(CONFIG_MACH_OMAP_ZOOM2) || defined(CONFIG_MACH_OMAP_ZOOM3))
  155. {
  156. .virtual = ZOOM_UART_VIRT,
  157. .pfn = __phys_to_pfn(ZOOM_UART_BASE),
  158. .length = SZ_1M,
  159. .type = MT_DEVICE
  160. },
  161. #endif
  162. };
  163. #endif
  164. #ifdef CONFIG_SOC_OMAPTI816X
  165. static struct map_desc omapti816x_io_desc[] __initdata = {
  166. {
  167. .virtual = L4_34XX_VIRT,
  168. .pfn = __phys_to_pfn(L4_34XX_PHYS),
  169. .length = L4_34XX_SIZE,
  170. .type = MT_DEVICE
  171. },
  172. };
  173. #endif
  174. #ifdef CONFIG_ARCH_OMAP4
  175. static struct map_desc omap44xx_io_desc[] __initdata = {
  176. {
  177. .virtual = L3_44XX_VIRT,
  178. .pfn = __phys_to_pfn(L3_44XX_PHYS),
  179. .length = L3_44XX_SIZE,
  180. .type = MT_DEVICE,
  181. },
  182. {
  183. .virtual = L4_44XX_VIRT,
  184. .pfn = __phys_to_pfn(L4_44XX_PHYS),
  185. .length = L4_44XX_SIZE,
  186. .type = MT_DEVICE,
  187. },
  188. {
  189. .virtual = OMAP44XX_GPMC_VIRT,
  190. .pfn = __phys_to_pfn(OMAP44XX_GPMC_PHYS),
  191. .length = OMAP44XX_GPMC_SIZE,
  192. .type = MT_DEVICE,
  193. },
  194. {
  195. .virtual = OMAP44XX_EMIF1_VIRT,
  196. .pfn = __phys_to_pfn(OMAP44XX_EMIF1_PHYS),
  197. .length = OMAP44XX_EMIF1_SIZE,
  198. .type = MT_DEVICE,
  199. },
  200. {
  201. .virtual = OMAP44XX_EMIF2_VIRT,
  202. .pfn = __phys_to_pfn(OMAP44XX_EMIF2_PHYS),
  203. .length = OMAP44XX_EMIF2_SIZE,
  204. .type = MT_DEVICE,
  205. },
  206. {
  207. .virtual = OMAP44XX_DMM_VIRT,
  208. .pfn = __phys_to_pfn(OMAP44XX_DMM_PHYS),
  209. .length = OMAP44XX_DMM_SIZE,
  210. .type = MT_DEVICE,
  211. },
  212. {
  213. .virtual = L4_PER_44XX_VIRT,
  214. .pfn = __phys_to_pfn(L4_PER_44XX_PHYS),
  215. .length = L4_PER_44XX_SIZE,
  216. .type = MT_DEVICE,
  217. },
  218. {
  219. .virtual = L4_EMU_44XX_VIRT,
  220. .pfn = __phys_to_pfn(L4_EMU_44XX_PHYS),
  221. .length = L4_EMU_44XX_SIZE,
  222. .type = MT_DEVICE,
  223. },
  224. };
  225. #endif
  226. static void __init _omap2_map_common_io(void)
  227. {
  228. /* Normally devicemaps_init() would flush caches and tlb after
  229. * mdesc->map_io(), but we must also do it here because of the CPU
  230. * revision check below.
  231. */
  232. local_flush_tlb_all();
  233. flush_cache_all();
  234. omap2_check_revision();
  235. omap_sram_init();
  236. }
  237. #ifdef CONFIG_SOC_OMAP2420
  238. void __init omap242x_map_common_io(void)
  239. {
  240. iotable_init(omap24xx_io_desc, ARRAY_SIZE(omap24xx_io_desc));
  241. iotable_init(omap242x_io_desc, ARRAY_SIZE(omap242x_io_desc));
  242. _omap2_map_common_io();
  243. }
  244. #endif
  245. #ifdef CONFIG_SOC_OMAP2430
  246. void __init omap243x_map_common_io(void)
  247. {
  248. iotable_init(omap24xx_io_desc, ARRAY_SIZE(omap24xx_io_desc));
  249. iotable_init(omap243x_io_desc, ARRAY_SIZE(omap243x_io_desc));
  250. _omap2_map_common_io();
  251. }
  252. #endif
  253. #ifdef CONFIG_ARCH_OMAP3
  254. void __init omap34xx_map_common_io(void)
  255. {
  256. iotable_init(omap34xx_io_desc, ARRAY_SIZE(omap34xx_io_desc));
  257. _omap2_map_common_io();
  258. }
  259. #endif
  260. #ifdef CONFIG_SOC_OMAPTI816X
  261. void __init omapti816x_map_common_io(void)
  262. {
  263. iotable_init(omapti816x_io_desc, ARRAY_SIZE(omapti816x_io_desc));
  264. _omap2_map_common_io();
  265. }
  266. #endif
  267. #ifdef CONFIG_ARCH_OMAP4
  268. void __init omap44xx_map_common_io(void)
  269. {
  270. iotable_init(omap44xx_io_desc, ARRAY_SIZE(omap44xx_io_desc));
  271. _omap2_map_common_io();
  272. }
  273. #endif
  274. /*
  275. * omap2_init_reprogram_sdrc - reprogram SDRC timing parameters
  276. *
  277. * Sets the CORE DPLL3 M2 divider to the same value that it's at
  278. * currently. This has the effect of setting the SDRC SDRAM AC timing
  279. * registers to the values currently defined by the kernel. Currently
  280. * only defined for OMAP3; will return 0 if called on OMAP2. Returns
  281. * -EINVAL if the dpll3_m2_ck cannot be found, 0 if called on OMAP2,
  282. * or passes along the return value of clk_set_rate().
  283. */
  284. static int __init _omap2_init_reprogram_sdrc(void)
  285. {
  286. struct clk *dpll3_m2_ck;
  287. int v = -EINVAL;
  288. long rate;
  289. if (!cpu_is_omap34xx())
  290. return 0;
  291. dpll3_m2_ck = clk_get(NULL, "dpll3_m2_ck");
  292. if (IS_ERR(dpll3_m2_ck))
  293. return -EINVAL;
  294. rate = clk_get_rate(dpll3_m2_ck);
  295. pr_info("Reprogramming SDRC clock to %ld Hz\n", rate);
  296. v = clk_set_rate(dpll3_m2_ck, rate);
  297. if (v)
  298. pr_err("dpll3_m2_clk rate change failed: %d\n", v);
  299. clk_put(dpll3_m2_ck);
  300. return v;
  301. }
  302. static int _set_hwmod_postsetup_state(struct omap_hwmod *oh, void *data)
  303. {
  304. return omap_hwmod_set_postsetup_state(oh, *(u8 *)data);
  305. }
  306. /* See irq.c, omap4-common.c and entry-macro.S */
  307. void __iomem *omap_irq_base;
  308. void __init omap2_init_common_infrastructure(void)
  309. {
  310. u8 postsetup_state;
  311. if (cpu_is_omap242x()) {
  312. omap2xxx_powerdomains_init();
  313. omap2xxx_clockdomains_init();
  314. omap2420_hwmod_init();
  315. } else if (cpu_is_omap243x()) {
  316. omap2xxx_powerdomains_init();
  317. omap2xxx_clockdomains_init();
  318. omap2430_hwmod_init();
  319. } else if (cpu_is_omap34xx()) {
  320. omap3xxx_powerdomains_init();
  321. omap3xxx_clockdomains_init();
  322. omap3xxx_hwmod_init();
  323. } else if (cpu_is_omap44xx()) {
  324. omap44xx_powerdomains_init();
  325. omap44xx_clockdomains_init();
  326. omap44xx_hwmod_init();
  327. } else {
  328. pr_err("Could not init hwmod data - unknown SoC\n");
  329. }
  330. /* Set the default postsetup state for all hwmods */
  331. #ifdef CONFIG_PM_RUNTIME
  332. postsetup_state = _HWMOD_STATE_IDLE;
  333. #else
  334. postsetup_state = _HWMOD_STATE_ENABLED;
  335. #endif
  336. omap_hwmod_for_each(_set_hwmod_postsetup_state, &postsetup_state);
  337. /*
  338. * Set the default postsetup state for unusual modules (like
  339. * MPU WDT).
  340. *
  341. * The postsetup_state is not actually used until
  342. * omap_hwmod_late_init(), so boards that desire full watchdog
  343. * coverage of kernel initialization can reprogram the
  344. * postsetup_state between the calls to
  345. * omap2_init_common_infra() and omap2_init_common_devices().
  346. *
  347. * XXX ideally we could detect whether the MPU WDT was currently
  348. * enabled here and make this conditional
  349. */
  350. postsetup_state = _HWMOD_STATE_DISABLED;
  351. omap_hwmod_for_each_by_class("wd_timer",
  352. _set_hwmod_postsetup_state,
  353. &postsetup_state);
  354. omap_pm_if_early_init();
  355. if (cpu_is_omap2420())
  356. omap2420_clk_init();
  357. else if (cpu_is_omap2430())
  358. omap2430_clk_init();
  359. else if (cpu_is_omap34xx())
  360. omap3xxx_clk_init();
  361. else if (cpu_is_omap44xx())
  362. omap4xxx_clk_init();
  363. else
  364. pr_err("Could not init clock framework - unknown SoC\n");
  365. }
  366. void __init omap2_init_common_devices(struct omap_sdrc_params *sdrc_cs0,
  367. struct omap_sdrc_params *sdrc_cs1)
  368. {
  369. if (cpu_is_omap24xx() || omap3_has_sdrc()) {
  370. omap2_sdrc_init(sdrc_cs0, sdrc_cs1);
  371. _omap2_init_reprogram_sdrc();
  372. }
  373. }
  374. /*
  375. * NOTE: Please use ioremap + __raw_read/write where possible instead of these
  376. */
  377. u8 omap_readb(u32 pa)
  378. {
  379. return __raw_readb(OMAP2_L4_IO_ADDRESS(pa));
  380. }
  381. EXPORT_SYMBOL(omap_readb);
  382. u16 omap_readw(u32 pa)
  383. {
  384. return __raw_readw(OMAP2_L4_IO_ADDRESS(pa));
  385. }
  386. EXPORT_SYMBOL(omap_readw);
  387. u32 omap_readl(u32 pa)
  388. {
  389. return __raw_readl(OMAP2_L4_IO_ADDRESS(pa));
  390. }
  391. EXPORT_SYMBOL(omap_readl);
  392. void omap_writeb(u8 v, u32 pa)
  393. {
  394. __raw_writeb(v, OMAP2_L4_IO_ADDRESS(pa));
  395. }
  396. EXPORT_SYMBOL(omap_writeb);
  397. void omap_writew(u16 v, u32 pa)
  398. {
  399. __raw_writew(v, OMAP2_L4_IO_ADDRESS(pa));
  400. }
  401. EXPORT_SYMBOL(omap_writew);
  402. void omap_writel(u32 v, u32 pa)
  403. {
  404. __raw_writel(v, OMAP2_L4_IO_ADDRESS(pa));
  405. }
  406. EXPORT_SYMBOL(omap_writel);