io.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  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 <asm/tlb.h>
  25. #include <asm/mach/map.h>
  26. #include <plat/sram.h>
  27. #include <plat/sdrc.h>
  28. #include <plat/serial.h>
  29. #include <plat/omap-pm.h>
  30. #include <plat/omap_hwmod.h>
  31. #include <plat/multi.h>
  32. #include <plat/dma.h>
  33. #include "iomap.h"
  34. #include "voltage.h"
  35. #include "powerdomain.h"
  36. #include "clockdomain.h"
  37. #include "common.h"
  38. #include "clock.h"
  39. #include "clock2xxx.h"
  40. #include "clock3xxx.h"
  41. #include "clock44xx.h"
  42. /*
  43. * The machine specific code may provide the extra mapping besides the
  44. * default mapping provided here.
  45. */
  46. #if defined(CONFIG_SOC_OMAP2420) || defined(CONFIG_SOC_OMAP2430)
  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_SOC_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_SOC_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_SOC_TI81XX
  168. static struct map_desc omapti81xx_io_desc[] __initdata = {
  169. {
  170. .virtual = L4_34XX_VIRT,
  171. .pfn = __phys_to_pfn(L4_34XX_PHYS),
  172. .length = L4_34XX_SIZE,
  173. .type = MT_DEVICE
  174. }
  175. };
  176. #endif
  177. #ifdef CONFIG_SOC_AM33XX
  178. static struct map_desc omapam33xx_io_desc[] __initdata = {
  179. {
  180. .virtual = L4_34XX_VIRT,
  181. .pfn = __phys_to_pfn(L4_34XX_PHYS),
  182. .length = L4_34XX_SIZE,
  183. .type = MT_DEVICE
  184. },
  185. {
  186. .virtual = L4_WK_AM33XX_VIRT,
  187. .pfn = __phys_to_pfn(L4_WK_AM33XX_PHYS),
  188. .length = L4_WK_AM33XX_SIZE,
  189. .type = MT_DEVICE
  190. }
  191. };
  192. #endif
  193. #ifdef CONFIG_ARCH_OMAP4
  194. static struct map_desc omap44xx_io_desc[] __initdata = {
  195. {
  196. .virtual = L3_44XX_VIRT,
  197. .pfn = __phys_to_pfn(L3_44XX_PHYS),
  198. .length = L3_44XX_SIZE,
  199. .type = MT_DEVICE,
  200. },
  201. {
  202. .virtual = L4_44XX_VIRT,
  203. .pfn = __phys_to_pfn(L4_44XX_PHYS),
  204. .length = L4_44XX_SIZE,
  205. .type = MT_DEVICE,
  206. },
  207. {
  208. .virtual = L4_PER_44XX_VIRT,
  209. .pfn = __phys_to_pfn(L4_PER_44XX_PHYS),
  210. .length = L4_PER_44XX_SIZE,
  211. .type = MT_DEVICE,
  212. },
  213. #ifdef CONFIG_OMAP4_ERRATA_I688
  214. {
  215. .virtual = OMAP4_SRAM_VA,
  216. .pfn = __phys_to_pfn(OMAP4_SRAM_PA),
  217. .length = PAGE_SIZE,
  218. .type = MT_MEMORY_SO,
  219. },
  220. #endif
  221. };
  222. #endif
  223. #ifdef CONFIG_SOC_OMAP5
  224. static struct map_desc omap54xx_io_desc[] __initdata = {
  225. {
  226. .virtual = L3_54XX_VIRT,
  227. .pfn = __phys_to_pfn(L3_54XX_PHYS),
  228. .length = L3_54XX_SIZE,
  229. .type = MT_DEVICE,
  230. },
  231. {
  232. .virtual = L4_54XX_VIRT,
  233. .pfn = __phys_to_pfn(L4_54XX_PHYS),
  234. .length = L4_54XX_SIZE,
  235. .type = MT_DEVICE,
  236. },
  237. {
  238. .virtual = L4_WK_54XX_VIRT,
  239. .pfn = __phys_to_pfn(L4_WK_54XX_PHYS),
  240. .length = L4_WK_54XX_SIZE,
  241. .type = MT_DEVICE,
  242. },
  243. {
  244. .virtual = L4_PER_54XX_VIRT,
  245. .pfn = __phys_to_pfn(L4_PER_54XX_PHYS),
  246. .length = L4_PER_54XX_SIZE,
  247. .type = MT_DEVICE,
  248. },
  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_TI81XX
  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_AM33XX
  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. omap_barriers_init();
  288. }
  289. #endif
  290. #ifdef CONFIG_SOC_OMAP5
  291. void __init omap5_map_common_io(void)
  292. {
  293. iotable_init(omap54xx_io_desc, ARRAY_SIZE(omap54xx_io_desc));
  294. }
  295. #endif
  296. /*
  297. * omap2_init_reprogram_sdrc - reprogram SDRC timing parameters
  298. *
  299. * Sets the CORE DPLL3 M2 divider to the same value that it's at
  300. * currently. This has the effect of setting the SDRC SDRAM AC timing
  301. * registers to the values currently defined by the kernel. Currently
  302. * only defined for OMAP3; will return 0 if called on OMAP2. Returns
  303. * -EINVAL if the dpll3_m2_ck cannot be found, 0 if called on OMAP2,
  304. * or passes along the return value of clk_set_rate().
  305. */
  306. static int __init _omap2_init_reprogram_sdrc(void)
  307. {
  308. struct clk *dpll3_m2_ck;
  309. int v = -EINVAL;
  310. long rate;
  311. if (!cpu_is_omap34xx())
  312. return 0;
  313. dpll3_m2_ck = clk_get(NULL, "dpll3_m2_ck");
  314. if (IS_ERR(dpll3_m2_ck))
  315. return -EINVAL;
  316. rate = clk_get_rate(dpll3_m2_ck);
  317. pr_info("Reprogramming SDRC clock to %ld Hz\n", rate);
  318. v = clk_set_rate(dpll3_m2_ck, rate);
  319. if (v)
  320. pr_err("dpll3_m2_clk rate change failed: %d\n", v);
  321. clk_put(dpll3_m2_ck);
  322. return v;
  323. }
  324. static int _set_hwmod_postsetup_state(struct omap_hwmod *oh, void *data)
  325. {
  326. return omap_hwmod_set_postsetup_state(oh, *(u8 *)data);
  327. }
  328. static void __init omap_common_init_early(void)
  329. {
  330. omap_init_consistent_dma_size();
  331. }
  332. static void __init omap_hwmod_init_postsetup(void)
  333. {
  334. u8 postsetup_state;
  335. /* Set the default postsetup state for all hwmods */
  336. #ifdef CONFIG_PM_RUNTIME
  337. postsetup_state = _HWMOD_STATE_IDLE;
  338. #else
  339. postsetup_state = _HWMOD_STATE_ENABLED;
  340. #endif
  341. omap_hwmod_for_each(_set_hwmod_postsetup_state, &postsetup_state);
  342. omap_pm_if_early_init();
  343. }
  344. #ifdef CONFIG_SOC_OMAP2420
  345. void __init omap2420_init_early(void)
  346. {
  347. omap2_set_globals_242x();
  348. omap2xxx_check_revision();
  349. omap_common_init_early();
  350. omap2xxx_voltagedomains_init();
  351. omap242x_powerdomains_init();
  352. omap242x_clockdomains_init();
  353. omap2420_hwmod_init();
  354. omap_hwmod_init_postsetup();
  355. omap2420_clk_init();
  356. }
  357. void __init omap2420_init_late(void)
  358. {
  359. omap_mux_late_init();
  360. omap2_common_pm_late_init();
  361. omap2_pm_init();
  362. }
  363. #endif
  364. #ifdef CONFIG_SOC_OMAP2430
  365. void __init omap2430_init_early(void)
  366. {
  367. omap2_set_globals_243x();
  368. omap2xxx_check_revision();
  369. omap_common_init_early();
  370. omap2xxx_voltagedomains_init();
  371. omap243x_powerdomains_init();
  372. omap243x_clockdomains_init();
  373. omap2430_hwmod_init();
  374. omap_hwmod_init_postsetup();
  375. omap2430_clk_init();
  376. }
  377. void __init omap2430_init_late(void)
  378. {
  379. omap_mux_late_init();
  380. omap2_common_pm_late_init();
  381. omap2_pm_init();
  382. }
  383. #endif
  384. /*
  385. * Currently only board-omap3beagle.c should call this because of the
  386. * same machine_id for 34xx and 36xx beagle.. Will get fixed with DT.
  387. */
  388. #ifdef CONFIG_ARCH_OMAP3
  389. void __init omap3_init_early(void)
  390. {
  391. omap2_set_globals_3xxx();
  392. omap3xxx_check_revision();
  393. omap3xxx_check_features();
  394. omap_common_init_early();
  395. omap3xxx_voltagedomains_init();
  396. omap3xxx_powerdomains_init();
  397. omap3xxx_clockdomains_init();
  398. omap3xxx_hwmod_init();
  399. omap_hwmod_init_postsetup();
  400. omap3xxx_clk_init();
  401. }
  402. void __init omap3430_init_early(void)
  403. {
  404. omap3_init_early();
  405. }
  406. void __init omap35xx_init_early(void)
  407. {
  408. omap3_init_early();
  409. }
  410. void __init omap3630_init_early(void)
  411. {
  412. omap3_init_early();
  413. }
  414. void __init am35xx_init_early(void)
  415. {
  416. omap3_init_early();
  417. }
  418. void __init ti81xx_init_early(void)
  419. {
  420. omap2_set_globals_ti81xx();
  421. omap3xxx_check_revision();
  422. ti81xx_check_features();
  423. omap_common_init_early();
  424. omap3xxx_voltagedomains_init();
  425. omap3xxx_powerdomains_init();
  426. omap3xxx_clockdomains_init();
  427. omap3xxx_hwmod_init();
  428. omap_hwmod_init_postsetup();
  429. omap3xxx_clk_init();
  430. }
  431. void __init omap3_init_late(void)
  432. {
  433. omap_mux_late_init();
  434. omap2_common_pm_late_init();
  435. omap3_pm_init();
  436. }
  437. void __init omap3430_init_late(void)
  438. {
  439. omap_mux_late_init();
  440. omap2_common_pm_late_init();
  441. omap3_pm_init();
  442. }
  443. void __init omap35xx_init_late(void)
  444. {
  445. omap_mux_late_init();
  446. omap2_common_pm_late_init();
  447. omap3_pm_init();
  448. }
  449. void __init omap3630_init_late(void)
  450. {
  451. omap_mux_late_init();
  452. omap2_common_pm_late_init();
  453. omap3_pm_init();
  454. }
  455. void __init am35xx_init_late(void)
  456. {
  457. omap_mux_late_init();
  458. omap2_common_pm_late_init();
  459. omap3_pm_init();
  460. }
  461. void __init ti81xx_init_late(void)
  462. {
  463. omap_mux_late_init();
  464. omap2_common_pm_late_init();
  465. omap3_pm_init();
  466. }
  467. #endif
  468. #ifdef CONFIG_SOC_AM33XX
  469. void __init am33xx_init_early(void)
  470. {
  471. omap2_set_globals_am33xx();
  472. omap3xxx_check_revision();
  473. ti81xx_check_features();
  474. omap_common_init_early();
  475. am33xx_voltagedomains_init();
  476. am33xx_powerdomains_init();
  477. am33xx_clockdomains_init();
  478. am33xx_clk_init();
  479. }
  480. #endif
  481. #ifdef CONFIG_ARCH_OMAP4
  482. void __init omap4430_init_early(void)
  483. {
  484. omap2_set_globals_443x();
  485. omap4xxx_check_revision();
  486. omap4xxx_check_features();
  487. omap_common_init_early();
  488. omap44xx_voltagedomains_init();
  489. omap44xx_powerdomains_init();
  490. omap44xx_clockdomains_init();
  491. omap44xx_hwmod_init();
  492. omap_hwmod_init_postsetup();
  493. omap4xxx_clk_init();
  494. }
  495. void __init omap4430_init_late(void)
  496. {
  497. omap_mux_late_init();
  498. omap2_common_pm_late_init();
  499. omap4_pm_init();
  500. }
  501. #endif
  502. #ifdef CONFIG_SOC_OMAP5
  503. void __init omap5_init_early(void)
  504. {
  505. omap2_set_globals_5xxx();
  506. omap5xxx_check_revision();
  507. omap_common_init_early();
  508. }
  509. #endif
  510. void __init omap_sdrc_init(struct omap_sdrc_params *sdrc_cs0,
  511. struct omap_sdrc_params *sdrc_cs1)
  512. {
  513. omap_sram_init();
  514. if (cpu_is_omap24xx() || omap3_has_sdrc()) {
  515. omap2_sdrc_init(sdrc_cs0, sdrc_cs1);
  516. _omap2_init_reprogram_sdrc();
  517. }
  518. }