musbfsh_io.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /*
  2. * MUSB OTG driver register I/O
  3. *
  4. * Copyright 2005 Mentor Graphics Corporation
  5. * Copyright (C) 2005-2006 by Texas Instruments
  6. * Copyright (C) 2006-2007 Nokia Corporation
  7. *
  8. * Copyright 2015 Mediatek Inc.
  9. * Marvin Lin <marvin.lin@mediatek.com>
  10. * Arvin Wang <arvin.wang@mediatek.com>
  11. * Vincent Fan <vincent.fan@mediatek.com>
  12. * Bryant Lu <bryant.lu@mediatek.com>
  13. * Yu-Chang Wang <yu-chang.wang@mediatek.com>
  14. * Macpaul Lin <macpaul.lin@mediatek.com>
  15. *
  16. * This program is free software; you can redistribute it and/or
  17. * modify it under the terms of the GNU General Public License
  18. * version 2 as published by the Free Software Foundation.
  19. *
  20. * This program is distributed in the hope that it will be useful, but
  21. * WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  23. * General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with this program.
  27. *
  28. * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
  29. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  30. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  31. * NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  32. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  33. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  34. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  35. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  36. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  37. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. */
  40. #ifndef __MUSBFSH_LINUX_PLATFORM_ARCH_H__
  41. #define __MUSBFSH_LINUX_PLATFORM_ARCH_H__
  42. #include <linux/io.h>
  43. #include <linux/spinlock.h>
  44. extern spinlock_t musbfs_io_lock;
  45. extern void mt65xx_usb11_clock_enable(bool enable);
  46. extern bool musbfsh_power;
  47. /* NOTE: these offsets are all in bytes */
  48. static inline u16 musbfsh_readw(const void __iomem *addr, unsigned offset)
  49. {
  50. u16 rc = 0;
  51. if (musbfsh_power) {
  52. rc = readw(addr + offset);
  53. } else {
  54. unsigned long flags = 0;
  55. spin_lock_irqsave(&musbfs_io_lock, flags);
  56. mt65xx_usb11_clock_enable(true);
  57. /*
  58. * DBG(0, "[MUSBfsh]: access %s FUNC: USB CLK is off 0x%X\n",
  59. * __func__, offset);
  60. */
  61. rc = readw(addr + offset);
  62. mt65xx_usb11_clock_enable(false);
  63. spin_unlock_irqrestore(&musbfs_io_lock, flags);
  64. }
  65. return rc;
  66. }
  67. static inline u32 musbfsh_readl(const void __iomem *addr, unsigned offset)
  68. {
  69. u32 rc = 0;
  70. if (musbfsh_power) {
  71. rc = readl(addr + offset);
  72. } else {
  73. unsigned long flags = 0;
  74. spin_lock_irqsave(&musbfs_io_lock, flags);
  75. mt65xx_usb11_clock_enable(true);
  76. /*
  77. * DBG(0, "[MUSBfsh]: access %s FUNC: USB CLK is off 0x%X\n",
  78. * __func__, offset);
  79. */
  80. rc = readl(addr + offset);
  81. mt65xx_usb11_clock_enable(false);
  82. spin_unlock_irqrestore(&musbfs_io_lock, flags);
  83. }
  84. return rc;
  85. }
  86. static inline void musbfsh_writew(void __iomem *addr, unsigned offset, u16 data)
  87. {
  88. if (musbfsh_power) {
  89. writew(data, addr + offset);
  90. } else {
  91. unsigned long flags = 0;
  92. spin_lock_irqsave(&musbfs_io_lock, flags);
  93. mt65xx_usb11_clock_enable(true);
  94. /*
  95. * DBG(0, "[MUSBfsh]: access %s FUNC: USB CLK is off 0x%X\n",
  96. * __func__, offset);
  97. */
  98. writew(data, addr + offset);
  99. mt65xx_usb11_clock_enable(false);
  100. spin_unlock_irqrestore(&musbfs_io_lock, flags);
  101. }
  102. }
  103. static inline void musbfsh_writel(void __iomem *addr, unsigned offset, u32 data)
  104. {
  105. if (musbfsh_power) {
  106. writel(data, addr + offset);
  107. } else {
  108. unsigned long flags = 0;
  109. spin_lock_irqsave(&musbfs_io_lock, flags);
  110. mt65xx_usb11_clock_enable(true);
  111. /*
  112. * DBG(0, "[MUSBfsh]: access %s FUNC: USB CLK is off 0x%X\n",
  113. * __func__, offset);
  114. */
  115. writel(data, addr + offset);
  116. mt65xx_usb11_clock_enable(false);
  117. spin_unlock_irqrestore(&musbfs_io_lock, flags);
  118. }
  119. }
  120. static inline u8 musbfsh_readb(const void __iomem *addr, unsigned offset)
  121. {
  122. u8 rc = 0;
  123. if (musbfsh_power) {
  124. rc = readb(addr + offset);
  125. } else {
  126. unsigned long flags = 0;
  127. spin_lock_irqsave(&musbfs_io_lock, flags);
  128. mt65xx_usb11_clock_enable(true);
  129. /*
  130. * DBG(0, "[MUSBfsh]: access %s FUNC: USB CLK is off 0x%X\n",
  131. * __func__, offset);
  132. */
  133. rc = readb(addr + offset);
  134. mt65xx_usb11_clock_enable(false);
  135. spin_unlock_irqrestore(&musbfs_io_lock, flags);
  136. }
  137. return rc;
  138. }
  139. static inline void musbfsh_writeb(void __iomem *addr, unsigned offset, u8 data)
  140. {
  141. if (musbfsh_power) {
  142. writeb(data, addr + offset);
  143. } else {
  144. unsigned long flags = 0;
  145. spin_lock_irqsave(&musbfs_io_lock, flags);
  146. mt65xx_usb11_clock_enable(true);
  147. /*
  148. * DBG(0, "[MUSBfsh]: access %s FUNC: USB CLK is off 0x%X\n",
  149. * __func__, offset);
  150. */
  151. writeb(data, addr + offset);
  152. mt65xx_usb11_clock_enable(false);
  153. spin_unlock_irqrestore(&musbfs_io_lock, flags);
  154. }
  155. }
  156. /* NOTE: these offsets are all in bytes */
  157. #if 0
  158. static inline u16 musbfsh_readw(const void __iomem *addr, unsigned offset)
  159. {
  160. return readw(addr + offset);
  161. }
  162. static inline u32 musbfsh_readl(const void __iomem *addr, unsigned offset)
  163. {
  164. return readl(addr + offset);
  165. }
  166. static inline void musbfsh_writew(void __iomem *addr, unsigned offset, u16 data)
  167. {
  168. writew(data, addr + offset);
  169. }
  170. static inline void musbfsh_writel(void __iomem *addr, unsigned offset, u32 data)
  171. {
  172. writel(data, addr + offset);
  173. }
  174. static inline u8 musbfsh_readb(const void __iomem *addr, unsigned offset)
  175. {
  176. return readb(addr + offset);
  177. }
  178. static inline void musbfsh_writeb(void __iomem *addr, unsigned offset, u8 data)
  179. {
  180. writeb(data, addr + offset);
  181. }
  182. #endif
  183. #endif