amd5536udc.h 18 KB

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