io.c 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  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/gpmc.h>
  30. #include <plat/serial.h>
  31. #include "clock2xxx.h"
  32. #include "clock3xxx.h"
  33. #include "clock44xx.h"
  34. #include "io.h"
  35. #include <plat/omap-pm.h>
  36. #include <plat/powerdomain.h>
  37. #include "powerdomains.h"
  38. #include <plat/clockdomain.h>
  39. #include "clockdomains.h"
  40. #include <plat/omap_hwmod.h>
  41. #include <plat/multi.h>
  42. /*
  43. * The machine specific code may provide the extra mapping besides the
  44. * default mapping provided here.
  45. */
  46. #ifdef CONFIG_ARCH_OMAP2
  47. static struct map_desc omap24xx_io_desc[] __initdata = {
  48. {
  49. .virtual = L3_24XX_VIRT,
  50. .pfn = __phys_to_pfn(L3_24XX_PHYS),
  51. .length = L3_24XX_SIZE,
  52. .type = MT_DEVICE
  53. },
  54. {
  55. .virtual = L4_24XX_VIRT,
  56. .pfn = __phys_to_pfn(L4_24XX_PHYS),
  57. .length = L4_24XX_SIZE,
  58. .type = MT_DEVICE
  59. },
  60. };
  61. #ifdef CONFIG_ARCH_OMAP2420
  62. static struct map_desc omap242x_io_desc[] __initdata = {
  63. {
  64. .virtual = DSP_MEM_2420_VIRT,
  65. .pfn = __phys_to_pfn(DSP_MEM_2420_PHYS),
  66. .length = DSP_MEM_2420_SIZE,
  67. .type = MT_DEVICE
  68. },
  69. {
  70. .virtual = DSP_IPI_2420_VIRT,
  71. .pfn = __phys_to_pfn(DSP_IPI_2420_PHYS),
  72. .length = DSP_IPI_2420_SIZE,
  73. .type = MT_DEVICE
  74. },
  75. {
  76. .virtual = DSP_MMU_2420_VIRT,
  77. .pfn = __phys_to_pfn(DSP_MMU_2420_PHYS),
  78. .length = DSP_MMU_2420_SIZE,
  79. .type = MT_DEVICE
  80. },
  81. };
  82. #endif
  83. #ifdef CONFIG_ARCH_OMAP2430
  84. static struct map_desc omap243x_io_desc[] __initdata = {
  85. {
  86. .virtual = L4_WK_243X_VIRT,
  87. .pfn = __phys_to_pfn(L4_WK_243X_PHYS),
  88. .length = L4_WK_243X_SIZE,
  89. .type = MT_DEVICE
  90. },
  91. {
  92. .virtual = OMAP243X_GPMC_VIRT,
  93. .pfn = __phys_to_pfn(OMAP243X_GPMC_PHYS),
  94. .length = OMAP243X_GPMC_SIZE,
  95. .type = MT_DEVICE
  96. },
  97. {
  98. .virtual = OMAP243X_SDRC_VIRT,
  99. .pfn = __phys_to_pfn(OMAP243X_SDRC_PHYS),
  100. .length = OMAP243X_SDRC_SIZE,
  101. .type = MT_DEVICE
  102. },
  103. {
  104. .virtual = OMAP243X_SMS_VIRT,
  105. .pfn = __phys_to_pfn(OMAP243X_SMS_PHYS),
  106. .length = OMAP243X_SMS_SIZE,
  107. .type = MT_DEVICE
  108. },
  109. };
  110. #endif
  111. #endif
  112. #ifdef CONFIG_ARCH_OMAP3
  113. static struct map_desc omap34xx_io_desc[] __initdata = {
  114. {
  115. .virtual = L3_34XX_VIRT,
  116. .pfn = __phys_to_pfn(L3_34XX_PHYS),
  117. .length = L3_34XX_SIZE,
  118. .type = MT_DEVICE
  119. },
  120. {
  121. .virtual = L4_34XX_VIRT,
  122. .pfn = __phys_to_pfn(L4_34XX_PHYS),
  123. .length = L4_34XX_SIZE,
  124. .type = MT_DEVICE
  125. },
  126. {
  127. .virtual = OMAP34XX_GPMC_VIRT,
  128. .pfn = __phys_to_pfn(OMAP34XX_GPMC_PHYS),
  129. .length = OMAP34XX_GPMC_SIZE,
  130. .type = MT_DEVICE
  131. },
  132. {
  133. .virtual = OMAP343X_SMS_VIRT,
  134. .pfn = __phys_to_pfn(OMAP343X_SMS_PHYS),
  135. .length = OMAP343X_SMS_SIZE,
  136. .type = MT_DEVICE
  137. },
  138. {
  139. .virtual = OMAP343X_SDRC_VIRT,
  140. .pfn = __phys_to_pfn(OMAP343X_SDRC_PHYS),
  141. .length = OMAP343X_SDRC_SIZE,
  142. .type = MT_DEVICE
  143. },
  144. {
  145. .virtual = L4_PER_34XX_VIRT,
  146. .pfn = __phys_to_pfn(L4_PER_34XX_PHYS),
  147. .length = L4_PER_34XX_SIZE,
  148. .type = MT_DEVICE
  149. },
  150. {
  151. .virtual = L4_EMU_34XX_VIRT,
  152. .pfn = __phys_to_pfn(L4_EMU_34XX_PHYS),
  153. .length = L4_EMU_34XX_SIZE,
  154. .type = MT_DEVICE
  155. },
  156. #if defined(CONFIG_DEBUG_LL) && \
  157. (defined(CONFIG_MACH_OMAP_ZOOM2) || defined(CONFIG_MACH_OMAP_ZOOM3))
  158. {
  159. .virtual = ZOOM_UART_VIRT,
  160. .pfn = __phys_to_pfn(ZOOM_UART_BASE),
  161. .length = SZ_1M,
  162. .type = MT_DEVICE
  163. },
  164. #endif
  165. };
  166. #endif
  167. #ifdef CONFIG_ARCH_OMAP4
  168. static struct map_desc omap44xx_io_desc[] __initdata = {
  169. {
  170. .virtual = L3_44XX_VIRT,
  171. .pfn = __phys_to_pfn(L3_44XX_PHYS),
  172. .length = L3_44XX_SIZE,
  173. .type = MT_DEVICE,
  174. },
  175. {
  176. .virtual = L4_44XX_VIRT,
  177. .pfn = __phys_to_pfn(L4_44XX_PHYS),
  178. .length = L4_44XX_SIZE,
  179. .type = MT_DEVICE,
  180. },
  181. {
  182. .virtual = OMAP44XX_GPMC_VIRT,
  183. .pfn = __phys_to_pfn(OMAP44XX_GPMC_PHYS),
  184. .length = OMAP44XX_GPMC_SIZE,
  185. .type = MT_DEVICE,
  186. },
  187. {
  188. .virtual = OMAP44XX_EMIF1_VIRT,
  189. .pfn = __phys_to_pfn(OMAP44XX_EMIF1_PHYS),
  190. .length = OMAP44XX_EMIF1_SIZE,
  191. .type = MT_DEVICE,
  192. },
  193. {
  194. .virtual = OMAP44XX_EMIF2_VIRT,
  195. .pfn = __phys_to_pfn(OMAP44XX_EMIF2_PHYS),
  196. .length = OMAP44XX_EMIF2_SIZE,
  197. .type = MT_DEVICE,
  198. },
  199. {
  200. .virtual = OMAP44XX_DMM_VIRT,
  201. .pfn = __phys_to_pfn(OMAP44XX_DMM_PHYS),
  202. .length = OMAP44XX_DMM_SIZE,
  203. .type = MT_DEVICE,
  204. },
  205. {
  206. .virtual = L4_PER_44XX_VIRT,
  207. .pfn = __phys_to_pfn(L4_PER_44XX_PHYS),
  208. .length = L4_PER_44XX_SIZE,
  209. .type = MT_DEVICE,
  210. },
  211. {
  212. .virtual = L4_EMU_44XX_VIRT,
  213. .pfn = __phys_to_pfn(L4_EMU_44XX_PHYS),
  214. .length = L4_EMU_44XX_SIZE,
  215. .type = MT_DEVICE,
  216. },
  217. };
  218. #endif
  219. static void __init _omap2_map_common_io(void)
  220. {
  221. /* Normally devicemaps_init() would flush caches and tlb after
  222. * mdesc->map_io(), but we must also do it here because of the CPU
  223. * revision check below.
  224. */
  225. local_flush_tlb_all();
  226. flush_cache_all();
  227. omap2_check_revision();
  228. omap_sram_init();
  229. }
  230. #ifdef CONFIG_ARCH_OMAP2420
  231. void __init omap242x_map_common_io(void)
  232. {
  233. iotable_init(omap24xx_io_desc, ARRAY_SIZE(omap24xx_io_desc));
  234. iotable_init(omap242x_io_desc, ARRAY_SIZE(omap242x_io_desc));
  235. _omap2_map_common_io();
  236. }
  237. #endif
  238. #ifdef CONFIG_ARCH_OMAP2430
  239. void __init omap243x_map_common_io(void)
  240. {
  241. iotable_init(omap24xx_io_desc, ARRAY_SIZE(omap24xx_io_desc));
  242. iotable_init(omap243x_io_desc, ARRAY_SIZE(omap243x_io_desc));
  243. _omap2_map_common_io();
  244. }
  245. #endif
  246. #ifdef CONFIG_ARCH_OMAP3
  247. void __init omap34xx_map_common_io(void)
  248. {
  249. iotable_init(omap34xx_io_desc, ARRAY_SIZE(omap34xx_io_desc));
  250. _omap2_map_common_io();
  251. }
  252. #endif
  253. #ifdef CONFIG_ARCH_OMAP4
  254. void __init omap44xx_map_common_io(void)
  255. {
  256. iotable_init(omap44xx_io_desc, ARRAY_SIZE(omap44xx_io_desc));
  257. _omap2_map_common_io();
  258. }
  259. #endif
  260. /*
  261. * omap2_init_reprogram_sdrc - reprogram SDRC timing parameters
  262. *
  263. * Sets the CORE DPLL3 M2 divider to the same value that it's at
  264. * currently. This has the effect of setting the SDRC SDRAM AC timing
  265. * registers to the values currently defined by the kernel. Currently
  266. * only defined for OMAP3; will return 0 if called on OMAP2. Returns
  267. * -EINVAL if the dpll3_m2_ck cannot be found, 0 if called on OMAP2,
  268. * or passes along the return value of clk_set_rate().
  269. */
  270. static int __init _omap2_init_reprogram_sdrc(void)
  271. {
  272. struct clk *dpll3_m2_ck;
  273. int v = -EINVAL;
  274. long rate;
  275. if (!cpu_is_omap34xx())
  276. return 0;
  277. dpll3_m2_ck = clk_get(NULL, "dpll3_m2_ck");
  278. if (IS_ERR(dpll3_m2_ck))
  279. return -EINVAL;
  280. rate = clk_get_rate(dpll3_m2_ck);
  281. pr_info("Reprogramming SDRC clock to %ld Hz\n", rate);
  282. v = clk_set_rate(dpll3_m2_ck, rate);
  283. if (v)
  284. pr_err("dpll3_m2_clk rate change failed: %d\n", v);
  285. clk_put(dpll3_m2_ck);
  286. return v;
  287. }
  288. static int _set_hwmod_postsetup_state(struct omap_hwmod *oh, void *data)
  289. {
  290. return omap_hwmod_set_postsetup_state(oh, *(u8 *)data);
  291. }
  292. /*
  293. * Initialize asm_irq_base for entry-macro.S
  294. */
  295. static inline void omap_irq_base_init(void)
  296. {
  297. extern void __iomem *omap_irq_base;
  298. #ifdef MULTI_OMAP2
  299. if (cpu_is_omap24xx())
  300. omap_irq_base = OMAP2_L4_IO_ADDRESS(OMAP24XX_IC_BASE);
  301. else if (cpu_is_omap34xx())
  302. omap_irq_base = OMAP2_L4_IO_ADDRESS(OMAP34XX_IC_BASE);
  303. else if (cpu_is_omap44xx())
  304. omap_irq_base = OMAP2_L4_IO_ADDRESS(OMAP44XX_GIC_CPU_BASE);
  305. else
  306. pr_err("Could not initialize omap_irq_base\n");
  307. #endif
  308. }
  309. void __init omap2_init_common_infrastructure(void)
  310. {
  311. u8 postsetup_state;
  312. pwrdm_init(powerdomains_omap);
  313. clkdm_init(clockdomains_omap, clkdm_autodeps);
  314. if (cpu_is_omap242x())
  315. omap2420_hwmod_init();
  316. else if (cpu_is_omap243x())
  317. omap2430_hwmod_init();
  318. else if (cpu_is_omap34xx())
  319. omap3xxx_hwmod_init();
  320. else if (cpu_is_omap44xx())
  321. omap44xx_hwmod_init();
  322. else
  323. pr_err("Could not init hwmod data - unknown SoC\n");
  324. /* Set the default postsetup state for all hwmods */
  325. #ifdef CONFIG_PM_RUNTIME
  326. postsetup_state = _HWMOD_STATE_IDLE;
  327. #else
  328. postsetup_state = _HWMOD_STATE_ENABLED;
  329. #endif
  330. omap_hwmod_for_each(_set_hwmod_postsetup_state, &postsetup_state);
  331. omap_pm_if_early_init();
  332. if (cpu_is_omap2420())
  333. omap2420_clk_init();
  334. else if (cpu_is_omap2430())
  335. omap2430_clk_init();
  336. else if (cpu_is_omap34xx())
  337. omap3xxx_clk_init();
  338. else if (cpu_is_omap44xx())
  339. omap4xxx_clk_init();
  340. else
  341. pr_err("Could not init clock framework - unknown SoC\n");
  342. }
  343. void __init omap2_init_common_devices(struct omap_sdrc_params *sdrc_cs0,
  344. struct omap_sdrc_params *sdrc_cs1)
  345. {
  346. omap_serial_early_init();
  347. omap_hwmod_late_init();
  348. if (cpu_is_omap24xx() || cpu_is_omap34xx()) {
  349. omap2_sdrc_init(sdrc_cs0, sdrc_cs1);
  350. _omap2_init_reprogram_sdrc();
  351. }
  352. gpmc_init();
  353. omap_irq_base_init();
  354. }
  355. /*
  356. * NOTE: Please use ioremap + __raw_read/write where possible instead of these
  357. */
  358. u8 omap_readb(u32 pa)
  359. {
  360. return __raw_readb(OMAP2_L4_IO_ADDRESS(pa));
  361. }
  362. EXPORT_SYMBOL(omap_readb);
  363. u16 omap_readw(u32 pa)
  364. {
  365. return __raw_readw(OMAP2_L4_IO_ADDRESS(pa));
  366. }
  367. EXPORT_SYMBOL(omap_readw);
  368. u32 omap_readl(u32 pa)
  369. {
  370. return __raw_readl(OMAP2_L4_IO_ADDRESS(pa));
  371. }
  372. EXPORT_SYMBOL(omap_readl);
  373. void omap_writeb(u8 v, u32 pa)
  374. {
  375. __raw_writeb(v, OMAP2_L4_IO_ADDRESS(pa));
  376. }
  377. EXPORT_SYMBOL(omap_writeb);
  378. void omap_writew(u16 v, u32 pa)
  379. {
  380. __raw_writew(v, OMAP2_L4_IO_ADDRESS(pa));
  381. }
  382. EXPORT_SYMBOL(omap_writew);
  383. void omap_writel(u32 v, u32 pa)
  384. {
  385. __raw_writel(v, OMAP2_L4_IO_ADDRESS(pa));
  386. }
  387. EXPORT_SYMBOL(omap_writel);