mv_udc.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * Copyright 2011, Marvell Semiconductor Inc.
  3. * Lei Wen <leiwen@marvell.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  18. * MA 02111-1307 USA
  19. */
  20. #ifndef __MV_UDC_H__
  21. #define __MV_UDC_H__
  22. #include <asm/byteorder.h>
  23. #include <asm/errno.h>
  24. #include <linux/usb/ch9.h>
  25. #include <linux/usb/gadget.h>
  26. /* Endpoint 0 states */
  27. #define EP0_IDLE 0
  28. #define EP0_IN_DATA 1
  29. #define EP0_OUT_DATA 2
  30. #define EP0_XFER_COMPLETE 3
  31. /* Endpoint parameters */
  32. #define MAX_ENDPOINTS 4
  33. #define EP_MAX_PACKET_SIZE 0x200
  34. #define EP0_MAX_PACKET_SIZE 64
  35. #define UDC_OUT_ENDPOINT 0x02
  36. #define UDC_OUT_PACKET_SIZE EP_MAX_PACKET_SIZE
  37. #define UDC_IN_ENDPOINT 0x01
  38. #define UDC_IN_PACKET_SIZE EP_MAX_PACKET_SIZE
  39. #define UDC_INT_ENDPOINT 0x05
  40. #define UDC_INT_PACKET_SIZE EP_MAX_PACKET_SIZE
  41. #define UDC_BULK_PACKET_SIZE EP_MAX_PACKET_SIZE
  42. #define NUM_ENDPOINTS 6
  43. #define REQ_COUNT 12
  44. struct mv_ep {
  45. struct usb_ep ep;
  46. struct usb_request req;
  47. struct list_head queue;
  48. const struct usb_endpoint_descriptor *desc;
  49. };
  50. struct mv_udc {
  51. u32 pad0[80];
  52. #define MICRO_8FRAME 0x8
  53. #define USBCMD_ITC(x) (((x > 0xff) ? 0xff : x) << 16)
  54. #define USBCMD_FS2 (1 << 15)
  55. #define USBCMD_RST (1 << 1)
  56. #define USBCMD_RUN (1)
  57. u32 usbcmd; /* 0x140 */
  58. #define STS_SLI (1 << 8)
  59. #define STS_URI (1 << 6)
  60. #define STS_PCI (1 << 2)
  61. #define STS_UEI (1 << 1)
  62. #define STS_UI (1 << 0)
  63. u32 usbsts; /* 0x144 */
  64. u32 pad1[3];
  65. u32 devaddr; /* 0x154 */
  66. u32 epinitaddr; /* 0x158 */
  67. u32 pad2[10];
  68. #define PTS_ENABLE 2
  69. #define PTS(x) ((x & 0x3) << 30)
  70. #define PFSC (1 << 24)
  71. u32 portsc; /* 0x184 */
  72. u32 pad3[8];
  73. #define USBMODE_DEVICE 2
  74. u32 usbmode; /* 0x1a8 */
  75. u32 epstat; /* 0x1ac */
  76. #define EPT_TX(x) (1 << ((x & 0xffff) + 16))
  77. #define EPT_RX(x) (1 << (x & 0xffff))
  78. u32 epprime; /* 0x1b0 */
  79. u32 epflush; /* 0x1b4 */
  80. u32 pad4;
  81. u32 epcomp; /* 0x1bc */
  82. #define CTRL_TXE (1 << 23)
  83. #define CTRL_TXR (1 << 22)
  84. #define CTRL_RXE (1 << 7)
  85. #define CTRL_RXR (1 << 6)
  86. #define CTRL_TXT_BULK (2 << 18)
  87. #define CTRL_RXT_BULK (2 << 2)
  88. u32 epctrl[16]; /* 0x1c0 */
  89. };
  90. struct mv_drv {
  91. struct usb_gadget gadget;
  92. struct usb_gadget_driver *driver;
  93. struct mv_udc *udc;
  94. };
  95. struct ept_queue_head {
  96. unsigned config;
  97. unsigned current; /* read-only */
  98. unsigned next;
  99. unsigned info;
  100. unsigned page0;
  101. unsigned page1;
  102. unsigned page2;
  103. unsigned page3;
  104. unsigned page4;
  105. unsigned reserved_0;
  106. unsigned char setup_data[8];
  107. unsigned reserved_1;
  108. unsigned reserved_2;
  109. unsigned reserved_3;
  110. unsigned reserved_4;
  111. };
  112. #define CONFIG_MAX_PKT(n) ((n) << 16)
  113. #define CONFIG_ZLT (1 << 29) /* stop on zero-len xfer */
  114. #define CONFIG_IOS (1 << 15) /* IRQ on setup */
  115. struct ept_queue_item {
  116. unsigned next;
  117. unsigned info;
  118. unsigned page0;
  119. unsigned page1;
  120. unsigned page2;
  121. unsigned page3;
  122. unsigned page4;
  123. unsigned reserved;
  124. };
  125. #define TERMINATE 1
  126. #define INFO_BYTES(n) ((n) << 16)
  127. #define INFO_IOC (1 << 15)
  128. #define INFO_ACTIVE (1 << 7)
  129. #define INFO_HALTED (1 << 6)
  130. #define INFO_BUFFER_ERROR (1 << 5)
  131. #define INFO_TX_ERROR (1 << 3)
  132. extern int usb_lowlevel_init(int index, void **controller);
  133. #endif /* __MV_UDC_H__ */