ci13xxx_udc.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /*
  2. * ci13xxx_udc.h - structures, registers, and macros MIPS USB IP core
  3. *
  4. * Copyright (C) 2008 Chipidea - MIPS Technologies, Inc. All rights reserved.
  5. *
  6. * Author: David Lopo
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. *
  12. * Description: MIPS USB IP core family device controller
  13. * Structures, registers and logging macros
  14. */
  15. #ifndef _CI13XXX_h_
  16. #define _CI13XXX_h_
  17. /******************************************************************************
  18. * DEFINE
  19. *****************************************************************************/
  20. #define ENDPT_MAX (16)
  21. #define CTRL_PAYLOAD_MAX (64)
  22. #define RX (0) /* similar to USB_DIR_OUT but can be used as an index */
  23. #define TX (1) /* similar to USB_DIR_IN but can be used as an index */
  24. /******************************************************************************
  25. * STRUCTURES
  26. *****************************************************************************/
  27. /* DMA layout of transfer descriptors */
  28. struct ci13xxx_td {
  29. /* 0 */
  30. u32 next;
  31. #define TD_TERMINATE BIT(0)
  32. /* 1 */
  33. u32 token;
  34. #define TD_STATUS (0x00FFUL << 0)
  35. #define TD_STATUS_TR_ERR BIT(3)
  36. #define TD_STATUS_DT_ERR BIT(5)
  37. #define TD_STATUS_HALTED BIT(6)
  38. #define TD_STATUS_ACTIVE BIT(7)
  39. #define TD_MULTO (0x0003UL << 10)
  40. #define TD_IOC BIT(15)
  41. #define TD_TOTAL_BYTES (0x7FFFUL << 16)
  42. /* 2 */
  43. u32 page[5];
  44. #define TD_CURR_OFFSET (0x0FFFUL << 0)
  45. #define TD_FRAME_NUM (0x07FFUL << 0)
  46. #define TD_RESERVED_MASK (0x0FFFUL << 0)
  47. } __attribute__ ((packed));
  48. /* DMA layout of queue heads */
  49. struct ci13xxx_qh {
  50. /* 0 */
  51. u32 cap;
  52. #define QH_IOS BIT(15)
  53. #define QH_MAX_PKT (0x07FFUL << 16)
  54. #define QH_ZLT BIT(29)
  55. #define QH_MULT (0x0003UL << 30)
  56. /* 1 */
  57. u32 curr;
  58. /* 2 - 8 */
  59. struct ci13xxx_td td;
  60. /* 9 */
  61. u32 RESERVED;
  62. struct usb_ctrlrequest setup;
  63. } __attribute__ ((packed));
  64. /* Extension of usb_request */
  65. struct ci13xxx_req {
  66. struct usb_request req;
  67. unsigned map;
  68. struct list_head queue;
  69. struct ci13xxx_td *ptr;
  70. dma_addr_t dma;
  71. };
  72. /* Extension of usb_ep */
  73. struct ci13xxx_ep {
  74. struct usb_ep ep;
  75. const struct usb_endpoint_descriptor *desc;
  76. u8 dir;
  77. u8 num;
  78. u8 type;
  79. char name[16];
  80. struct {
  81. struct list_head queue;
  82. struct ci13xxx_qh *ptr;
  83. dma_addr_t dma;
  84. } qh[2];
  85. struct usb_request *status;
  86. int wedge;
  87. /* global resources */
  88. spinlock_t *lock;
  89. struct device *device;
  90. struct dma_pool *td_pool;
  91. };
  92. /* CI13XXX UDC descriptor & global resources */
  93. struct ci13xxx {
  94. spinlock_t *lock; /* ctrl register bank access */
  95. struct dma_pool *qh_pool; /* DMA pool for queue heads */
  96. struct dma_pool *td_pool; /* DMA pool for transfer descs */
  97. struct usb_gadget gadget; /* USB slave device */
  98. struct ci13xxx_ep ci13xxx_ep[ENDPT_MAX]; /* extended endpts */
  99. struct usb_gadget_driver *driver; /* 3rd party gadget driver */
  100. };
  101. /******************************************************************************
  102. * REGISTERS
  103. *****************************************************************************/
  104. /* register size */
  105. #define REG_BITS (32)
  106. /* HCCPARAMS */
  107. #define HCCPARAMS_LEN BIT(17)
  108. /* DCCPARAMS */
  109. #define DCCPARAMS_DEN (0x1F << 0)
  110. #define DCCPARAMS_DC BIT(7)
  111. /* TESTMODE */
  112. #define TESTMODE_FORCE BIT(0)
  113. /* USBCMD */
  114. #define USBCMD_RS BIT(0)
  115. #define USBCMD_RST BIT(1)
  116. #define USBCMD_SUTW BIT(13)
  117. /* USBSTS & USBINTR */
  118. #define USBi_UI BIT(0)
  119. #define USBi_UEI BIT(1)
  120. #define USBi_PCI BIT(2)
  121. #define USBi_URI BIT(6)
  122. #define USBi_SLI BIT(8)
  123. /* DEVICEADDR */
  124. #define DEVICEADDR_USBADRA BIT(24)
  125. #define DEVICEADDR_USBADR (0x7FUL << 25)
  126. /* PORTSC */
  127. #define PORTSC_SUSP BIT(7)
  128. #define PORTSC_HSP BIT(9)
  129. #define PORTSC_PTC (0x0FUL << 16)
  130. /* DEVLC */
  131. #define DEVLC_PSPD (0x03UL << 25)
  132. #define DEVLC_PSPD_HS (0x02UL << 25)
  133. /* USBMODE */
  134. #define USBMODE_CM (0x03UL << 0)
  135. #define USBMODE_CM_IDLE (0x00UL << 0)
  136. #define USBMODE_CM_DEVICE (0x02UL << 0)
  137. #define USBMODE_CM_HOST (0x03UL << 0)
  138. #define USBMODE_SLOM BIT(3)
  139. /* ENDPTCTRL */
  140. #define ENDPTCTRL_RXS BIT(0)
  141. #define ENDPTCTRL_RXT (0x03UL << 2)
  142. #define ENDPTCTRL_RXR BIT(6) /* reserved for port 0 */
  143. #define ENDPTCTRL_RXE BIT(7)
  144. #define ENDPTCTRL_TXS BIT(16)
  145. #define ENDPTCTRL_TXT (0x03UL << 18)
  146. #define ENDPTCTRL_TXR BIT(22) /* reserved for port 0 */
  147. #define ENDPTCTRL_TXE BIT(23)
  148. /******************************************************************************
  149. * LOGGING
  150. *****************************************************************************/
  151. #define ci13xxx_printk(level, format, args...) \
  152. do { \
  153. if (_udc == NULL) \
  154. printk(level "[%s] " format "\n", __func__, ## args); \
  155. else \
  156. dev_printk(level, _udc->gadget.dev.parent, \
  157. "[%s] " format "\n", __func__, ## args); \
  158. } while (0)
  159. #define err(format, args...) ci13xxx_printk(KERN_ERR, format, ## args)
  160. #define warn(format, args...) ci13xxx_printk(KERN_WARNING, format, ## args)
  161. #define info(format, args...) ci13xxx_printk(KERN_INFO, format, ## args)
  162. #ifdef TRACE
  163. #define trace(format, args...) ci13xxx_printk(KERN_DEBUG, format, ## args)
  164. #define dbg_trace(format, args...) dev_dbg(dev, format, ##args)
  165. #else
  166. #define trace(format, args...) do {} while (0)
  167. #define dbg_trace(format, args...) do {} while (0)
  168. #endif
  169. #endif /* _CI13XXX_h_ */