io.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  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 "common.h"
  34. #include <plat/omap-pm.h>
  35. #include "voltage.h"
  36. #include "powerdomain.h"
  37. #include "clockdomain.h"
  38. #include <plat/omap_hwmod.h>
  39. #include <plat/multi.h>
  40. /*
  41. * The machine specific code may provide the extra mapping besides the
  42. * default mapping provided here.
  43. */
  44. #ifdef CONFIG_ARCH_OMAP2
  45. static struct map_desc omap24xx_io_desc[] __initdata = {
  46. {
  47. .virtual = L3_24XX_VIRT,
  48. .pfn = __phys_to_pfn(L3_24XX_PHYS),
  49. .length = L3_24XX_SIZE,
  50. .type = MT_DEVICE
  51. },
  52. {
  53. .virtual = L4_24XX_VIRT,
  54. .pfn = __phys_to_pfn(L4_24XX_PHYS),
  55. .length = L4_24XX_SIZE,
  56. .type = MT_DEVICE
  57. },
  58. };
  59. #ifdef CONFIG_SOC_OMAP2420
  60. static struct map_desc omap242x_io_desc[] __initdata = {
  61. {
  62. .virtual = DSP_MEM_2420_VIRT,
  63. .pfn = __phys_to_pfn(DSP_MEM_2420_PHYS),
  64. .length = DSP_MEM_2420_SIZE,
  65. .type = MT_DEVICE
  66. },
  67. {
  68. .virtual = DSP_IPI_2420_VIRT,
  69. .pfn = __phys_to_pfn(DSP_IPI_2420_PHYS),
  70. .length = DSP_IPI_2420_SIZE,
  71. .type = MT_DEVICE
  72. },
  73. {
  74. .virtual = DSP_MMU_2420_VIRT,
  75. .pfn = __phys_to_pfn(DSP_MMU_2420_PHYS),
  76. .length = DSP_MMU_2420_SIZE,
  77. .type = MT_DEVICE
  78. },
  79. };
  80. #endif
  81. #ifdef CONFIG_SOC_OMAP2430
  82. static struct map_desc omap243x_io_desc[] __initdata = {
  83. {
  84. .virtual = L4_WK_243X_VIRT,
  85. .pfn = __phys_to_pfn(L4_WK_243X_PHYS),
  86. .length = L4_WK_243X_SIZE,
  87. .type = MT_DEVICE
  88. },
  89. {
  90. .virtual = OMAP243X_GPMC_VIRT,
  91. .pfn = __phys_to_pfn(OMAP243X_GPMC_PHYS),
  92. .length = OMAP243X_GPMC_SIZE,
  93. .type = MT_DEVICE
  94. },
  95. {
  96. .virtual = OMAP243X_SDRC_VIRT,
  97. .pfn = __phys_to_pfn(OMAP243X_SDRC_PHYS),
  98. .length = OMAP243X_SDRC_SIZE,
  99. .type = MT_DEVICE
  100. },
  101. {
  102. .virtual = OMAP243X_SMS_VIRT,
  103. .pfn = __phys_to_pfn(OMAP243X_SMS_PHYS),
  104. .length = OMAP243X_SMS_SIZE,
  105. .type = MT_DEVICE
  106. },
  107. };
  108. #endif
  109. #endif
  110. #ifdef CONFIG_ARCH_OMAP3
  111. static struct map_desc omap34xx_io_desc[] __initdata = {
  112. {
  113. .virtual = L3_34XX_VIRT,
  114. .pfn = __phys_to_pfn(L3_34XX_PHYS),
  115. .length = L3_34XX_SIZE,
  116. .type = MT_DEVICE
  117. },
  118. {
  119. .virtual = L4_34XX_VIRT,
  120. .pfn = __phys_to_pfn(L4_34XX_PHYS),
  121. .length = L4_34XX_SIZE,
  122. .type = MT_DEVICE
  123. },
  124. {
  125. .virtual = OMAP34XX_GPMC_VIRT,
  126. .pfn = __phys_to_pfn(OMAP34XX_GPMC_PHYS),
  127. .length = OMAP34XX_GPMC_SIZE,
  128. .type = MT_DEVICE
  129. },
  130. {
  131. .virtual = OMAP343X_SMS_VIRT,
  132. .pfn = __phys_to_pfn(OMAP343X_SMS_PHYS),
  133. .length = OMAP343X_SMS_SIZE,
  134. .type = MT_DEVICE
  135. },
  136. {
  137. .virtual = OMAP343X_SDRC_VIRT,
  138. .pfn = __phys_to_pfn(OMAP343X_SDRC_PHYS),
  139. .length = OMAP343X_SDRC_SIZE,
  140. .type = MT_DEVICE
  141. },
  142. {
  143. .virtual = L4_PER_34XX_VIRT,
  144. .pfn = __phys_to_pfn(L4_PER_34XX_PHYS),
  145. .length = L4_PER_34XX_SIZE,
  146. .type = MT_DEVICE
  147. },
  148. {
  149. .virtual = L4_EMU_34XX_VIRT,
  150. .pfn = __phys_to_pfn(L4_EMU_34XX_PHYS),
  151. .length = L4_EMU_34XX_SIZE,
  152. .type = MT_DEVICE
  153. },
  154. #if defined(CONFIG_DEBUG_LL) && \
  155. (defined(CONFIG_MACH_OMAP_ZOOM2) || defined(CONFIG_MACH_OMAP_ZOOM3))
  156. {
  157. .virtual = ZOOM_UART_VIRT,
  158. .pfn = __phys_to_pfn(ZOOM_UART_BASE),
  159. .length = SZ_1M,
  160. .type = MT_DEVICE
  161. },
  162. #endif
  163. };
  164. #endif
  165. #ifdef CONFIG_SOC_OMAPTI81XX
  166. static struct map_desc omapti81xx_io_desc[] __initdata = {
  167. {
  168. .virtual = L4_34XX_VIRT,
  169. .pfn = __phys_to_pfn(L4_34XX_PHYS),
  170. .length = L4_34XX_SIZE,
  171. .type = MT_DEVICE
  172. }
  173. };
  174. #endif
  175. #ifdef CONFIG_SOC_OMAPAM33XX
  176. static struct map_desc omapam33xx_io_desc[] __initdata = {
  177. {
  178. .virtual = L4_34XX_VIRT,
  179. .pfn = __phys_to_pfn(L4_34XX_PHYS),
  180. .length = L4_34XX_SIZE,
  181. .type = MT_DEVICE
  182. },
  183. {
  184. .virtual = L4_WK_AM33XX_VIRT,
  185. .pfn = __phys_to_pfn(L4_WK_AM33XX_PHYS),
  186. .length = L4_WK_AM33XX_SIZE,
  187. .type = MT_DEVICE
  188. }
  189. };
  190. #endif
  191. #ifdef CONFIG_ARCH_OMAP4
  192. static struct map_desc omap44xx_io_desc[] __initdata = {
  193. {
  194. .virtual = L3_44XX_VIRT,
  195. .pfn = __phys_to_pfn(L3_44XX_PHYS),
  196. .length = L3_44XX_SIZE,
  197. .type = MT_DEVICE,
  198. },
  199. {
  200. .virtual = L4_44XX_VIRT,
  201. .pfn = __phys_to_pfn(L4_44XX_PHYS),
  202. .length = L4_44XX_SIZE,
  203. .type = MT_DEVICE,
  204. },
  205. {
  206. .virtual = OMAP44XX_GPMC_VIRT,
  207. .pfn = __phys_to_pfn(OMAP44XX_GPMC_PHYS),
  208. .length = OMAP44XX_GPMC_SIZE,
  209. .type = MT_DEVICE,
  210. },
  211. {
  212. .virtual = OMAP44XX_EMIF1_VIRT,
  213. .pfn = __phys_to_pfn(OMAP44XX_EMIF1_PHYS),
  214. .length = OMAP44XX_EMIF1_SIZE,
  215. .type = MT_DEVICE,
  216. },
  217. {
  218. .virtual = OMAP44XX_EMIF2_VIRT,
  219. .pfn = __phys_to_pfn(OMAP44XX_EMIF2_PHYS),
  220. .length = OMAP44XX_EMIF2_SIZE,
  221. .type = MT_DEVICE,
  222. },
  223. {
  224. .virtual = OMAP44XX_DMM_VIRT,
  225. .pfn = __phys_to_pfn(OMAP44XX_DMM_PHYS),
  226. .length = OMAP44XX_DMM_SIZE,
  227. .type = MT_DEVICE,
  228. },
  229. {
  230. .virtual = L4_PER_44XX_VIRT,
  231. .pfn = __phys_to_pfn(L4_PER_44XX_PHYS),
  232. .length = L4_PER_44XX_SIZE,
  233. .type = MT_DEVICE,
  234. },
  235. {
  236. .virtual = L4_EMU_44XX_VIRT,
  237. .pfn = __phys_to_pfn(L4_EMU_44XX_PHYS),
  238. .length = L4_EMU_44XX_SIZE,
  239. .type = MT_DEVICE,
  240. },
  241. #ifdef CONFIG_OMAP4_ERRATA_I688
  242. {
  243. .virtual = OMAP4_SRAM_VA,
  244. .pfn = __phys_to_pfn(OMAP4_SRAM_PA),
  245. .length = PAGE_SIZE,
  246. .type = MT_MEMORY_SO,
  247. },
  248. #endif
  249. };
  250. #endif
  251. #ifdef CONFIG_SOC_OMAP2420
  252. void __init omap242x_map_common_io(void)
  253. {
  254. iotable_init(omap24xx_io_desc, ARRAY_SIZE(omap24xx_io_desc));
  255. iotable_init(omap242x_io_desc, ARRAY_SIZE(omap242x_io_desc));
  256. }
  257. #endif
  258. #ifdef CONFIG_SOC_OMAP2430
  259. void __init omap243x_map_common_io(void)
  260. {
  261. iotable_init(omap24xx_io_desc, ARRAY_SIZE(omap24xx_io_desc));
  262. iotable_init(omap243x_io_desc, ARRAY_SIZE(omap243x_io_desc));
  263. }
  264. #endif
  265. #ifdef CONFIG_ARCH_OMAP3
  266. void __init omap34xx_map_common_io(void)
  267. {
  268. iotable_init(omap34xx_io_desc, ARRAY_SIZE(omap34xx_io_desc));
  269. }
  270. #endif
  271. #ifdef CONFIG_SOC_OMAPTI81XX
  272. void __init omapti81xx_map_common_io(void)
  273. {
  274. iotable_init(omapti81xx_io_desc, ARRAY_SIZE(omapti81xx_io_desc));
  275. }
  276. #endif
  277. #ifdef CONFIG_SOC_OMAPAM33XX
  278. void __init omapam33xx_map_common_io(void)
  279. {
  280. iotable_init(omapam33xx_io_desc, ARRAY_SIZE(omapam33xx_io_desc));
  281. }
  282. #endif
  283. #ifdef CONFIG_ARCH_OMAP4
  284. void __init omap44xx_map_common_io(void)
  285. {
  286. iotable_init(omap44xx_io_desc, ARRAY_SIZE(omap44xx_io_desc));
  287. }
  288. #endif
  289. /*
  290. * omap2_init_reprogram_sdrc - reprogram SDRC timing parameters
  291. *
  292. * Sets the CORE DPLL3 M2 divider to the same value that it's at
  293. * currently. This has the effect of setting the SDRC SDRAM AC timing
  294. * registers to the values currently defined by the kernel. Currently
  295. * only defined for OMAP3; will return 0 if called on OMAP2. Returns
  296. * -EINVAL if the dpll3_m2_ck cannot be found, 0 if called on OMAP2,
  297. * or passes along the return value of clk_set_rate().
  298. */
  299. static int __init _omap2_init_reprogram_sdrc(void)
  300. {
  301. struct clk *dpll3_m2_ck;
  302. int v = -EINVAL;
  303. long rate;
  304. if (!cpu_is_omap34xx())
  305. return 0;
  306. dpll3_m2_ck = clk_get(NULL, "dpll3_m2_ck");
  307. if (IS_ERR(dpll3_m2_ck))
  308. return -EINVAL;
  309. rate = clk_get_rate(dpll3_m2_ck);
  310. pr_info("Reprogramming SDRC clock to %ld Hz\n", rate);
  311. v = clk_set_rate(dpll3_m2_ck, rate);
  312. if (v)
  313. pr_err("dpll3_m2_clk rate change failed: %d\n", v);
  314. clk_put(dpll3_m2_ck);
  315. return v;
  316. }
  317. static int _set_hwmod_postsetup_state(struct omap_hwmod *oh, void *data)
  318. {
  319. return omap_hwmod_set_postsetup_state(oh, *(u8 *)data);
  320. }
  321. static void __init omap_common_init_early(void)
  322. {
  323. omap2_check_revision();
  324. omap_init_consistent_dma_size();
  325. }
  326. static void __init omap_hwmod_init_postsetup(void)
  327. {
  328. u8 postsetup_state;
  329. /* Set the default postsetup state for all hwmods */
  330. #ifdef CONFIG_PM_RUNTIME
  331. postsetup_state = _HWMOD_STATE_IDLE;
  332. #else
  333. postsetup_state = _HWMOD_STATE_ENABLED;
  334. #endif
  335. omap_hwmod_for_each(_set_hwmod_postsetup_state, &postsetup_state);
  336. /*
  337. * Set the default postsetup state for unusual modules (like
  338. * MPU WDT).
  339. *
  340. * The postsetup_state is not actually used until
  341. * omap_hwmod_late_init(), so boards that desire full watchdog
  342. * coverage of kernel initialization can reprogram the
  343. * postsetup_state between the calls to
  344. * omap2_init_common_infra() and omap_sdrc_init().
  345. *
  346. * XXX ideally we could detect whether the MPU WDT was currently
  347. * enabled here and make this conditional
  348. */
  349. postsetup_state = _HWMOD_STATE_DISABLED;
  350. omap_hwmod_for_each_by_class("wd_timer",
  351. _set_hwmod_postsetup_state,
  352. &postsetup_state);
  353. omap_pm_if_early_init();
  354. }
  355. #ifdef CONFIG_SOC_OMAP2420
  356. void __init omap2420_init_early(void)
  357. {
  358. omap2_set_globals_242x();
  359. omap_common_init_early();
  360. omap2xxx_voltagedomains_init();
  361. omap242x_powerdomains_init();
  362. omap242x_clockdomains_init();
  363. omap2420_hwmod_init();
  364. omap_hwmod_init_postsetup();
  365. omap2420_clk_init();
  366. }
  367. #endif
  368. #ifdef CONFIG_SOC_OMAP2430
  369. void __init omap2430_init_early(void)
  370. {
  371. omap2_set_globals_243x();
  372. omap_common_init_early();
  373. omap2xxx_voltagedomains_init();
  374. omap243x_powerdomains_init();
  375. omap243x_clockdomains_init();
  376. omap2430_hwmod_init();
  377. omap_hwmod_init_postsetup();
  378. omap2430_clk_init();
  379. }
  380. #endif
  381. /*
  382. * Currently only board-omap3beagle.c should call this because of the
  383. * same machine_id for 34xx and 36xx beagle.. Will get fixed with DT.
  384. */
  385. #ifdef CONFIG_ARCH_OMAP3
  386. void __init omap3_init_early(void)
  387. {
  388. omap2_set_globals_3xxx();
  389. omap_common_init_early();
  390. omap3xxx_voltagedomains_init();
  391. omap3xxx_powerdomains_init();
  392. omap3xxx_clockdomains_init();
  393. omap3xxx_hwmod_init();
  394. omap_hwmod_init_postsetup();
  395. omap3xxx_clk_init();
  396. }
  397. void __init omap3430_init_early(void)
  398. {
  399. omap3_init_early();
  400. }
  401. void __init omap35xx_init_early(void)
  402. {
  403. omap3_init_early();
  404. }
  405. void __init omap3630_init_early(void)
  406. {
  407. omap3_init_early();
  408. }
  409. void __init am35xx_init_early(void)
  410. {
  411. omap3_init_early();
  412. }
  413. void __init ti81xx_init_early(void)
  414. {
  415. omap2_set_globals_ti81xx();
  416. omap_common_init_early();
  417. omap3xxx_voltagedomains_init();
  418. omap3xxx_powerdomains_init();
  419. omap3xxx_clockdomains_init();
  420. omap3xxx_hwmod_init();
  421. omap_hwmod_init_postsetup();
  422. omap3xxx_clk_init();
  423. }
  424. #endif
  425. #ifdef CONFIG_ARCH_OMAP4
  426. void __init omap4430_init_early(void)
  427. {
  428. omap2_set_globals_443x();
  429. omap_common_init_early();
  430. omap44xx_voltagedomains_init();
  431. omap44xx_powerdomains_init();
  432. omap44xx_clockdomains_init();
  433. omap44xx_hwmod_init();
  434. omap_hwmod_init_postsetup();
  435. omap4xxx_clk_init();
  436. }
  437. #endif
  438. void __init omap_sdrc_init(struct omap_sdrc_params *sdrc_cs0,
  439. struct omap_sdrc_params *sdrc_cs1)
  440. {
  441. omap_sram_init();
  442. if (cpu_is_omap24xx() || omap3_has_sdrc()) {
  443. omap2_sdrc_init(sdrc_cs0, sdrc_cs1);
  444. _omap2_init_reprogram_sdrc();
  445. }
  446. }
  447. /*
  448. * NOTE: Please use ioremap + __raw_read/write where possible instead of these
  449. */
  450. u8 omap_readb(u32 pa)
  451. {
  452. return __raw_readb(OMAP2_L4_IO_ADDRESS(pa));
  453. }
  454. EXPORT_SYMBOL(omap_readb);
  455. u16 omap_readw(u32 pa)
  456. {
  457. return __raw_readw(OMAP2_L4_IO_ADDRESS(pa));
  458. }
  459. EXPORT_SYMBOL(omap_readw);
  460. u32 omap_readl(u32 pa)
  461. {
  462. return __raw_readl(OMAP2_L4_IO_ADDRESS(pa));
  463. }
  464. EXPORT_SYMBOL(omap_readl);
  465. void omap_writeb(u8 v, u32 pa)
  466. {
  467. __raw_writeb(v, OMAP2_L4_IO_ADDRESS(pa));
  468. }
  469. EXPORT_SYMBOL(omap_writeb);
  470. void omap_writew(u16 v, u32 pa)
  471. {
  472. __raw_writew(v, OMAP2_L4_IO_ADDRESS(pa));
  473. }
  474. EXPORT_SYMBOL(omap_writew);
  475. void omap_writel(u32 v, u32 pa)
  476. {
  477. __raw_writel(v, OMAP2_L4_IO_ADDRESS(pa));
  478. }
  479. EXPORT_SYMBOL(omap_writel);