io.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  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/serial.h>
  28. #include <plat/omap-pm.h>
  29. #include <plat/omap_hwmod.h>
  30. #include <plat/multi.h>
  31. #include <plat/dma.h>
  32. #include "soc.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. #include "sdrc.h"
  43. /*
  44. * The machine specific code may provide the extra mapping besides the
  45. * default mapping provided here.
  46. */
  47. #if defined(CONFIG_SOC_OMAP2420) || defined(CONFIG_SOC_OMAP2430)
  48. static struct map_desc omap24xx_io_desc[] __initdata = {
  49. {
  50. .virtual = L3_24XX_VIRT,
  51. .pfn = __phys_to_pfn(L3_24XX_PHYS),
  52. .length = L3_24XX_SIZE,
  53. .type = MT_DEVICE
  54. },
  55. {
  56. .virtual = L4_24XX_VIRT,
  57. .pfn = __phys_to_pfn(L4_24XX_PHYS),
  58. .length = L4_24XX_SIZE,
  59. .type = MT_DEVICE
  60. },
  61. };
  62. #ifdef CONFIG_SOC_OMAP2420
  63. static struct map_desc omap242x_io_desc[] __initdata = {
  64. {
  65. .virtual = DSP_MEM_2420_VIRT,
  66. .pfn = __phys_to_pfn(DSP_MEM_2420_PHYS),
  67. .length = DSP_MEM_2420_SIZE,
  68. .type = MT_DEVICE
  69. },
  70. {
  71. .virtual = DSP_IPI_2420_VIRT,
  72. .pfn = __phys_to_pfn(DSP_IPI_2420_PHYS),
  73. .length = DSP_IPI_2420_SIZE,
  74. .type = MT_DEVICE
  75. },
  76. {
  77. .virtual = DSP_MMU_2420_VIRT,
  78. .pfn = __phys_to_pfn(DSP_MMU_2420_PHYS),
  79. .length = DSP_MMU_2420_SIZE,
  80. .type = MT_DEVICE
  81. },
  82. };
  83. #endif
  84. #ifdef CONFIG_SOC_OMAP2430
  85. static struct map_desc omap243x_io_desc[] __initdata = {
  86. {
  87. .virtual = L4_WK_243X_VIRT,
  88. .pfn = __phys_to_pfn(L4_WK_243X_PHYS),
  89. .length = L4_WK_243X_SIZE,
  90. .type = MT_DEVICE
  91. },
  92. {
  93. .virtual = OMAP243X_GPMC_VIRT,
  94. .pfn = __phys_to_pfn(OMAP243X_GPMC_PHYS),
  95. .length = OMAP243X_GPMC_SIZE,
  96. .type = MT_DEVICE
  97. },
  98. {
  99. .virtual = OMAP243X_SDRC_VIRT,
  100. .pfn = __phys_to_pfn(OMAP243X_SDRC_PHYS),
  101. .length = OMAP243X_SDRC_SIZE,
  102. .type = MT_DEVICE
  103. },
  104. {
  105. .virtual = OMAP243X_SMS_VIRT,
  106. .pfn = __phys_to_pfn(OMAP243X_SMS_PHYS),
  107. .length = OMAP243X_SMS_SIZE,
  108. .type = MT_DEVICE
  109. },
  110. };
  111. #endif
  112. #endif
  113. #ifdef CONFIG_ARCH_OMAP3
  114. static struct map_desc omap34xx_io_desc[] __initdata = {
  115. {
  116. .virtual = L3_34XX_VIRT,
  117. .pfn = __phys_to_pfn(L3_34XX_PHYS),
  118. .length = L3_34XX_SIZE,
  119. .type = MT_DEVICE
  120. },
  121. {
  122. .virtual = L4_34XX_VIRT,
  123. .pfn = __phys_to_pfn(L4_34XX_PHYS),
  124. .length = L4_34XX_SIZE,
  125. .type = MT_DEVICE
  126. },
  127. {
  128. .virtual = OMAP34XX_GPMC_VIRT,
  129. .pfn = __phys_to_pfn(OMAP34XX_GPMC_PHYS),
  130. .length = OMAP34XX_GPMC_SIZE,
  131. .type = MT_DEVICE
  132. },
  133. {
  134. .virtual = OMAP343X_SMS_VIRT,
  135. .pfn = __phys_to_pfn(OMAP343X_SMS_PHYS),
  136. .length = OMAP343X_SMS_SIZE,
  137. .type = MT_DEVICE
  138. },
  139. {
  140. .virtual = OMAP343X_SDRC_VIRT,
  141. .pfn = __phys_to_pfn(OMAP343X_SDRC_PHYS),
  142. .length = OMAP343X_SDRC_SIZE,
  143. .type = MT_DEVICE
  144. },
  145. {
  146. .virtual = L4_PER_34XX_VIRT,
  147. .pfn = __phys_to_pfn(L4_PER_34XX_PHYS),
  148. .length = L4_PER_34XX_SIZE,
  149. .type = MT_DEVICE
  150. },
  151. {
  152. .virtual = L4_EMU_34XX_VIRT,
  153. .pfn = __phys_to_pfn(L4_EMU_34XX_PHYS),
  154. .length = L4_EMU_34XX_SIZE,
  155. .type = MT_DEVICE
  156. },
  157. #if defined(CONFIG_DEBUG_LL) && \
  158. (defined(CONFIG_MACH_OMAP_ZOOM2) || defined(CONFIG_MACH_OMAP_ZOOM3))
  159. {
  160. .virtual = ZOOM_UART_VIRT,
  161. .pfn = __phys_to_pfn(ZOOM_UART_BASE),
  162. .length = SZ_1M,
  163. .type = MT_DEVICE
  164. },
  165. #endif
  166. };
  167. #endif
  168. #ifdef CONFIG_SOC_TI81XX
  169. static struct map_desc omapti81xx_io_desc[] __initdata = {
  170. {
  171. .virtual = L4_34XX_VIRT,
  172. .pfn = __phys_to_pfn(L4_34XX_PHYS),
  173. .length = L4_34XX_SIZE,
  174. .type = MT_DEVICE
  175. }
  176. };
  177. #endif
  178. #ifdef CONFIG_SOC_AM33XX
  179. static struct map_desc omapam33xx_io_desc[] __initdata = {
  180. {
  181. .virtual = L4_34XX_VIRT,
  182. .pfn = __phys_to_pfn(L4_34XX_PHYS),
  183. .length = L4_34XX_SIZE,
  184. .type = MT_DEVICE
  185. },
  186. {
  187. .virtual = L4_WK_AM33XX_VIRT,
  188. .pfn = __phys_to_pfn(L4_WK_AM33XX_PHYS),
  189. .length = L4_WK_AM33XX_SIZE,
  190. .type = MT_DEVICE
  191. }
  192. };
  193. #endif
  194. #ifdef CONFIG_ARCH_OMAP4
  195. static struct map_desc omap44xx_io_desc[] __initdata = {
  196. {
  197. .virtual = L3_44XX_VIRT,
  198. .pfn = __phys_to_pfn(L3_44XX_PHYS),
  199. .length = L3_44XX_SIZE,
  200. .type = MT_DEVICE,
  201. },
  202. {
  203. .virtual = L4_44XX_VIRT,
  204. .pfn = __phys_to_pfn(L4_44XX_PHYS),
  205. .length = L4_44XX_SIZE,
  206. .type = MT_DEVICE,
  207. },
  208. {
  209. .virtual = L4_PER_44XX_VIRT,
  210. .pfn = __phys_to_pfn(L4_PER_44XX_PHYS),
  211. .length = L4_PER_44XX_SIZE,
  212. .type = MT_DEVICE,
  213. },
  214. #ifdef CONFIG_OMAP4_ERRATA_I688
  215. {
  216. .virtual = OMAP4_SRAM_VA,
  217. .pfn = __phys_to_pfn(OMAP4_SRAM_PA),
  218. .length = PAGE_SIZE,
  219. .type = MT_MEMORY_SO,
  220. },
  221. #endif
  222. };
  223. #endif
  224. #ifdef CONFIG_SOC_OMAP5
  225. static struct map_desc omap54xx_io_desc[] __initdata = {
  226. {
  227. .virtual = L3_54XX_VIRT,
  228. .pfn = __phys_to_pfn(L3_54XX_PHYS),
  229. .length = L3_54XX_SIZE,
  230. .type = MT_DEVICE,
  231. },
  232. {
  233. .virtual = L4_54XX_VIRT,
  234. .pfn = __phys_to_pfn(L4_54XX_PHYS),
  235. .length = L4_54XX_SIZE,
  236. .type = MT_DEVICE,
  237. },
  238. {
  239. .virtual = L4_WK_54XX_VIRT,
  240. .pfn = __phys_to_pfn(L4_WK_54XX_PHYS),
  241. .length = L4_WK_54XX_SIZE,
  242. .type = MT_DEVICE,
  243. },
  244. {
  245. .virtual = L4_PER_54XX_VIRT,
  246. .pfn = __phys_to_pfn(L4_PER_54XX_PHYS),
  247. .length = L4_PER_54XX_SIZE,
  248. .type = MT_DEVICE,
  249. },
  250. };
  251. #endif
  252. #ifdef CONFIG_SOC_OMAP2420
  253. void __init omap242x_map_common_io(void)
  254. {
  255. iotable_init(omap24xx_io_desc, ARRAY_SIZE(omap24xx_io_desc));
  256. iotable_init(omap242x_io_desc, ARRAY_SIZE(omap242x_io_desc));
  257. }
  258. #endif
  259. #ifdef CONFIG_SOC_OMAP2430
  260. void __init omap243x_map_common_io(void)
  261. {
  262. iotable_init(omap24xx_io_desc, ARRAY_SIZE(omap24xx_io_desc));
  263. iotable_init(omap243x_io_desc, ARRAY_SIZE(omap243x_io_desc));
  264. }
  265. #endif
  266. #ifdef CONFIG_ARCH_OMAP3
  267. void __init omap34xx_map_common_io(void)
  268. {
  269. iotable_init(omap34xx_io_desc, ARRAY_SIZE(omap34xx_io_desc));
  270. }
  271. #endif
  272. #ifdef CONFIG_SOC_TI81XX
  273. void __init omapti81xx_map_common_io(void)
  274. {
  275. iotable_init(omapti81xx_io_desc, ARRAY_SIZE(omapti81xx_io_desc));
  276. }
  277. #endif
  278. #ifdef CONFIG_SOC_AM33XX
  279. void __init omapam33xx_map_common_io(void)
  280. {
  281. iotable_init(omapam33xx_io_desc, ARRAY_SIZE(omapam33xx_io_desc));
  282. }
  283. #endif
  284. #ifdef CONFIG_ARCH_OMAP4
  285. void __init omap44xx_map_common_io(void)
  286. {
  287. iotable_init(omap44xx_io_desc, ARRAY_SIZE(omap44xx_io_desc));
  288. omap_barriers_init();
  289. }
  290. #endif
  291. #ifdef CONFIG_SOC_OMAP5
  292. void __init omap5_map_common_io(void)
  293. {
  294. iotable_init(omap54xx_io_desc, ARRAY_SIZE(omap54xx_io_desc));
  295. }
  296. #endif
  297. /*
  298. * omap2_init_reprogram_sdrc - reprogram SDRC timing parameters
  299. *
  300. * Sets the CORE DPLL3 M2 divider to the same value that it's at
  301. * currently. This has the effect of setting the SDRC SDRAM AC timing
  302. * registers to the values currently defined by the kernel. Currently
  303. * only defined for OMAP3; will return 0 if called on OMAP2. Returns
  304. * -EINVAL if the dpll3_m2_ck cannot be found, 0 if called on OMAP2,
  305. * or passes along the return value of clk_set_rate().
  306. */
  307. static int __init _omap2_init_reprogram_sdrc(void)
  308. {
  309. struct clk *dpll3_m2_ck;
  310. int v = -EINVAL;
  311. long rate;
  312. if (!cpu_is_omap34xx())
  313. return 0;
  314. dpll3_m2_ck = clk_get(NULL, "dpll3_m2_ck");
  315. if (IS_ERR(dpll3_m2_ck))
  316. return -EINVAL;
  317. rate = clk_get_rate(dpll3_m2_ck);
  318. pr_info("Reprogramming SDRC clock to %ld Hz\n", rate);
  319. v = clk_set_rate(dpll3_m2_ck, rate);
  320. if (v)
  321. pr_err("dpll3_m2_clk rate change failed: %d\n", v);
  322. clk_put(dpll3_m2_ck);
  323. return v;
  324. }
  325. static int _set_hwmod_postsetup_state(struct omap_hwmod *oh, void *data)
  326. {
  327. return omap_hwmod_set_postsetup_state(oh, *(u8 *)data);
  328. }
  329. static void __init omap_common_init_early(void)
  330. {
  331. omap_init_consistent_dma_size();
  332. }
  333. static void __init omap_hwmod_init_postsetup(void)
  334. {
  335. u8 postsetup_state;
  336. /* Set the default postsetup state for all hwmods */
  337. #ifdef CONFIG_PM_RUNTIME
  338. postsetup_state = _HWMOD_STATE_IDLE;
  339. #else
  340. postsetup_state = _HWMOD_STATE_ENABLED;
  341. #endif
  342. omap_hwmod_for_each(_set_hwmod_postsetup_state, &postsetup_state);
  343. omap_pm_if_early_init();
  344. }
  345. #ifdef CONFIG_SOC_OMAP2420
  346. void __init omap2420_init_early(void)
  347. {
  348. omap2_set_globals_242x();
  349. omap2xxx_check_revision();
  350. omap_common_init_early();
  351. omap2xxx_voltagedomains_init();
  352. omap242x_powerdomains_init();
  353. omap242x_clockdomains_init();
  354. omap2420_hwmod_init();
  355. omap_hwmod_init_postsetup();
  356. omap2420_clk_init();
  357. }
  358. void __init omap2420_init_late(void)
  359. {
  360. omap_mux_late_init();
  361. omap2_common_pm_late_init();
  362. omap2_pm_init();
  363. }
  364. #endif
  365. #ifdef CONFIG_SOC_OMAP2430
  366. void __init omap2430_init_early(void)
  367. {
  368. omap2_set_globals_243x();
  369. omap2xxx_check_revision();
  370. omap_common_init_early();
  371. omap2xxx_voltagedomains_init();
  372. omap243x_powerdomains_init();
  373. omap243x_clockdomains_init();
  374. omap2430_hwmod_init();
  375. omap_hwmod_init_postsetup();
  376. omap2430_clk_init();
  377. }
  378. void __init omap2430_init_late(void)
  379. {
  380. omap_mux_late_init();
  381. omap2_common_pm_late_init();
  382. omap2_pm_init();
  383. }
  384. #endif
  385. /*
  386. * Currently only board-omap3beagle.c should call this because of the
  387. * same machine_id for 34xx and 36xx beagle.. Will get fixed with DT.
  388. */
  389. #ifdef CONFIG_ARCH_OMAP3
  390. void __init omap3_init_early(void)
  391. {
  392. omap2_set_globals_3xxx();
  393. omap3xxx_check_revision();
  394. omap3xxx_check_features();
  395. omap_common_init_early();
  396. omap3xxx_voltagedomains_init();
  397. omap3xxx_powerdomains_init();
  398. omap3xxx_clockdomains_init();
  399. omap3xxx_hwmod_init();
  400. omap_hwmod_init_postsetup();
  401. omap3xxx_clk_init();
  402. }
  403. void __init omap3430_init_early(void)
  404. {
  405. omap3_init_early();
  406. }
  407. void __init omap35xx_init_early(void)
  408. {
  409. omap3_init_early();
  410. }
  411. void __init omap3630_init_early(void)
  412. {
  413. omap3_init_early();
  414. }
  415. void __init am35xx_init_early(void)
  416. {
  417. omap3_init_early();
  418. }
  419. void __init ti81xx_init_early(void)
  420. {
  421. omap2_set_globals_ti81xx();
  422. omap3xxx_check_revision();
  423. ti81xx_check_features();
  424. omap_common_init_early();
  425. omap3xxx_voltagedomains_init();
  426. omap3xxx_powerdomains_init();
  427. omap3xxx_clockdomains_init();
  428. omap3xxx_hwmod_init();
  429. omap_hwmod_init_postsetup();
  430. omap3xxx_clk_init();
  431. }
  432. void __init omap3_init_late(void)
  433. {
  434. omap_mux_late_init();
  435. omap2_common_pm_late_init();
  436. omap3_pm_init();
  437. }
  438. void __init omap3430_init_late(void)
  439. {
  440. omap_mux_late_init();
  441. omap2_common_pm_late_init();
  442. omap3_pm_init();
  443. }
  444. void __init omap35xx_init_late(void)
  445. {
  446. omap_mux_late_init();
  447. omap2_common_pm_late_init();
  448. omap3_pm_init();
  449. }
  450. void __init omap3630_init_late(void)
  451. {
  452. omap_mux_late_init();
  453. omap2_common_pm_late_init();
  454. omap3_pm_init();
  455. }
  456. void __init am35xx_init_late(void)
  457. {
  458. omap_mux_late_init();
  459. omap2_common_pm_late_init();
  460. omap3_pm_init();
  461. }
  462. void __init ti81xx_init_late(void)
  463. {
  464. omap_mux_late_init();
  465. omap2_common_pm_late_init();
  466. omap3_pm_init();
  467. }
  468. #endif
  469. #ifdef CONFIG_SOC_AM33XX
  470. void __init am33xx_init_early(void)
  471. {
  472. omap2_set_globals_am33xx();
  473. omap3xxx_check_revision();
  474. ti81xx_check_features();
  475. omap_common_init_early();
  476. am33xx_voltagedomains_init();
  477. am33xx_powerdomains_init();
  478. am33xx_clockdomains_init();
  479. am33xx_hwmod_init();
  480. omap_hwmod_init_postsetup();
  481. am33xx_clk_init();
  482. }
  483. #endif
  484. #ifdef CONFIG_ARCH_OMAP4
  485. void __init omap4430_init_early(void)
  486. {
  487. omap2_set_globals_443x();
  488. omap4xxx_check_revision();
  489. omap4xxx_check_features();
  490. omap_common_init_early();
  491. omap44xx_voltagedomains_init();
  492. omap44xx_powerdomains_init();
  493. omap44xx_clockdomains_init();
  494. omap44xx_hwmod_init();
  495. omap_hwmod_init_postsetup();
  496. omap4xxx_clk_init();
  497. }
  498. void __init omap4430_init_late(void)
  499. {
  500. omap_mux_late_init();
  501. omap2_common_pm_late_init();
  502. omap4_pm_init();
  503. }
  504. #endif
  505. #ifdef CONFIG_SOC_OMAP5
  506. void __init omap5_init_early(void)
  507. {
  508. omap2_set_globals_5xxx();
  509. omap5xxx_check_revision();
  510. omap_common_init_early();
  511. }
  512. #endif
  513. void __init omap_sdrc_init(struct omap_sdrc_params *sdrc_cs0,
  514. struct omap_sdrc_params *sdrc_cs1)
  515. {
  516. omap_sram_init();
  517. if (cpu_is_omap24xx() || omap3_has_sdrc()) {
  518. omap2_sdrc_init(sdrc_cs0, sdrc_cs1);
  519. _omap2_init_reprogram_sdrc();
  520. }
  521. }