io.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. * Common io.c file
  3. * This file is created by Russell King <rmk+kernel@arm.linux.org.uk>
  4. *
  5. * Copyright (C) 2009 Texas Instruments
  6. * Added OMAP4 support - Santosh Shilimkar <santosh.shilimkar@ti.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/module.h>
  13. #include <linux/io.h>
  14. #include <linux/mm.h>
  15. #include <plat/omap7xx.h>
  16. #include <plat/omap1510.h>
  17. #include <plat/omap16xx.h>
  18. #include <plat/omap24xx.h>
  19. #include <plat/omap34xx.h>
  20. #include <plat/omap44xx.h>
  21. #define BETWEEN(p,st,sz) ((p) >= (st) && (p) < ((st) + (sz)))
  22. #define XLATE(p,pst,vst) ((void __iomem *)((p) - (pst) + (vst)))
  23. /*
  24. * Intercept ioremap() requests for addresses in our fixed mapping regions.
  25. */
  26. void __iomem *omap_ioremap(unsigned long p, size_t size, unsigned int type)
  27. {
  28. #ifdef CONFIG_ARCH_OMAP1
  29. if (cpu_class_is_omap1()) {
  30. if (BETWEEN(p, OMAP1_IO_PHYS, OMAP1_IO_SIZE))
  31. return XLATE(p, OMAP1_IO_PHYS, OMAP1_IO_VIRT);
  32. }
  33. if (cpu_is_omap7xx()) {
  34. if (BETWEEN(p, OMAP7XX_DSP_BASE, OMAP7XX_DSP_SIZE))
  35. return XLATE(p, OMAP7XX_DSP_BASE, OMAP7XX_DSP_START);
  36. if (BETWEEN(p, OMAP7XX_DSPREG_BASE, OMAP7XX_DSPREG_SIZE))
  37. return XLATE(p, OMAP7XX_DSPREG_BASE,
  38. OMAP7XX_DSPREG_START);
  39. }
  40. if (cpu_is_omap15xx()) {
  41. if (BETWEEN(p, OMAP1510_DSP_BASE, OMAP1510_DSP_SIZE))
  42. return XLATE(p, OMAP1510_DSP_BASE, OMAP1510_DSP_START);
  43. if (BETWEEN(p, OMAP1510_DSPREG_BASE, OMAP1510_DSPREG_SIZE))
  44. return XLATE(p, OMAP1510_DSPREG_BASE,
  45. OMAP1510_DSPREG_START);
  46. }
  47. if (cpu_is_omap16xx()) {
  48. if (BETWEEN(p, OMAP16XX_DSP_BASE, OMAP16XX_DSP_SIZE))
  49. return XLATE(p, OMAP16XX_DSP_BASE, OMAP16XX_DSP_START);
  50. if (BETWEEN(p, OMAP16XX_DSPREG_BASE, OMAP16XX_DSPREG_SIZE))
  51. return XLATE(p, OMAP16XX_DSPREG_BASE,
  52. OMAP16XX_DSPREG_START);
  53. }
  54. #endif
  55. #ifdef CONFIG_ARCH_OMAP2
  56. if (cpu_is_omap24xx()) {
  57. if (BETWEEN(p, L3_24XX_PHYS, L3_24XX_SIZE))
  58. return XLATE(p, L3_24XX_PHYS, L3_24XX_VIRT);
  59. if (BETWEEN(p, L4_24XX_PHYS, L4_24XX_SIZE))
  60. return XLATE(p, L4_24XX_PHYS, L4_24XX_VIRT);
  61. }
  62. if (cpu_is_omap2420()) {
  63. if (BETWEEN(p, DSP_MEM_2420_PHYS, DSP_MEM_2420_SIZE))
  64. return XLATE(p, DSP_MEM_2420_PHYS, DSP_MEM_2420_VIRT);
  65. if (BETWEEN(p, DSP_IPI_2420_PHYS, DSP_IPI_2420_SIZE))
  66. return XLATE(p, DSP_IPI_2420_PHYS, DSP_IPI_2420_SIZE);
  67. if (BETWEEN(p, DSP_MMU_2420_PHYS, DSP_MMU_2420_SIZE))
  68. return XLATE(p, DSP_MMU_2420_PHYS, DSP_MMU_2420_VIRT);
  69. }
  70. if (cpu_is_omap2430()) {
  71. if (BETWEEN(p, L4_WK_243X_PHYS, L4_WK_243X_SIZE))
  72. return XLATE(p, L4_WK_243X_PHYS, L4_WK_243X_VIRT);
  73. if (BETWEEN(p, OMAP243X_GPMC_PHYS, OMAP243X_GPMC_SIZE))
  74. return XLATE(p, OMAP243X_GPMC_PHYS, OMAP243X_GPMC_VIRT);
  75. if (BETWEEN(p, OMAP243X_SDRC_PHYS, OMAP243X_SDRC_SIZE))
  76. return XLATE(p, OMAP243X_SDRC_PHYS, OMAP243X_SDRC_VIRT);
  77. if (BETWEEN(p, OMAP243X_SMS_PHYS, OMAP243X_SMS_SIZE))
  78. return XLATE(p, OMAP243X_SMS_PHYS, OMAP243X_SMS_VIRT);
  79. }
  80. #endif
  81. #ifdef CONFIG_ARCH_OMAP3
  82. if (cpu_is_ti816x()) {
  83. if (BETWEEN(p, L4_34XX_PHYS, L4_34XX_SIZE))
  84. return XLATE(p, L4_34XX_PHYS, L4_34XX_VIRT);
  85. } else if (cpu_is_omap34xx()) {
  86. if (BETWEEN(p, L3_34XX_PHYS, L3_34XX_SIZE))
  87. return XLATE(p, L3_34XX_PHYS, L3_34XX_VIRT);
  88. if (BETWEEN(p, L4_34XX_PHYS, L4_34XX_SIZE))
  89. return XLATE(p, L4_34XX_PHYS, L4_34XX_VIRT);
  90. if (BETWEEN(p, OMAP34XX_GPMC_PHYS, OMAP34XX_GPMC_SIZE))
  91. return XLATE(p, OMAP34XX_GPMC_PHYS, OMAP34XX_GPMC_VIRT);
  92. if (BETWEEN(p, OMAP343X_SMS_PHYS, OMAP343X_SMS_SIZE))
  93. return XLATE(p, OMAP343X_SMS_PHYS, OMAP343X_SMS_VIRT);
  94. if (BETWEEN(p, OMAP343X_SDRC_PHYS, OMAP343X_SDRC_SIZE))
  95. return XLATE(p, OMAP343X_SDRC_PHYS, OMAP343X_SDRC_VIRT);
  96. if (BETWEEN(p, L4_PER_34XX_PHYS, L4_PER_34XX_SIZE))
  97. return XLATE(p, L4_PER_34XX_PHYS, L4_PER_34XX_VIRT);
  98. if (BETWEEN(p, L4_EMU_34XX_PHYS, L4_EMU_34XX_SIZE))
  99. return XLATE(p, L4_EMU_34XX_PHYS, L4_EMU_34XX_VIRT);
  100. }
  101. #endif
  102. #ifdef CONFIG_ARCH_OMAP4
  103. if (cpu_is_omap44xx()) {
  104. if (BETWEEN(p, L3_44XX_PHYS, L3_44XX_SIZE))
  105. return XLATE(p, L3_44XX_PHYS, L3_44XX_VIRT);
  106. if (BETWEEN(p, L4_44XX_PHYS, L4_44XX_SIZE))
  107. return XLATE(p, L4_44XX_PHYS, L4_44XX_VIRT);
  108. if (BETWEEN(p, OMAP44XX_GPMC_PHYS, OMAP44XX_GPMC_SIZE))
  109. return XLATE(p, OMAP44XX_GPMC_PHYS, OMAP44XX_GPMC_VIRT);
  110. if (BETWEEN(p, OMAP44XX_EMIF1_PHYS, OMAP44XX_EMIF1_SIZE))
  111. return XLATE(p, OMAP44XX_EMIF1_PHYS, \
  112. OMAP44XX_EMIF1_VIRT);
  113. if (BETWEEN(p, OMAP44XX_EMIF2_PHYS, OMAP44XX_EMIF2_SIZE))
  114. return XLATE(p, OMAP44XX_EMIF2_PHYS, \
  115. OMAP44XX_EMIF2_VIRT);
  116. if (BETWEEN(p, OMAP44XX_DMM_PHYS, OMAP44XX_DMM_SIZE))
  117. return XLATE(p, OMAP44XX_DMM_PHYS, OMAP44XX_DMM_VIRT);
  118. if (BETWEEN(p, L4_PER_44XX_PHYS, L4_PER_44XX_SIZE))
  119. return XLATE(p, L4_PER_44XX_PHYS, L4_PER_44XX_VIRT);
  120. if (BETWEEN(p, L4_EMU_44XX_PHYS, L4_EMU_44XX_SIZE))
  121. return XLATE(p, L4_EMU_44XX_PHYS, L4_EMU_44XX_VIRT);
  122. }
  123. #endif
  124. return __arm_ioremap_caller(p, size, type, __builtin_return_address(0));
  125. }
  126. EXPORT_SYMBOL(omap_ioremap);
  127. void omap_iounmap(volatile void __iomem *addr)
  128. {
  129. unsigned long virt = (unsigned long)addr;
  130. if (virt >= VMALLOC_START && virt < VMALLOC_END)
  131. __iounmap(addr);
  132. }
  133. EXPORT_SYMBOL(omap_iounmap);