musbhsdma.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. * MUSB OTG driver - support for Mentor's DMA controller
  3. *
  4. * Copyright 2005 Mentor Graphics Corporation
  5. * Copyright (C) 2005-2007 by Texas Instruments
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * version 2 as published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  19. * 02110-1301 USA
  20. *
  21. * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
  22. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  23. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  24. * NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  25. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  26. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  27. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  28. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  30. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. *
  32. */
  33. #if defined(CONFIG_SOC_OMAP2430) || defined(CONFIG_SOC_OMAP3430)
  34. #include "omap2430.h"
  35. #endif
  36. #ifndef CONFIG_BLACKFIN
  37. #define MUSB_HSDMA_BASE 0x200
  38. #define MUSB_HSDMA_INTR (MUSB_HSDMA_BASE + 0)
  39. #define MUSB_HSDMA_CONTROL 0x4
  40. #define MUSB_HSDMA_ADDRESS 0x8
  41. #define MUSB_HSDMA_COUNT 0xc
  42. #define MUSB_HSDMA_CHANNEL_OFFSET(_bchannel, _offset) \
  43. (MUSB_HSDMA_BASE + (_bchannel << 4) + _offset)
  44. #define musb_read_hsdma_addr(mbase, bchannel) \
  45. musb_readl(mbase, \
  46. MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_ADDRESS))
  47. #define musb_write_hsdma_addr(mbase, bchannel, addr) \
  48. musb_writel(mbase, \
  49. MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_ADDRESS), \
  50. addr)
  51. #define musb_read_hsdma_count(mbase, bchannel) \
  52. musb_readl(mbase, \
  53. MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_COUNT))
  54. #define musb_write_hsdma_count(mbase, bchannel, len) \
  55. musb_writel(mbase, \
  56. MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_COUNT), \
  57. len)
  58. #else
  59. #define MUSB_HSDMA_BASE 0x400
  60. #define MUSB_HSDMA_INTR (MUSB_HSDMA_BASE + 0)
  61. #define MUSB_HSDMA_CONTROL 0x04
  62. #define MUSB_HSDMA_ADDR_LOW 0x08
  63. #define MUSB_HSDMA_ADDR_HIGH 0x0C
  64. #define MUSB_HSDMA_COUNT_LOW 0x10
  65. #define MUSB_HSDMA_COUNT_HIGH 0x14
  66. #define MUSB_HSDMA_CHANNEL_OFFSET(_bchannel, _offset) \
  67. (MUSB_HSDMA_BASE + (_bchannel * 0x20) + _offset)
  68. static inline u32 musb_read_hsdma_addr(void __iomem *mbase, u8 bchannel)
  69. {
  70. u32 addr = musb_readw(mbase,
  71. MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_ADDR_HIGH));
  72. addr = addr << 16;
  73. addr |= musb_readw(mbase,
  74. MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_ADDR_LOW));
  75. return addr;
  76. }
  77. static inline void musb_write_hsdma_addr(void __iomem *mbase,
  78. u8 bchannel, dma_addr_t dma_addr)
  79. {
  80. musb_writew(mbase,
  81. MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_ADDR_LOW),
  82. dma_addr);
  83. musb_writew(mbase,
  84. MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_ADDR_HIGH),
  85. (dma_addr >> 16));
  86. }
  87. static inline u32 musb_read_hsdma_count(void __iomem *mbase, u8 bchannel)
  88. {
  89. u32 count = musb_readw(mbase,
  90. MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_COUNT_HIGH));
  91. count = count << 16;
  92. count |= musb_readw(mbase,
  93. MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_COUNT_LOW));
  94. return count;
  95. }
  96. static inline void musb_write_hsdma_count(void __iomem *mbase,
  97. u8 bchannel, u32 len)
  98. {
  99. musb_writew(mbase,
  100. MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_COUNT_LOW),len);
  101. musb_writew(mbase,
  102. MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_COUNT_HIGH),
  103. (len >> 16));
  104. }
  105. #endif /* CONFIG_BLACKFIN */
  106. /* control register (16-bit): */
  107. #define MUSB_HSDMA_ENABLE_SHIFT 0
  108. #define MUSB_HSDMA_TRANSMIT_SHIFT 1
  109. #define MUSB_HSDMA_MODE1_SHIFT 2
  110. #define MUSB_HSDMA_IRQENABLE_SHIFT 3
  111. #define MUSB_HSDMA_ENDPOINT_SHIFT 4
  112. #define MUSB_HSDMA_BUSERROR_SHIFT 8
  113. #define MUSB_HSDMA_BURSTMODE_SHIFT 9
  114. #define MUSB_HSDMA_BURSTMODE (3 << MUSB_HSDMA_BURSTMODE_SHIFT)
  115. #define MUSB_HSDMA_BURSTMODE_UNSPEC 0
  116. #define MUSB_HSDMA_BURSTMODE_INCR4 1
  117. #define MUSB_HSDMA_BURSTMODE_INCR8 2
  118. #define MUSB_HSDMA_BURSTMODE_INCR16 3
  119. #define MUSB_HSDMA_CHANNELS 8
  120. struct musb_dma_controller;
  121. struct musb_dma_channel {
  122. struct dma_channel channel;
  123. struct musb_dma_controller *controller;
  124. u32 start_addr;
  125. u32 len;
  126. u16 max_packet_sz;
  127. u8 idx;
  128. u8 epnum;
  129. u8 transmit;
  130. };
  131. struct musb_dma_controller {
  132. struct dma_controller controller;
  133. struct musb_dma_channel channel[MUSB_HSDMA_CHANNELS];
  134. void *private_data;
  135. void __iomem *base;
  136. u8 channel_count;
  137. u8 used_channels;
  138. u8 irq;
  139. };