amd5536udc.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627
  1. /*
  2. * amd5536.h -- header for AMD 5536 UDC high/full speed USB device controller
  3. *
  4. * Copyright (C) 2007 AMD (http://www.amd.com)
  5. * Author: Thomas Dahlmann
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. #ifndef AMD5536UDC_H
  22. #define AMD5536UDC_H
  23. /* various constants */
  24. #define UDC_RDE_TIMER_SECONDS 1
  25. #define UDC_RDE_TIMER_DIV 10
  26. #define UDC_POLLSTALL_TIMER_USECONDS 500
  27. /* Hs AMD5536 chip rev. */
  28. #define UDC_HSA0_REV 1
  29. #define UDC_HSB1_REV 2
  30. /*
  31. * SETUP usb commands
  32. * needed, because some SETUP's are handled in hw, but must be passed to
  33. * gadget driver above
  34. * SET_CONFIG
  35. */
  36. #define UDC_SETCONFIG_DWORD0 0x00000900
  37. #define UDC_SETCONFIG_DWORD0_VALUE_MASK 0xffff0000
  38. #define UDC_SETCONFIG_DWORD0_VALUE_OFS 16
  39. #define UDC_SETCONFIG_DWORD1 0x00000000
  40. /* SET_INTERFACE */
  41. #define UDC_SETINTF_DWORD0 0x00000b00
  42. #define UDC_SETINTF_DWORD0_ALT_MASK 0xffff0000
  43. #define UDC_SETINTF_DWORD0_ALT_OFS 16
  44. #define UDC_SETINTF_DWORD1 0x00000000
  45. #define UDC_SETINTF_DWORD1_INTF_MASK 0x0000ffff
  46. #define UDC_SETINTF_DWORD1_INTF_OFS 0
  47. /* Mass storage reset */
  48. #define UDC_MSCRES_DWORD0 0x0000ff21
  49. #define UDC_MSCRES_DWORD1 0x00000000
  50. /* Global CSR's -------------------------------------------------------------*/
  51. #define UDC_CSR_ADDR 0x500
  52. /* EP NE bits */
  53. /* EP number */
  54. #define UDC_CSR_NE_NUM_MASK 0x0000000f
  55. #define UDC_CSR_NE_NUM_OFS 0
  56. /* EP direction */
  57. #define UDC_CSR_NE_DIR_MASK 0x00000010
  58. #define UDC_CSR_NE_DIR_OFS 4
  59. /* EP type */
  60. #define UDC_CSR_NE_TYPE_MASK 0x00000060
  61. #define UDC_CSR_NE_TYPE_OFS 5
  62. /* EP config number */
  63. #define UDC_CSR_NE_CFG_MASK 0x00000780
  64. #define UDC_CSR_NE_CFG_OFS 7
  65. /* EP interface number */
  66. #define UDC_CSR_NE_INTF_MASK 0x00007800
  67. #define UDC_CSR_NE_INTF_OFS 11
  68. /* EP alt setting */
  69. #define UDC_CSR_NE_ALT_MASK 0x00078000
  70. #define UDC_CSR_NE_ALT_OFS 15
  71. /* max pkt */
  72. #define UDC_CSR_NE_MAX_PKT_MASK 0x3ff80000
  73. #define UDC_CSR_NE_MAX_PKT_OFS 19
  74. /* Device Config Register ---------------------------------------------------*/
  75. #define UDC_DEVCFG_ADDR 0x400
  76. #define UDC_DEVCFG_SOFTRESET 31
  77. #define UDC_DEVCFG_HNPSFEN 30
  78. #define UDC_DEVCFG_DMARST 29
  79. #define UDC_DEVCFG_SET_DESC 18
  80. #define UDC_DEVCFG_CSR_PRG 17
  81. #define UDC_DEVCFG_STATUS 7
  82. #define UDC_DEVCFG_DIR 6
  83. #define UDC_DEVCFG_PI 5
  84. #define UDC_DEVCFG_SS 4
  85. #define UDC_DEVCFG_SP 3
  86. #define UDC_DEVCFG_RWKP 2
  87. #define UDC_DEVCFG_SPD_MASK 0x3
  88. #define UDC_DEVCFG_SPD_OFS 0
  89. #define UDC_DEVCFG_SPD_HS 0x0
  90. #define UDC_DEVCFG_SPD_FS 0x1
  91. #define UDC_DEVCFG_SPD_LS 0x2
  92. /*#define UDC_DEVCFG_SPD_FS 0x3*/
  93. /* Device Control Register --------------------------------------------------*/
  94. #define UDC_DEVCTL_ADDR 0x404
  95. #define UDC_DEVCTL_THLEN_MASK 0xff000000
  96. #define UDC_DEVCTL_THLEN_OFS 24
  97. #define UDC_DEVCTL_BRLEN_MASK 0x00ff0000
  98. #define UDC_DEVCTL_BRLEN_OFS 16
  99. #define UDC_DEVCTL_CSR_DONE 13
  100. #define UDC_DEVCTL_DEVNAK 12
  101. #define UDC_DEVCTL_SD 10
  102. #define UDC_DEVCTL_MODE 9
  103. #define UDC_DEVCTL_BREN 8
  104. #define UDC_DEVCTL_THE 7
  105. #define UDC_DEVCTL_BF 6
  106. #define UDC_DEVCTL_BE 5
  107. #define UDC_DEVCTL_DU 4
  108. #define UDC_DEVCTL_TDE 3
  109. #define UDC_DEVCTL_RDE 2
  110. #define UDC_DEVCTL_RES 0
  111. /* Device Status Register ---------------------------------------------------*/
  112. #define UDC_DEVSTS_ADDR 0x408
  113. #define UDC_DEVSTS_TS_MASK 0xfffc0000
  114. #define UDC_DEVSTS_TS_OFS 18
  115. #define UDC_DEVSTS_SESSVLD 17
  116. #define UDC_DEVSTS_PHY_ERROR 16
  117. #define UDC_DEVSTS_RXFIFO_EMPTY 15
  118. #define UDC_DEVSTS_ENUM_SPEED_MASK 0x00006000
  119. #define UDC_DEVSTS_ENUM_SPEED_OFS 13
  120. #define UDC_DEVSTS_ENUM_SPEED_FULL 1
  121. #define UDC_DEVSTS_ENUM_SPEED_HIGH 0
  122. #define UDC_DEVSTS_SUSP 12
  123. #define UDC_DEVSTS_ALT_MASK 0x00000f00
  124. #define UDC_DEVSTS_ALT_OFS 8
  125. #define UDC_DEVSTS_INTF_MASK 0x000000f0
  126. #define UDC_DEVSTS_INTF_OFS 4
  127. #define UDC_DEVSTS_CFG_MASK 0x0000000f
  128. #define UDC_DEVSTS_CFG_OFS 0
  129. /* Device Interrupt Register ------------------------------------------------*/
  130. #define UDC_DEVINT_ADDR 0x40c
  131. #define UDC_DEVINT_SVC 7
  132. #define UDC_DEVINT_ENUM 6
  133. #define UDC_DEVINT_SOF 5
  134. #define UDC_DEVINT_US 4
  135. #define UDC_DEVINT_UR 3
  136. #define UDC_DEVINT_ES 2
  137. #define UDC_DEVINT_SI 1
  138. #define UDC_DEVINT_SC 0
  139. /* Device Interrupt Mask Register -------------------------------------------*/
  140. #define UDC_DEVINT_MSK_ADDR 0x410
  141. #define UDC_DEVINT_MSK 0x7f
  142. /* Endpoint Interrupt Register ----------------------------------------------*/
  143. #define UDC_EPINT_ADDR 0x414
  144. #define UDC_EPINT_OUT_MASK 0xffff0000
  145. #define UDC_EPINT_OUT_OFS 16
  146. #define UDC_EPINT_IN_MASK 0x0000ffff
  147. #define UDC_EPINT_IN_OFS 0
  148. #define UDC_EPINT_IN_EP0 0
  149. #define UDC_EPINT_IN_EP1 1
  150. #define UDC_EPINT_IN_EP2 2
  151. #define UDC_EPINT_IN_EP3 3
  152. #define UDC_EPINT_OUT_EP0 16
  153. #define UDC_EPINT_OUT_EP1 17
  154. #define UDC_EPINT_OUT_EP2 18
  155. #define UDC_EPINT_OUT_EP3 19
  156. #define UDC_EPINT_EP0_ENABLE_MSK 0x001e001e
  157. /* Endpoint Interrupt Mask Register -----------------------------------------*/
  158. #define UDC_EPINT_MSK_ADDR 0x418
  159. #define UDC_EPINT_OUT_MSK_MASK 0xffff0000
  160. #define UDC_EPINT_OUT_MSK_OFS 16
  161. #define UDC_EPINT_IN_MSK_MASK 0x0000ffff
  162. #define UDC_EPINT_IN_MSK_OFS 0
  163. #define UDC_EPINT_MSK_DISABLE_ALL 0xffffffff
  164. /* mask non-EP0 endpoints */
  165. #define UDC_EPDATAINT_MSK_DISABLE 0xfffefffe
  166. /* mask all dev interrupts */
  167. #define UDC_DEV_MSK_DISABLE 0x7f
  168. /* Endpoint-specific CSR's --------------------------------------------------*/
  169. #define UDC_EPREGS_ADDR 0x0
  170. #define UDC_EPIN_REGS_ADDR 0x0
  171. #define UDC_EPOUT_REGS_ADDR 0x200
  172. #define UDC_EPCTL_ADDR 0x0
  173. #define UDC_EPCTL_RRDY 9
  174. #define UDC_EPCTL_CNAK 8
  175. #define UDC_EPCTL_SNAK 7
  176. #define UDC_EPCTL_NAK 6
  177. #define UDC_EPCTL_ET_MASK 0x00000030
  178. #define UDC_EPCTL_ET_OFS 4
  179. #define UDC_EPCTL_ET_CONTROL 0
  180. #define UDC_EPCTL_ET_ISO 1
  181. #define UDC_EPCTL_ET_BULK 2
  182. #define UDC_EPCTL_ET_INTERRUPT 3
  183. #define UDC_EPCTL_P 3
  184. #define UDC_EPCTL_SN 2
  185. #define UDC_EPCTL_F 1
  186. #define UDC_EPCTL_S 0
  187. /* Endpoint Status Registers ------------------------------------------------*/
  188. #define UDC_EPSTS_ADDR 0x4
  189. #define UDC_EPSTS_RX_PKT_SIZE_MASK 0x007ff800
  190. #define UDC_EPSTS_RX_PKT_SIZE_OFS 11
  191. #define UDC_EPSTS_TDC 10
  192. #define UDC_EPSTS_HE 9
  193. #define UDC_EPSTS_BNA 7
  194. #define UDC_EPSTS_IN 6
  195. #define UDC_EPSTS_OUT_MASK 0x00000030
  196. #define UDC_EPSTS_OUT_OFS 4
  197. #define UDC_EPSTS_OUT_DATA 1
  198. #define UDC_EPSTS_OUT_DATA_CLEAR 0x10
  199. #define UDC_EPSTS_OUT_SETUP 2
  200. #define UDC_EPSTS_OUT_SETUP_CLEAR 0x20
  201. #define UDC_EPSTS_OUT_CLEAR 0x30
  202. /* Endpoint Buffer Size IN/ Receive Packet Frame Number OUT Registers ------*/
  203. #define UDC_EPIN_BUFF_SIZE_ADDR 0x8
  204. #define UDC_EPOUT_FRAME_NUMBER_ADDR 0x8
  205. #define UDC_EPIN_BUFF_SIZE_MASK 0x0000ffff
  206. #define UDC_EPIN_BUFF_SIZE_OFS 0
  207. /* EP0in txfifo = 128 bytes*/
  208. #define UDC_EPIN0_BUFF_SIZE 32
  209. /* EP0in fullspeed txfifo = 128 bytes*/
  210. #define UDC_FS_EPIN0_BUFF_SIZE 32
  211. /* fifo size mult = fifo size / max packet */
  212. #define UDC_EPIN_BUFF_SIZE_MULT 2
  213. /* EPin data fifo size = 1024 bytes DOUBLE BUFFERING */
  214. #define UDC_EPIN_BUFF_SIZE 256
  215. /* EPin small INT data fifo size = 128 bytes */
  216. #define UDC_EPIN_SMALLINT_BUFF_SIZE 32
  217. /* EPin fullspeed data fifo size = 128 bytes DOUBLE BUFFERING */
  218. #define UDC_FS_EPIN_BUFF_SIZE 32
  219. #define UDC_EPOUT_FRAME_NUMBER_MASK 0x0000ffff
  220. #define UDC_EPOUT_FRAME_NUMBER_OFS 0
  221. /* Endpoint Buffer Size OUT/Max Packet Size Registers -----------------------*/
  222. #define UDC_EPOUT_BUFF_SIZE_ADDR 0x0c
  223. #define UDC_EP_MAX_PKT_SIZE_ADDR 0x0c
  224. #define UDC_EPOUT_BUFF_SIZE_MASK 0xffff0000
  225. #define UDC_EPOUT_BUFF_SIZE_OFS 16
  226. #define UDC_EP_MAX_PKT_SIZE_MASK 0x0000ffff
  227. #define UDC_EP_MAX_PKT_SIZE_OFS 0
  228. /* EP0in max packet size = 64 bytes */
  229. #define UDC_EP0IN_MAX_PKT_SIZE 64
  230. /* EP0out max packet size = 64 bytes */
  231. #define UDC_EP0OUT_MAX_PKT_SIZE 64
  232. /* EP0in fullspeed max packet size = 64 bytes */
  233. #define UDC_FS_EP0IN_MAX_PKT_SIZE 64
  234. /* EP0out fullspeed max packet size = 64 bytes */
  235. #define UDC_FS_EP0OUT_MAX_PKT_SIZE 64
  236. /*
  237. * Endpoint dma descriptors ------------------------------------------------
  238. *
  239. * Setup data, Status dword
  240. */
  241. #define UDC_DMA_STP_STS_CFG_MASK 0x0fff0000
  242. #define UDC_DMA_STP_STS_CFG_OFS 16
  243. #define UDC_DMA_STP_STS_CFG_ALT_MASK 0x000f0000
  244. #define UDC_DMA_STP_STS_CFG_ALT_OFS 16
  245. #define UDC_DMA_STP_STS_CFG_INTF_MASK 0x00f00000
  246. #define UDC_DMA_STP_STS_CFG_INTF_OFS 20
  247. #define UDC_DMA_STP_STS_CFG_NUM_MASK 0x0f000000
  248. #define UDC_DMA_STP_STS_CFG_NUM_OFS 24
  249. #define UDC_DMA_STP_STS_RX_MASK 0x30000000
  250. #define UDC_DMA_STP_STS_RX_OFS 28
  251. #define UDC_DMA_STP_STS_BS_MASK 0xc0000000
  252. #define UDC_DMA_STP_STS_BS_OFS 30
  253. #define UDC_DMA_STP_STS_BS_HOST_READY 0
  254. #define UDC_DMA_STP_STS_BS_DMA_BUSY 1
  255. #define UDC_DMA_STP_STS_BS_DMA_DONE 2
  256. #define UDC_DMA_STP_STS_BS_HOST_BUSY 3
  257. /* IN data, Status dword */
  258. #define UDC_DMA_IN_STS_TXBYTES_MASK 0x0000ffff
  259. #define UDC_DMA_IN_STS_TXBYTES_OFS 0
  260. #define UDC_DMA_IN_STS_FRAMENUM_MASK 0x07ff0000
  261. #define UDC_DMA_IN_STS_FRAMENUM_OFS 0
  262. #define UDC_DMA_IN_STS_L 27
  263. #define UDC_DMA_IN_STS_TX_MASK 0x30000000
  264. #define UDC_DMA_IN_STS_TX_OFS 28
  265. #define UDC_DMA_IN_STS_BS_MASK 0xc0000000
  266. #define UDC_DMA_IN_STS_BS_OFS 30
  267. #define UDC_DMA_IN_STS_BS_HOST_READY 0
  268. #define UDC_DMA_IN_STS_BS_DMA_BUSY 1
  269. #define UDC_DMA_IN_STS_BS_DMA_DONE 2
  270. #define UDC_DMA_IN_STS_BS_HOST_BUSY 3
  271. /* OUT data, Status dword */
  272. #define UDC_DMA_OUT_STS_RXBYTES_MASK 0x0000ffff
  273. #define UDC_DMA_OUT_STS_RXBYTES_OFS 0
  274. #define UDC_DMA_OUT_STS_FRAMENUM_MASK 0x07ff0000
  275. #define UDC_DMA_OUT_STS_FRAMENUM_OFS 0
  276. #define UDC_DMA_OUT_STS_L 27
  277. #define UDC_DMA_OUT_STS_RX_MASK 0x30000000
  278. #define UDC_DMA_OUT_STS_RX_OFS 28
  279. #define UDC_DMA_OUT_STS_BS_MASK 0xc0000000
  280. #define UDC_DMA_OUT_STS_BS_OFS 30
  281. #define UDC_DMA_OUT_STS_BS_HOST_READY 0
  282. #define UDC_DMA_OUT_STS_BS_DMA_BUSY 1
  283. #define UDC_DMA_OUT_STS_BS_DMA_DONE 2
  284. #define UDC_DMA_OUT_STS_BS_HOST_BUSY 3
  285. /* max ep0in packet */
  286. #define UDC_EP0IN_MAXPACKET 1000
  287. /* max dma packet */
  288. #define UDC_DMA_MAXPACKET 65536
  289. /* un-usable DMA address */
  290. #define DMA_DONT_USE (~(dma_addr_t) 0 )
  291. /* other Endpoint register addresses and values-----------------------------*/
  292. #define UDC_EP_SUBPTR_ADDR 0x10
  293. #define UDC_EP_DESPTR_ADDR 0x14
  294. #define UDC_EP_WRITE_CONFIRM_ADDR 0x1c
  295. /* EP number as layouted in AHB space */
  296. #define UDC_EP_NUM 32
  297. #define UDC_EPIN_NUM 16
  298. #define UDC_EPIN_NUM_USED 5
  299. #define UDC_EPOUT_NUM 16
  300. /* EP number of EP's really used = EP0 + 8 data EP's */
  301. #define UDC_USED_EP_NUM 9
  302. /* UDC CSR regs are aligned but AHB regs not - offset for OUT EP's */
  303. #define UDC_CSR_EP_OUT_IX_OFS 12
  304. #define UDC_EP0OUT_IX 16
  305. #define UDC_EP0IN_IX 0
  306. /* Rx fifo address and size = 1k -------------------------------------------*/
  307. #define UDC_RXFIFO_ADDR 0x800
  308. #define UDC_RXFIFO_SIZE 0x400
  309. /* Tx fifo address and size = 1.5k -----------------------------------------*/
  310. #define UDC_TXFIFO_ADDR 0xc00
  311. #define UDC_TXFIFO_SIZE 0x600
  312. /* default data endpoints --------------------------------------------------*/
  313. #define UDC_EPIN_STATUS_IX 1
  314. #define UDC_EPIN_IX 2
  315. #define UDC_EPOUT_IX 18
  316. /* general constants -------------------------------------------------------*/
  317. #define UDC_DWORD_BYTES 4
  318. #define UDC_BITS_PER_BYTE_SHIFT 3
  319. #define UDC_BYTE_MASK 0xff
  320. #define UDC_BITS_PER_BYTE 8
  321. /*---------------------------------------------------------------------------*/
  322. /* UDC CSR's */
  323. struct udc_csrs {
  324. /* sca - setup command address */
  325. u32 sca;
  326. /* ep ne's */
  327. u32 ne[UDC_USED_EP_NUM];
  328. } __attribute__ ((packed));
  329. /* AHB subsystem CSR registers */
  330. struct udc_regs {
  331. /* device configuration */
  332. u32 cfg;
  333. /* device control */
  334. u32 ctl;
  335. /* device status */
  336. u32 sts;
  337. /* device interrupt */
  338. u32 irqsts;
  339. /* device interrupt mask */
  340. u32 irqmsk;
  341. /* endpoint interrupt */
  342. u32 ep_irqsts;
  343. /* endpoint interrupt mask */
  344. u32 ep_irqmsk;
  345. } __attribute__ ((packed));
  346. /* endpoint specific registers */
  347. struct udc_ep_regs {
  348. /* endpoint control */
  349. u32 ctl;
  350. /* endpoint status */
  351. u32 sts;
  352. /* endpoint buffer size in/ receive packet frame number out */
  353. u32 bufin_framenum;
  354. /* endpoint buffer size out/max packet size */
  355. u32 bufout_maxpkt;
  356. /* endpoint setup buffer pointer */
  357. u32 subptr;
  358. /* endpoint data descriptor pointer */
  359. u32 desptr;
  360. /* reserverd */
  361. u32 reserved;
  362. /* write/read confirmation */
  363. u32 confirm;
  364. } __attribute__ ((packed));
  365. /* control data DMA desc */
  366. struct udc_stp_dma {
  367. /* status quadlet */
  368. u32 status;
  369. /* reserved */
  370. u32 _reserved;
  371. /* first setup word */
  372. u32 data12;
  373. /* second setup word */
  374. u32 data34;
  375. } __attribute__ ((aligned (16)));
  376. /* normal data DMA desc */
  377. struct udc_data_dma {
  378. /* status quadlet */
  379. u32 status;
  380. /* reserved */
  381. u32 _reserved;
  382. /* buffer pointer */
  383. u32 bufptr;
  384. /* next descriptor pointer */
  385. u32 next;
  386. } __attribute__ ((aligned (16)));
  387. /* request packet */
  388. struct udc_request {
  389. /* embedded gadget ep */
  390. struct usb_request req;
  391. /* flags */
  392. unsigned dma_going : 1,
  393. dma_mapping : 1,
  394. dma_done : 1;
  395. /* phys. address */
  396. dma_addr_t td_phys;
  397. /* first dma desc. of chain */
  398. struct udc_data_dma *td_data;
  399. /* last dma desc. of chain */
  400. struct udc_data_dma *td_data_last;
  401. struct list_head queue;
  402. /* chain length */
  403. unsigned chain_len;
  404. };
  405. /* UDC specific endpoint parameters */
  406. struct udc_ep {
  407. struct usb_ep ep;
  408. struct udc_ep_regs __iomem *regs;
  409. u32 __iomem *txfifo;
  410. u32 __iomem *dma;
  411. dma_addr_t td_phys;
  412. dma_addr_t td_stp_dma;
  413. struct udc_stp_dma *td_stp;
  414. struct udc_data_dma *td;
  415. /* temp request */
  416. struct udc_request *req;
  417. unsigned req_used;
  418. unsigned req_completed;
  419. /* dummy DMA desc for BNA dummy */
  420. struct udc_request *bna_dummy_req;
  421. unsigned bna_occurred;
  422. /* NAK state */
  423. unsigned naking;
  424. struct udc *dev;
  425. /* queue for requests */
  426. struct list_head queue;
  427. const struct usb_endpoint_descriptor *desc;
  428. unsigned halted;
  429. unsigned cancel_transfer;
  430. unsigned num : 5,
  431. fifo_depth : 14,
  432. in : 1;
  433. };
  434. /* device struct */
  435. struct udc {
  436. struct usb_gadget gadget;
  437. spinlock_t lock; /* protects all state */
  438. /* all endpoints */
  439. struct udc_ep ep[UDC_EP_NUM];
  440. struct usb_gadget_driver *driver;
  441. /* operational flags */
  442. unsigned active : 1,
  443. stall_ep0in : 1,
  444. waiting_zlp_ack_ep0in : 1,
  445. set_cfg_not_acked : 1,
  446. irq_registered : 1,
  447. data_ep_enabled : 1,
  448. data_ep_queued : 1,
  449. mem_region : 1,
  450. sys_suspended : 1,
  451. connected;
  452. u16 chiprev;
  453. /* registers */
  454. struct pci_dev *pdev;
  455. struct udc_csrs __iomem *csr;
  456. struct udc_regs __iomem *regs;
  457. struct udc_ep_regs __iomem *ep_regs;
  458. u32 __iomem *rxfifo;
  459. u32 __iomem *txfifo;
  460. /* DMA desc pools */
  461. struct pci_pool *data_requests;
  462. struct pci_pool *stp_requests;
  463. /* device data */
  464. unsigned long phys_addr;
  465. void __iomem *virt_addr;
  466. unsigned irq;
  467. /* states */
  468. u16 cur_config;
  469. u16 cur_intf;
  470. u16 cur_alt;
  471. };
  472. /* setup request data */
  473. union udc_setup_data {
  474. u32 data[2];
  475. struct usb_ctrlrequest request;
  476. };
  477. /*
  478. *---------------------------------------------------------------------------
  479. * SET and GET bitfields in u32 values
  480. * via constants for mask/offset:
  481. * <bit_field_stub_name> is the text between
  482. * UDC_ and _MASK|_OFS of appropriate
  483. * constant
  484. *
  485. * set bitfield value in u32 u32Val
  486. */
  487. #define AMD_ADDBITS(u32Val, bitfield_val, bitfield_stub_name) \
  488. (((u32Val) & (((u32) ~((u32) bitfield_stub_name##_MASK)))) \
  489. | (((bitfield_val) << ((u32) bitfield_stub_name##_OFS)) \
  490. & ((u32) bitfield_stub_name##_MASK)))
  491. /*
  492. * set bitfield value in zero-initialized u32 u32Val
  493. * => bitfield bits in u32Val are all zero
  494. */
  495. #define AMD_INIT_SETBITS(u32Val, bitfield_val, bitfield_stub_name) \
  496. ((u32Val) \
  497. | (((bitfield_val) << ((u32) bitfield_stub_name##_OFS)) \
  498. & ((u32) bitfield_stub_name##_MASK)))
  499. /* get bitfield value from u32 u32Val */
  500. #define AMD_GETBITS(u32Val, bitfield_stub_name) \
  501. ((u32Val & ((u32) bitfield_stub_name##_MASK)) \
  502. >> ((u32) bitfield_stub_name##_OFS))
  503. /* SET and GET bits in u32 values ------------------------------------------*/
  504. #define AMD_BIT(bit_stub_name) (1 << bit_stub_name)
  505. #define AMD_UNMASK_BIT(bit_stub_name) (~AMD_BIT(bit_stub_name))
  506. #define AMD_CLEAR_BIT(bit_stub_name) (~AMD_BIT(bit_stub_name))
  507. /* debug macros ------------------------------------------------------------*/
  508. #define DBG(udc , args...) dev_dbg(&(udc)->pdev->dev, args)
  509. #ifdef UDC_VERBOSE
  510. #define VDBG DBG
  511. #else
  512. #define VDBG(udc , args...) do {} while (0)
  513. #endif
  514. #endif /* #ifdef AMD5536UDC_H */