musb_io.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. #if !defined(CONFIG_ARM) && !defined(CONFIG_SUPERH) \
  38. && !defined(CONFIG_AVR32) && !defined(CONFIG_PPC32) \
  39. && !defined(CONFIG_PPC64) && !defined(CONFIG_BLACKFIN) \
  40. && !defined(CONFIG_MIPS)
  41. static inline void readsl(const void __iomem *addr, void *buf, int len)
  42. { insl((unsigned long)addr, buf, len); }
  43. static inline void readsw(const void __iomem *addr, void *buf, int len)
  44. { insw((unsigned long)addr, buf, len); }
  45. static inline void readsb(const void __iomem *addr, void *buf, int len)
  46. { insb((unsigned long)addr, buf, len); }
  47. static inline void writesl(const void __iomem *addr, const void *buf, int len)
  48. { outsl((unsigned long)addr, buf, len); }
  49. static inline void writesw(const void __iomem *addr, const void *buf, int len)
  50. { outsw((unsigned long)addr, buf, len); }
  51. static inline void writesb(const void __iomem *addr, const void *buf, int len)
  52. { outsb((unsigned long)addr, buf, len); }
  53. #endif
  54. #ifndef CONFIG_BLACKFIN
  55. /* NOTE: these offsets are all in bytes */
  56. static inline u16 musb_readw(const void __iomem *addr, unsigned offset)
  57. { return __raw_readw(addr + offset); }
  58. static inline u32 musb_readl(const void __iomem *addr, unsigned offset)
  59. { return __raw_readl(addr + offset); }
  60. static inline void musb_writew(void __iomem *addr, unsigned offset, u16 data)
  61. { __raw_writew(data, addr + offset); }
  62. static inline void musb_writel(void __iomem *addr, unsigned offset, u32 data)
  63. { __raw_writel(data, addr + offset); }
  64. #if defined(CONFIG_USB_MUSB_TUSB6010) || defined (CONFIG_USB_MUSB_TUSB6010_MODULE)
  65. /*
  66. * TUSB6010 doesn't allow 8-bit access; 16-bit access is the minimum.
  67. */
  68. static inline u8 musb_readb(const void __iomem *addr, unsigned offset)
  69. {
  70. u16 tmp;
  71. u8 val;
  72. tmp = __raw_readw(addr + (offset & ~1));
  73. if (offset & 1)
  74. val = (tmp >> 8);
  75. else
  76. val = tmp & 0xff;
  77. return val;
  78. }
  79. static inline void musb_writeb(void __iomem *addr, unsigned offset, u8 data)
  80. {
  81. u16 tmp;
  82. tmp = __raw_readw(addr + (offset & ~1));
  83. if (offset & 1)
  84. tmp = (data << 8) | (tmp & 0xff);
  85. else
  86. tmp = (tmp & 0xff00) | data;
  87. __raw_writew(tmp, addr + (offset & ~1));
  88. }
  89. #else
  90. static inline u8 musb_readb(const void __iomem *addr, unsigned offset)
  91. { return __raw_readb(addr + offset); }
  92. static inline void musb_writeb(void __iomem *addr, unsigned offset, u8 data)
  93. { __raw_writeb(data, addr + offset); }
  94. #endif /* CONFIG_USB_MUSB_TUSB6010 */
  95. #else
  96. static inline u8 musb_readb(const void __iomem *addr, unsigned offset)
  97. { return (u8) (bfin_read16(addr + offset)); }
  98. static inline u16 musb_readw(const void __iomem *addr, unsigned offset)
  99. { return bfin_read16(addr + offset); }
  100. static inline u32 musb_readl(const void __iomem *addr, unsigned offset)
  101. { return (u32) (bfin_read16(addr + offset)); }
  102. static inline void musb_writeb(void __iomem *addr, unsigned offset, u8 data)
  103. { bfin_write16(addr + offset, (u16) data); }
  104. static inline void musb_writew(void __iomem *addr, unsigned offset, u16 data)
  105. { bfin_write16(addr + offset, data); }
  106. static inline void musb_writel(void __iomem *addr, unsigned offset, u32 data)
  107. { bfin_write16(addr + offset, (u16) data); }
  108. #endif /* CONFIG_BLACKFIN */
  109. #endif