musb_io.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * version 2 as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA
  21. *
  22. * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
  23. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  24. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  25. * NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  26. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  27. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  28. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  29. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  31. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. *
  33. */
  34. #ifndef __MUSB_LINUX_PLATFORM_ARCH_H__
  35. #define __MUSB_LINUX_PLATFORM_ARCH_H__
  36. #include <linux/io.h>
  37. #include <linux/spinlock.h>
  38. extern bool mtk_usb_power;
  39. extern bool usb_enable_clock(bool enable);
  40. extern spinlock_t usb_io_lock;
  41. static inline u16 musb_readw(const void __iomem *addr, unsigned offset)
  42. {
  43. u16 rc = 0;
  44. if (mtk_usb_power) {
  45. rc = readw(addr + offset);
  46. } else {
  47. unsigned long flags = 0;
  48. spin_lock_irqsave(&usb_io_lock, flags);
  49. usb_enable_clock(true);
  50. DBG(1, "[MUSB]:access %s function when usb clock is off 0x%X\n", __func__, offset);
  51. rc = readw(addr + offset);
  52. usb_enable_clock(false);
  53. spin_unlock_irqrestore(&usb_io_lock, flags);
  54. }
  55. return rc;
  56. }
  57. static inline u32 musb_readl(const void __iomem *addr, unsigned offset)
  58. {
  59. u32 rc = 0;
  60. if (mtk_usb_power) {
  61. rc = readl(addr + offset);
  62. } else {
  63. unsigned long flags = 0;
  64. spin_lock_irqsave(&usb_io_lock, flags);
  65. usb_enable_clock(true);
  66. DBG(1, "[MUSB]:access %s function when usb clock is off 0x%X\n", __func__, offset);
  67. rc = readl(addr + offset);
  68. usb_enable_clock(false);
  69. spin_unlock_irqrestore(&usb_io_lock, flags);
  70. }
  71. return rc;
  72. }
  73. static inline void musb_writew(void __iomem *addr, unsigned offset, u16 data)
  74. {
  75. if (mtk_usb_power) {
  76. writew(data, addr + offset);
  77. } else {
  78. unsigned long flags = 0;
  79. spin_lock_irqsave(&usb_io_lock, flags);
  80. usb_enable_clock(true);
  81. DBG(1, "[MUSB]:access %s function when usb clock is off 0x%X\n", __func__, offset);
  82. writew(data, addr + offset);
  83. usb_enable_clock(false);
  84. spin_unlock_irqrestore(&usb_io_lock, flags);
  85. }
  86. }
  87. static inline void musb_writel(void __iomem *addr, unsigned offset, u32 data)
  88. {
  89. if (mtk_usb_power) {
  90. writel(data, addr + offset);
  91. } else {
  92. unsigned long flags = 0;
  93. spin_lock_irqsave(&usb_io_lock, flags);
  94. usb_enable_clock(true);
  95. DBG(1, "[MUSB]:access %s function when usb clock is off 0x%X\n", __func__, offset);
  96. writel(data, addr + offset);
  97. usb_enable_clock(false);
  98. spin_unlock_irqrestore(&usb_io_lock, flags);
  99. }
  100. }
  101. static inline u8 musb_readb(const void __iomem *addr, unsigned offset)
  102. {
  103. u8 rc = 0;
  104. if (mtk_usb_power) {
  105. rc = readb(addr + offset);
  106. } else {
  107. unsigned long flags = 0;
  108. spin_lock_irqsave(&usb_io_lock, flags);
  109. usb_enable_clock(true);
  110. DBG(1, "[MUSB]:access %s function when usb clock is off 0x%X\n", __func__, offset);
  111. rc = readb(addr + offset);
  112. usb_enable_clock(false);
  113. spin_unlock_irqrestore(&usb_io_lock, flags);
  114. }
  115. return rc;
  116. }
  117. static inline void musb_writeb(void __iomem *addr, unsigned offset, u8 data)
  118. {
  119. if (mtk_usb_power) {
  120. writeb(data, addr + offset);
  121. } else {
  122. unsigned long flags = 0;
  123. spin_lock_irqsave(&usb_io_lock, flags);
  124. usb_enable_clock(true);
  125. DBG(1, "[MUSB]:access %s function when usb clock is off 0x%X\n", __func__, offset);
  126. writeb(data, addr + offset);
  127. usb_enable_clock(false);
  128. spin_unlock_irqrestore(&usb_io_lock, flags);
  129. }
  130. }
  131. #endif