ci13xxx_udc.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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 CI13XXX_PAGE_SIZE 4096ul /* page size for TD's */
  21. #define ENDPT_MAX (32)
  22. #define CTRL_PAYLOAD_MAX (64)
  23. #define RX (0) /* similar to USB_DIR_OUT but can be used as an index */
  24. #define TX (1) /* similar to USB_DIR_IN but can be used as an index */
  25. /******************************************************************************
  26. * STRUCTURES
  27. *****************************************************************************/
  28. /* DMA layout of transfer descriptors */
  29. struct ci13xxx_td {
  30. /* 0 */
  31. u32 next;
  32. #define TD_TERMINATE BIT(0)
  33. #define TD_ADDR_MASK (0xFFFFFFEUL << 5)
  34. /* 1 */
  35. u32 token;
  36. #define TD_STATUS (0x00FFUL << 0)
  37. #define TD_STATUS_TR_ERR BIT(3)
  38. #define TD_STATUS_DT_ERR BIT(5)
  39. #define TD_STATUS_HALTED BIT(6)
  40. #define TD_STATUS_ACTIVE BIT(7)
  41. #define TD_MULTO (0x0003UL << 10)
  42. #define TD_IOC BIT(15)
  43. #define TD_TOTAL_BYTES (0x7FFFUL << 16)
  44. /* 2 */
  45. u32 page[5];
  46. #define TD_CURR_OFFSET (0x0FFFUL << 0)
  47. #define TD_FRAME_NUM (0x07FFUL << 0)
  48. #define TD_RESERVED_MASK (0x0FFFUL << 0)
  49. } __attribute__ ((packed));
  50. /* DMA layout of queue heads */
  51. struct ci13xxx_qh {
  52. /* 0 */
  53. u32 cap;
  54. #define QH_IOS BIT(15)
  55. #define QH_MAX_PKT (0x07FFUL << 16)
  56. #define QH_ZLT BIT(29)
  57. #define QH_MULT (0x0003UL << 30)
  58. /* 1 */
  59. u32 curr;
  60. /* 2 - 8 */
  61. struct ci13xxx_td td;
  62. /* 9 */
  63. u32 RESERVED;
  64. struct usb_ctrlrequest setup;
  65. } __attribute__ ((packed));
  66. /* Extension of usb_request */
  67. struct ci13xxx_req {
  68. struct usb_request req;
  69. unsigned map;
  70. struct list_head queue;
  71. struct ci13xxx_td *ptr;
  72. dma_addr_t dma;
  73. struct ci13xxx_td *zptr;
  74. dma_addr_t zdma;
  75. };
  76. /* Extension of usb_ep */
  77. struct ci13xxx_ep {
  78. struct usb_ep ep;
  79. u8 dir;
  80. u8 num;
  81. u8 type;
  82. char name[16];
  83. struct {
  84. struct list_head queue;
  85. struct ci13xxx_qh *ptr;
  86. dma_addr_t dma;
  87. } qh;
  88. int wedge;
  89. /* global resources */
  90. spinlock_t *lock;
  91. struct device *device;
  92. struct dma_pool *td_pool;
  93. };
  94. struct ci13xxx;
  95. struct ci13xxx_udc_driver {
  96. const char *name;
  97. unsigned long flags;
  98. #define CI13XXX_REGS_SHARED BIT(0)
  99. #define CI13XXX_REQUIRE_TRANSCEIVER BIT(1)
  100. #define CI13XXX_PULLUP_ON_VBUS BIT(2)
  101. #define CI13XXX_DISABLE_STREAMING BIT(3)
  102. #define CI13XXX_CONTROLLER_RESET_EVENT 0
  103. #define CI13XXX_CONTROLLER_STOPPED_EVENT 1
  104. void (*notify_event) (struct ci13xxx *udc, unsigned event);
  105. };
  106. /* CI13XXX UDC descriptor & global resources */
  107. struct ci13xxx {
  108. spinlock_t *lock; /* ctrl register bank access */
  109. void __iomem *regs; /* registers address space */
  110. struct dma_pool *qh_pool; /* DMA pool for queue heads */
  111. struct dma_pool *td_pool; /* DMA pool for transfer descs */
  112. struct usb_request *status; /* ep0 status request */
  113. struct usb_gadget gadget; /* USB slave device */
  114. struct ci13xxx_ep ci13xxx_ep[ENDPT_MAX]; /* extended endpts */
  115. u32 ep0_dir; /* ep0 direction */
  116. #define ep0out ci13xxx_ep[0]
  117. #define ep0in ci13xxx_ep[hw_ep_max / 2]
  118. u8 remote_wakeup; /* Is remote wakeup feature
  119. enabled by the host? */
  120. u8 suspended; /* suspended by the host */
  121. u8 test_mode; /* the selected test mode */
  122. struct usb_gadget_driver *driver; /* 3rd party gadget driver */
  123. struct ci13xxx_udc_driver *udc_driver; /* device controller driver */
  124. int vbus_active; /* is VBUS active */
  125. struct usb_phy *transceiver; /* Transceiver struct */
  126. };
  127. /******************************************************************************
  128. * REGISTERS
  129. *****************************************************************************/
  130. /* register size */
  131. #define REG_BITS (32)
  132. /* HCCPARAMS */
  133. #define HCCPARAMS_LEN BIT(17)
  134. /* DCCPARAMS */
  135. #define DCCPARAMS_DEN (0x1F << 0)
  136. #define DCCPARAMS_DC BIT(7)
  137. /* TESTMODE */
  138. #define TESTMODE_FORCE BIT(0)
  139. /* USBCMD */
  140. #define USBCMD_RS BIT(0)
  141. #define USBCMD_RST BIT(1)
  142. #define USBCMD_SUTW BIT(13)
  143. #define USBCMD_ATDTW BIT(14)
  144. /* USBSTS & USBINTR */
  145. #define USBi_UI BIT(0)
  146. #define USBi_UEI BIT(1)
  147. #define USBi_PCI BIT(2)
  148. #define USBi_URI BIT(6)
  149. #define USBi_SLI BIT(8)
  150. /* DEVICEADDR */
  151. #define DEVICEADDR_USBADRA BIT(24)
  152. #define DEVICEADDR_USBADR (0x7FUL << 25)
  153. /* PORTSC */
  154. #define PORTSC_FPR BIT(6)
  155. #define PORTSC_SUSP BIT(7)
  156. #define PORTSC_HSP BIT(9)
  157. #define PORTSC_PTC (0x0FUL << 16)
  158. /* DEVLC */
  159. #define DEVLC_PSPD (0x03UL << 25)
  160. #define DEVLC_PSPD_HS (0x02UL << 25)
  161. /* USBMODE */
  162. #define USBMODE_CM (0x03UL << 0)
  163. #define USBMODE_CM_IDLE (0x00UL << 0)
  164. #define USBMODE_CM_DEVICE (0x02UL << 0)
  165. #define USBMODE_CM_HOST (0x03UL << 0)
  166. #define USBMODE_SLOM BIT(3)
  167. #define USBMODE_SDIS BIT(4)
  168. /* ENDPTCTRL */
  169. #define ENDPTCTRL_RXS BIT(0)
  170. #define ENDPTCTRL_RXT (0x03UL << 2)
  171. #define ENDPTCTRL_RXR BIT(6) /* reserved for port 0 */
  172. #define ENDPTCTRL_RXE BIT(7)
  173. #define ENDPTCTRL_TXS BIT(16)
  174. #define ENDPTCTRL_TXT (0x03UL << 18)
  175. #define ENDPTCTRL_TXR BIT(22) /* reserved for port 0 */
  176. #define ENDPTCTRL_TXE BIT(23)
  177. /******************************************************************************
  178. * LOGGING
  179. *****************************************************************************/
  180. #define ci13xxx_printk(level, format, args...) \
  181. do { \
  182. if (_udc == NULL) \
  183. printk(level "[%s] " format "\n", __func__, ## args); \
  184. else \
  185. dev_printk(level, _udc->gadget.dev.parent, \
  186. "[%s] " format "\n", __func__, ## args); \
  187. } while (0)
  188. #define warn(format, args...) ci13xxx_printk(KERN_WARNING, format, ## args)
  189. #define info(format, args...) ci13xxx_printk(KERN_INFO, format, ## args)
  190. #ifdef TRACE
  191. #define trace(format, args...) ci13xxx_printk(KERN_DEBUG, format, ## args)
  192. #define dbg_trace(format, args...) dev_dbg(dev, format, ##args)
  193. #else
  194. #define trace(format, args...) do {} while (0)
  195. #define dbg_trace(format, args...) do {} while (0)
  196. #endif
  197. #endif /* _CI13XXX_h_ */