ci13xxx_udc.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. struct ci13xxx;
  93. struct ci13xxx_udc_driver {
  94. const char *name;
  95. unsigned long flags;
  96. #define CI13XXX_REGS_SHARED BIT(0)
  97. #define CI13XXX_REQUIRE_TRANSCEIVER BIT(1)
  98. #define CI13XXX_PULLUP_ON_VBUS BIT(2)
  99. #define CI13XXX_DISABLE_STREAMING BIT(3)
  100. #define CI13XXX_CONTROLLER_RESET_EVENT 0
  101. #define CI13XXX_CONTROLLER_STOPPED_EVENT 1
  102. void (*notify_event) (struct ci13xxx *udc, unsigned event);
  103. };
  104. /* CI13XXX UDC descriptor & global resources */
  105. struct ci13xxx {
  106. spinlock_t *lock; /* ctrl register bank access */
  107. void __iomem *regs; /* registers address space */
  108. struct dma_pool *qh_pool; /* DMA pool for queue heads */
  109. struct dma_pool *td_pool; /* DMA pool for transfer descs */
  110. struct usb_gadget gadget; /* USB slave device */
  111. struct ci13xxx_ep ci13xxx_ep[ENDPT_MAX]; /* extended endpts */
  112. struct usb_gadget_driver *driver; /* 3rd party gadget driver */
  113. struct ci13xxx_udc_driver *udc_driver; /* device controller driver */
  114. int vbus_active; /* is VBUS active */
  115. struct otg_transceiver *transceiver; /* Transceiver struct */
  116. };
  117. /******************************************************************************
  118. * REGISTERS
  119. *****************************************************************************/
  120. /* register size */
  121. #define REG_BITS (32)
  122. /* HCCPARAMS */
  123. #define HCCPARAMS_LEN BIT(17)
  124. /* DCCPARAMS */
  125. #define DCCPARAMS_DEN (0x1F << 0)
  126. #define DCCPARAMS_DC BIT(7)
  127. /* TESTMODE */
  128. #define TESTMODE_FORCE BIT(0)
  129. /* USBCMD */
  130. #define USBCMD_RS BIT(0)
  131. #define USBCMD_RST BIT(1)
  132. #define USBCMD_SUTW BIT(13)
  133. /* USBSTS & USBINTR */
  134. #define USBi_UI BIT(0)
  135. #define USBi_UEI BIT(1)
  136. #define USBi_PCI BIT(2)
  137. #define USBi_URI BIT(6)
  138. #define USBi_SLI BIT(8)
  139. /* DEVICEADDR */
  140. #define DEVICEADDR_USBADRA BIT(24)
  141. #define DEVICEADDR_USBADR (0x7FUL << 25)
  142. /* PORTSC */
  143. #define PORTSC_SUSP BIT(7)
  144. #define PORTSC_HSP BIT(9)
  145. #define PORTSC_PTC (0x0FUL << 16)
  146. /* DEVLC */
  147. #define DEVLC_PSPD (0x03UL << 25)
  148. #define DEVLC_PSPD_HS (0x02UL << 25)
  149. /* USBMODE */
  150. #define USBMODE_CM (0x03UL << 0)
  151. #define USBMODE_CM_IDLE (0x00UL << 0)
  152. #define USBMODE_CM_DEVICE (0x02UL << 0)
  153. #define USBMODE_CM_HOST (0x03UL << 0)
  154. #define USBMODE_SLOM BIT(3)
  155. #define USBMODE_SDIS BIT(4)
  156. /* ENDPTCTRL */
  157. #define ENDPTCTRL_RXS BIT(0)
  158. #define ENDPTCTRL_RXT (0x03UL << 2)
  159. #define ENDPTCTRL_RXR BIT(6) /* reserved for port 0 */
  160. #define ENDPTCTRL_RXE BIT(7)
  161. #define ENDPTCTRL_TXS BIT(16)
  162. #define ENDPTCTRL_TXT (0x03UL << 18)
  163. #define ENDPTCTRL_TXR BIT(22) /* reserved for port 0 */
  164. #define ENDPTCTRL_TXE BIT(23)
  165. /******************************************************************************
  166. * LOGGING
  167. *****************************************************************************/
  168. #define ci13xxx_printk(level, format, args...) \
  169. do { \
  170. if (_udc == NULL) \
  171. printk(level "[%s] " format "\n", __func__, ## args); \
  172. else \
  173. dev_printk(level, _udc->gadget.dev.parent, \
  174. "[%s] " format "\n", __func__, ## args); \
  175. } while (0)
  176. #define err(format, args...) ci13xxx_printk(KERN_ERR, format, ## args)
  177. #define warn(format, args...) ci13xxx_printk(KERN_WARNING, format, ## args)
  178. #define info(format, args...) ci13xxx_printk(KERN_INFO, format, ## args)
  179. #ifdef TRACE
  180. #define trace(format, args...) ci13xxx_printk(KERN_DEBUG, format, ## args)
  181. #define dbg_trace(format, args...) dev_dbg(dev, format, ##args)
  182. #else
  183. #define trace(format, args...) do {} while (0)
  184. #define dbg_trace(format, args...) do {} while (0)
  185. #endif
  186. #endif /* _CI13XXX_h_ */