amd5536udc.h 16 KB

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