io.c 11 KB

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