goku_udc.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. /*
  2. * Toshiba TC86C001 ("Goku-S") USB Device Controller driver
  3. *
  4. * Copyright (C) 2000-2002 Lineo
  5. * by Stuart Lynne, Tom Rushworth, and Bruce Balden
  6. * Copyright (C) 2002 Toshiba Corporation
  7. * Copyright (C) 2003 MontaVista Software (source@mvista.com)
  8. *
  9. * This file is licensed under the terms of the GNU General Public
  10. * License version 2. This program is licensed "as is" without any
  11. * warranty of any kind, whether express or implied.
  12. */
  13. /*
  14. * PCI BAR 0 points to these registers.
  15. */
  16. struct goku_udc_regs {
  17. /* irq management */
  18. u32 int_status; /* 0x000 */
  19. u32 int_enable;
  20. #define INT_SUSPEND 0x00001 /* or resume */
  21. #define INT_USBRESET 0x00002
  22. #define INT_ENDPOINT0 0x00004
  23. #define INT_SETUP 0x00008
  24. #define INT_STATUS 0x00010
  25. #define INT_STATUSNAK 0x00020
  26. #define INT_EPxDATASET(n) (0x00020 << (n)) /* 0 < n < 4 */
  27. # define INT_EP1DATASET 0x00040
  28. # define INT_EP2DATASET 0x00080
  29. # define INT_EP3DATASET 0x00100
  30. #define INT_EPnNAK(n) (0x00100 << (n)) /* 0 < n < 4 */
  31. # define INT_EP1NAK 0x00200
  32. # define INT_EP2NAK 0x00400
  33. # define INT_EP3NAK 0x00800
  34. #define INT_SOF 0x01000
  35. #define INT_ERR 0x02000
  36. #define INT_MSTWRSET 0x04000
  37. #define INT_MSTWREND 0x08000
  38. #define INT_MSTWRTMOUT 0x10000
  39. #define INT_MSTRDEND 0x20000
  40. #define INT_SYSERROR 0x40000
  41. #define INT_PWRDETECT 0x80000
  42. #define INT_DEVWIDE \
  43. (INT_PWRDETECT|INT_SYSERROR/*|INT_ERR*/|INT_USBRESET|INT_SUSPEND)
  44. #define INT_EP0 \
  45. (INT_SETUP|INT_ENDPOINT0/*|INT_STATUS*/|INT_STATUSNAK)
  46. u32 dma_master;
  47. #define MST_EOPB_DIS 0x0800
  48. #define MST_EOPB_ENA 0x0400
  49. #define MST_TIMEOUT_DIS 0x0200
  50. #define MST_TIMEOUT_ENA 0x0100
  51. #define MST_RD_EOPB 0x0080 /* write-only */
  52. #define MST_RD_RESET 0x0040
  53. #define MST_WR_RESET 0x0020
  54. #define MST_RD_ENA 0x0004 /* 1:start, 0:ignore */
  55. #define MST_WR_ENA 0x0002 /* 1:start, 0:ignore */
  56. #define MST_CONNECTION 0x0001 /* 0 for ep1out/ep2in */
  57. #define MST_R_BITS (MST_EOPB_DIS|MST_EOPB_ENA \
  58. |MST_RD_ENA|MST_RD_RESET)
  59. #define MST_W_BITS (MST_TIMEOUT_DIS|MST_TIMEOUT_ENA \
  60. |MST_WR_ENA|MST_WR_RESET)
  61. #define MST_RW_BITS (MST_R_BITS|MST_W_BITS \
  62. |MST_CONNECTION)
  63. /* these values assume (dma_master & MST_CONNECTION) == 0 */
  64. #define UDC_MSTWR_ENDPOINT 1
  65. #define UDC_MSTRD_ENDPOINT 2
  66. /* dma master write */
  67. u32 out_dma_start;
  68. u32 out_dma_end;
  69. u32 out_dma_current;
  70. /* dma master read */
  71. u32 in_dma_start;
  72. u32 in_dma_end;
  73. u32 in_dma_current;
  74. u32 power_detect;
  75. #define PW_DETECT 0x04
  76. #define PW_RESETB 0x02
  77. #define PW_PULLUP 0x01
  78. u8 _reserved0 [0x1d8];
  79. /* endpoint registers */
  80. u32 ep_fifo [4]; /* 0x200 */
  81. u8 _reserved1 [0x10];
  82. u32 ep_mode [4]; /* only 1-3 valid */
  83. u8 _reserved2 [0x10];
  84. u32 ep_status [4];
  85. #define EPxSTATUS_TOGGLE 0x40
  86. #define EPxSTATUS_SUSPEND 0x20
  87. #define EPxSTATUS_EP_MASK (0x07<<2)
  88. # define EPxSTATUS_EP_READY (0<<2)
  89. # define EPxSTATUS_EP_DATAIN (1<<2)
  90. # define EPxSTATUS_EP_FULL (2<<2)
  91. # define EPxSTATUS_EP_TX_ERR (3<<2)
  92. # define EPxSTATUS_EP_RX_ERR (4<<2)
  93. # define EPxSTATUS_EP_BUSY (5<<2)
  94. # define EPxSTATUS_EP_STALL (6<<2)
  95. # define EPxSTATUS_EP_INVALID (7<<2)
  96. #define EPxSTATUS_FIFO_DISABLE 0x02
  97. #define EPxSTATUS_STAGE_ERROR 0x01
  98. u8 _reserved3 [0x10];
  99. u32 EPxSizeLA[4];
  100. #define PACKET_ACTIVE (1<<7)
  101. #define DATASIZE 0x7f
  102. u8 _reserved3a [0x10];
  103. u32 EPxSizeLB[4]; /* only 1,2 valid */
  104. u8 _reserved3b [0x10];
  105. u32 EPxSizeHA[4]; /* only 1-3 valid */
  106. u8 _reserved3c [0x10];
  107. u32 EPxSizeHB[4]; /* only 1,2 valid */
  108. u8 _reserved4[0x30];
  109. /* SETUP packet contents */
  110. u32 bRequestType; /* 0x300 */
  111. u32 bRequest;
  112. u32 wValueL;
  113. u32 wValueH;
  114. u32 wIndexL;
  115. u32 wIndexH;
  116. u32 wLengthL;
  117. u32 wLengthH;
  118. /* command interaction/handshaking */
  119. u32 SetupRecv; /* 0x320 */
  120. u32 CurrConfig;
  121. u32 StdRequest;
  122. u32 Request;
  123. u32 DataSet;
  124. #define DATASET_A(epnum) (1<<(2*(epnum)))
  125. #define DATASET_B(epnum) (2<<(2*(epnum)))
  126. #define DATASET_AB(epnum) (3<<(2*(epnum)))
  127. u8 _reserved5[4];
  128. u32 UsbState;
  129. #define USBSTATE_CONFIGURED 0x04
  130. #define USBSTATE_ADDRESSED 0x02
  131. #define USBSTATE_DEFAULT 0x01
  132. u32 EOP;
  133. u32 Command; /* 0x340 */
  134. #define COMMAND_SETDATA0 2
  135. #define COMMAND_RESET 3
  136. #define COMMAND_STALL 4
  137. #define COMMAND_INVALID 5
  138. #define COMMAND_FIFO_DISABLE 7
  139. #define COMMAND_FIFO_ENABLE 8
  140. #define COMMAND_INIT_DESCRIPTOR 9
  141. #define COMMAND_FIFO_CLEAR 10 /* also stall */
  142. #define COMMAND_STALL_CLEAR 11
  143. #define COMMAND_EP(n) ((n) << 4)
  144. u32 EPxSingle;
  145. u8 _reserved6[4];
  146. u32 EPxBCS;
  147. u8 _reserved7[8];
  148. u32 IntControl;
  149. #define ICONTROL_STATUSNAK 1
  150. u8 _reserved8[4];
  151. u32 reqmode; // 0x360 standard request mode, low 8 bits
  152. #define G_REQMODE_SET_INTF (1<<7)
  153. #define G_REQMODE_GET_INTF (1<<6)
  154. #define G_REQMODE_SET_CONF (1<<5)
  155. #define G_REQMODE_GET_CONF (1<<4)
  156. #define G_REQMODE_GET_DESC (1<<3)
  157. #define G_REQMODE_SET_FEAT (1<<2)
  158. #define G_REQMODE_CLEAR_FEAT (1<<1)
  159. #define G_REQMODE_GET_STATUS (1<<0)
  160. u32 ReqMode;
  161. u8 _reserved9[0x18];
  162. u32 PortStatus; /* 0x380 */
  163. u8 _reserved10[8];
  164. u32 address;
  165. u32 buff_test;
  166. u8 _reserved11[4];
  167. u32 UsbReady;
  168. u8 _reserved12[4];
  169. u32 SetDescStall; /* 0x3a0 */
  170. u8 _reserved13[0x45c];
  171. /* hardware could handle limited GET_DESCRIPTOR duties */
  172. #define DESC_LEN 0x80
  173. u32 descriptors[DESC_LEN]; /* 0x800 */
  174. u8 _reserved14[0x600];
  175. } __attribute__ ((packed));
  176. #define MAX_FIFO_SIZE 64
  177. #define MAX_EP0_SIZE 8 /* ep0 fifo is bigger, though */
  178. /*-------------------------------------------------------------------------*/
  179. /* DRIVER DATA STRUCTURES and UTILITIES */
  180. struct goku_ep {
  181. struct usb_ep ep;
  182. struct goku_udc *dev;
  183. unsigned long irqs;
  184. unsigned num:8,
  185. dma:1,
  186. is_in:1,
  187. stopped:1;
  188. /* analogous to a host-side qh */
  189. struct list_head queue;
  190. u32 __iomem *reg_fifo;
  191. u32 __iomem *reg_mode;
  192. u32 __iomem *reg_status;
  193. };
  194. struct goku_request {
  195. struct usb_request req;
  196. struct list_head queue;
  197. unsigned mapped:1;
  198. };
  199. enum ep0state {
  200. EP0_DISCONNECT, /* no host */
  201. EP0_IDLE, /* between STATUS ack and SETUP report */
  202. EP0_IN, EP0_OUT, /* data stage */
  203. EP0_STATUS, /* status stage */
  204. EP0_STALL, /* data or status stages */
  205. EP0_SUSPEND, /* usb suspend */
  206. };
  207. struct goku_udc {
  208. /* each pci device provides one gadget, several endpoints */
  209. struct usb_gadget gadget;
  210. spinlock_t lock;
  211. struct goku_ep ep[4];
  212. struct usb_gadget_driver *driver;
  213. enum ep0state ep0state;
  214. unsigned got_irq:1,
  215. got_region:1,
  216. req_config:1,
  217. configured:1,
  218. enabled:1;
  219. /* pci state used to access those endpoints */
  220. struct pci_dev *pdev;
  221. struct goku_udc_regs __iomem *regs;
  222. u32 int_enable;
  223. /* statistics... */
  224. unsigned long irqs;
  225. };
  226. #define to_goku_udc(g) (container_of((g), struct goku_udc, gadget))
  227. /*-------------------------------------------------------------------------*/
  228. #define xprintk(dev,level,fmt,args...) \
  229. printk(level "%s %s: " fmt , driver_name , \
  230. pci_name(dev->pdev) , ## args)
  231. #ifdef DEBUG
  232. #define DBG(dev,fmt,args...) \
  233. xprintk(dev , KERN_DEBUG , fmt , ## args)
  234. #else
  235. #define DBG(dev,fmt,args...) \
  236. do { } while (0)
  237. #endif /* DEBUG */
  238. #ifdef VERBOSE
  239. #define VDBG DBG
  240. #else
  241. #define VDBG(dev,fmt,args...) \
  242. do { } while (0)
  243. #endif /* VERBOSE */
  244. #define ERROR(dev,fmt,args...) \
  245. xprintk(dev , KERN_ERR , fmt , ## args)
  246. #define WARNING(dev,fmt,args...) \
  247. xprintk(dev , KERN_WARNING , fmt , ## args)
  248. #define INFO(dev,fmt,args...) \
  249. xprintk(dev , KERN_INFO , fmt , ## args)