fusb300_udc.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. /*
  2. * Fusb300 UDC (USB gadget)
  3. *
  4. * Copyright (C) 2010 Faraday Technology Corp.
  5. *
  6. * Author : Yuan-hsin Chen <yhchen@faraday-tech.com>
  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 as published by
  10. * the Free Software Foundation; version 2 of the License.
  11. */
  12. #ifndef __FUSB300_UDC_H__
  13. #define __FUSB300_UDC_H__
  14. #include <linux/kernel.h>
  15. #define FUSB300_OFFSET_GCR 0x00
  16. #define FUSB300_OFFSET_GTM 0x04
  17. #define FUSB300_OFFSET_DAR 0x08
  18. #define FUSB300_OFFSET_CSR 0x0C
  19. #define FUSB300_OFFSET_CXPORT 0x10
  20. #define FUSB300_OFFSET_EPSET0(n) (0x20 + (n - 1) * 0x30)
  21. #define FUSB300_OFFSET_EPSET1(n) (0x24 + (n - 1) * 0x30)
  22. #define FUSB300_OFFSET_EPSET2(n) (0x28 + (n - 1) * 0x30)
  23. #define FUSB300_OFFSET_EPFFR(n) (0x2c + (n - 1) * 0x30)
  24. #define FUSB300_OFFSET_EPSTRID(n) (0x40 + (n - 1) * 0x30)
  25. #define FUSB300_OFFSET_HSPTM 0x300
  26. #define FUSB300_OFFSET_HSCR 0x304
  27. #define FUSB300_OFFSET_SSCR0 0x308
  28. #define FUSB300_OFFSET_SSCR1 0x30C
  29. #define FUSB300_OFFSET_TT 0x310
  30. #define FUSB300_OFFSET_DEVNOTF 0x314
  31. #define FUSB300_OFFSET_DNC1 0x318
  32. #define FUSB300_OFFSET_CS 0x31C
  33. #define FUSB300_OFFSET_SOF 0x324
  34. #define FUSB300_OFFSET_EFCS 0x328
  35. #define FUSB300_OFFSET_IGR0 0x400
  36. #define FUSB300_OFFSET_IGR1 0x404
  37. #define FUSB300_OFFSET_IGR2 0x408
  38. #define FUSB300_OFFSET_IGR3 0x40C
  39. #define FUSB300_OFFSET_IGR4 0x410
  40. #define FUSB300_OFFSET_IGR5 0x414
  41. #define FUSB300_OFFSET_IGER0 0x420
  42. #define FUSB300_OFFSET_IGER1 0x424
  43. #define FUSB300_OFFSET_IGER2 0x428
  44. #define FUSB300_OFFSET_IGER3 0x42C
  45. #define FUSB300_OFFSET_IGER4 0x430
  46. #define FUSB300_OFFSET_IGER5 0x434
  47. #define FUSB300_OFFSET_DMAHMER 0x500
  48. #define FUSB300_OFFSET_EPPRDRDY 0x504
  49. #define FUSB300_OFFSET_DMAEPMR 0x508
  50. #define FUSB300_OFFSET_DMAENR 0x50C
  51. #define FUSB300_OFFSET_DMAAPR 0x510
  52. #define FUSB300_OFFSET_AHBCR 0x514
  53. #define FUSB300_OFFSET_EPPRD_W0(n) (0x520 + (n - 1) * 0x10)
  54. #define FUSB300_OFFSET_EPPRD_W1(n) (0x524 + (n - 1) * 0x10)
  55. #define FUSB300_OFFSET_EPPRD_W2(n) (0x528 + (n - 1) * 0x10)
  56. #define FUSB300_OFFSET_EPRD_PTR(n) (0x52C + (n - 1) * 0x10)
  57. #define FUSB300_OFFSET_BUFDBG_START 0x800
  58. #define FUSB300_OFFSET_BUFDBG_END 0xBFC
  59. #define FUSB300_OFFSET_EPPORT(n) (0x1010 + (n - 1) * 0x10)
  60. /*
  61. * * Global Control Register (offset = 000H)
  62. * */
  63. #define FUSB300_GCR_SF_RST (1 << 8)
  64. #define FUSB300_GCR_VBUS_STATUS (1 << 7)
  65. #define FUSB300_GCR_FORCE_HS_SUSP (1 << 6)
  66. #define FUSB300_GCR_SYNC_FIFO1_CLR (1 << 5)
  67. #define FUSB300_GCR_SYNC_FIFO0_CLR (1 << 4)
  68. #define FUSB300_GCR_FIFOCLR (1 << 3)
  69. #define FUSB300_GCR_GLINTEN (1 << 2)
  70. #define FUSB300_GCR_DEVEN_FS 0x3
  71. #define FUSB300_GCR_DEVEN_HS 0x2
  72. #define FUSB300_GCR_DEVEN_SS 0x1
  73. #define FUSB300_GCR_DEVDIS 0x0
  74. #define FUSB300_GCR_DEVEN_MSK 0x3
  75. /*
  76. * *Global Test Mode (offset = 004H)
  77. * */
  78. #define FUSB300_GTM_TST_DIS_SOFGEN (1 << 16)
  79. #define FUSB300_GTM_TST_CUR_EP_ENTRY(n) ((n & 0xF) << 12)
  80. #define FUSB300_GTM_TST_EP_ENTRY(n) ((n & 0xF) << 8)
  81. #define FUSB300_GTM_TST_EP_NUM(n) ((n & 0xF) << 4)
  82. #define FUSB300_GTM_TST_FIFO_DEG (1 << 1)
  83. #define FUSB300_GTM_TSTMODE (1 << 0)
  84. /*
  85. * * Device Address Register (offset = 008H)
  86. * */
  87. #define FUSB300_DAR_SETCONFG (1 << 7)
  88. #define FUSB300_DAR_DRVADDR(x) (x & 0x7F)
  89. #define FUSB300_DAR_DRVADDR_MSK 0x7F
  90. /*
  91. * *Control Transfer Configuration and Status Register
  92. * (CX_Config_Status, offset = 00CH)
  93. * */
  94. #define FUSB300_CSR_LEN(x) ((x & 0xFFFF) << 8)
  95. #define FUSB300_CSR_LEN_MSK (0xFFFF << 8)
  96. #define FUSB300_CSR_EMP (1 << 4)
  97. #define FUSB300_CSR_FUL (1 << 3)
  98. #define FUSB300_CSR_CLR (1 << 2)
  99. #define FUSB300_CSR_STL (1 << 1)
  100. #define FUSB300_CSR_DONE (1 << 0)
  101. /*
  102. * * EPn Setting 0 (EPn_SET0, offset = 020H+(n-1)*30H, n=1~15 )
  103. * */
  104. #define FUSB300_EPSET0_STL_CLR (1 << 3)
  105. #define FUSB300_EPSET0_CLRSEQNUM (1 << 2)
  106. #define FUSB300_EPSET0_STL (1 << 0)
  107. /*
  108. * * EPn Setting 1 (EPn_SET1, offset = 024H+(n-1)*30H, n=1~15)
  109. * */
  110. #define FUSB300_EPSET1_START_ENTRY(x) ((x & 0xFF) << 24)
  111. #define FUSB300_EPSET1_START_ENTRY_MSK (0xFF << 24)
  112. #define FUSB300_EPSET1_FIFOENTRY(x) ((x & 0x1F) << 12)
  113. #define FUSB300_EPSET1_FIFOENTRY_MSK (0x1f << 12)
  114. #define FUSB300_EPSET1_INTERVAL(x) ((x & 0x7) << 6)
  115. #define FUSB300_EPSET1_BWNUM(x) ((x & 0x3) << 4)
  116. #define FUSB300_EPSET1_TYPEISO (1 << 2)
  117. #define FUSB300_EPSET1_TYPEBLK (2 << 2)
  118. #define FUSB300_EPSET1_TYPEINT (3 << 2)
  119. #define FUSB300_EPSET1_TYPE(x) ((x & 0x3) << 2)
  120. #define FUSB300_EPSET1_TYPE_MSK (0x3 << 2)
  121. #define FUSB300_EPSET1_DIROUT (0 << 1)
  122. #define FUSB300_EPSET1_DIRIN (1 << 1)
  123. #define FUSB300_EPSET1_DIR(x) ((x & 0x1) << 1)
  124. #define FUSB300_EPSET1_DIRIN (1 << 1)
  125. #define FUSB300_EPSET1_DIR_MSK ((0x1) << 1)
  126. #define FUSB300_EPSET1_ACTDIS 0
  127. #define FUSB300_EPSET1_ACTEN 1
  128. /*
  129. * *EPn Setting 2 (EPn_SET2, offset = 028H+(n-1)*30H, n=1~15)
  130. * */
  131. #define FUSB300_EPSET2_ADDROFS(x) ((x & 0x7FFF) << 16)
  132. #define FUSB300_EPSET2_ADDROFS_MSK (0x7fff << 16)
  133. #define FUSB300_EPSET2_MPS(x) (x & 0x7FF)
  134. #define FUSB300_EPSET2_MPS_MSK 0x7FF
  135. /*
  136. * * EPn FIFO Register (offset = 2cH+(n-1)*30H)
  137. * */
  138. #define FUSB300_FFR_RST (1 << 31)
  139. #define FUSB300_FF_FUL (1 << 30)
  140. #define FUSB300_FF_EMPTY (1 << 29)
  141. #define FUSB300_FFR_BYCNT 0x1FFFF
  142. /*
  143. * *EPn Stream ID (EPn_STR_ID, offset = 040H+(n-1)*30H, n=1~15)
  144. * */
  145. #define FUSB300_STRID_STREN (1 << 16)
  146. #define FUSB300_STRID_STRID(x) (x & 0xFFFF)
  147. /*
  148. * *HS PHY Test Mode (offset = 300H)
  149. * */
  150. #define FUSB300_HSPTM_TSTPKDONE (1 << 4)
  151. #define FUSB300_HSPTM_TSTPKT (1 << 3)
  152. #define FUSB300_HSPTM_TSTSET0NAK (1 << 2)
  153. #define FUSB300_HSPTM_TSTKSTA (1 << 1)
  154. #define FUSB300_HSPTM_TSTJSTA (1 << 0)
  155. /*
  156. * *HS Control Register (offset = 304H)
  157. * */
  158. #define FUSB300_HSCR_HS_LPM_PERMIT (1 << 8)
  159. #define FUSB300_HSCR_HS_LPM_RMWKUP (1 << 7)
  160. #define FUSB300_HSCR_CAP_LPM_RMWKUP (1 << 6)
  161. #define FUSB300_HSCR_HS_GOSUSP (1 << 5)
  162. #define FUSB300_HSCR_HS_GORMWKU (1 << 4)
  163. #define FUSB300_HSCR_CAP_RMWKUP (1 << 3)
  164. #define FUSB300_HSCR_IDLECNT_0MS 0
  165. #define FUSB300_HSCR_IDLECNT_1MS 1
  166. #define FUSB300_HSCR_IDLECNT_2MS 2
  167. #define FUSB300_HSCR_IDLECNT_3MS 3
  168. #define FUSB300_HSCR_IDLECNT_4MS 4
  169. #define FUSB300_HSCR_IDLECNT_5MS 5
  170. #define FUSB300_HSCR_IDLECNT_6MS 6
  171. #define FUSB300_HSCR_IDLECNT_7MS 7
  172. /*
  173. * * SS Controller Register 0 (offset = 308H)
  174. * */
  175. #define FUSB300_SSCR0_MAX_INTERVAL(x) ((x & 0x7) << 4)
  176. #define FUSB300_SSCR0_U2_FUN_EN (1 << 1)
  177. #define FUSB300_SSCR0_U1_FUN_EN (1 << 0)
  178. /*
  179. * * SS Controller Register 1 (offset = 30CH)
  180. * */
  181. #define FUSB300_SSCR1_GO_U3_DONE (1 << 8)
  182. #define FUSB300_SSCR1_TXDEEMPH_LEVEL (1 << 7)
  183. #define FUSB300_SSCR1_DIS_SCRMB (1 << 6)
  184. #define FUSB300_SSCR1_FORCE_RECOVERY (1 << 5)
  185. #define FUSB300_SSCR1_U3_WAKEUP_EN (1 << 4)
  186. #define FUSB300_SSCR1_U2_EXIT_EN (1 << 3)
  187. #define FUSB300_SSCR1_U1_EXIT_EN (1 << 2)
  188. #define FUSB300_SSCR1_U2_ENTRY_EN (1 << 1)
  189. #define FUSB300_SSCR1_U1_ENTRY_EN (1 << 0)
  190. /*
  191. * *SS Controller Register 2 (offset = 310H)
  192. * */
  193. #define FUSB300_SSCR2_SS_TX_SWING (1 << 25)
  194. #define FUSB300_SSCR2_FORCE_LINKPM_ACCEPT (1 << 24)
  195. #define FUSB300_SSCR2_U2_INACT_TIMEOUT(x) ((x & 0xFF) << 16)
  196. #define FUSB300_SSCR2_U1TIMEOUT(x) ((x & 0xFF) << 8)
  197. #define FUSB300_SSCR2_U2TIMEOUT(x) (x & 0xFF)
  198. /*
  199. * *SS Device Notification Control (DEV_NOTF, offset = 314H)
  200. * */
  201. #define FUSB300_DEVNOTF_CONTEXT0(x) ((x & 0xFFFFFF) << 8)
  202. #define FUSB300_DEVNOTF_TYPE_DIS 0
  203. #define FUSB300_DEVNOTF_TYPE_FUNCWAKE 1
  204. #define FUSB300_DEVNOTF_TYPE_LTM 2
  205. #define FUSB300_DEVNOTF_TYPE_BUSINT_ADJMSG 3
  206. /*
  207. * *BFM Arbiter Priority Register (BFM_ARB offset = 31CH)
  208. * */
  209. #define FUSB300_BFMARB_ARB_M1 (1 << 3)
  210. #define FUSB300_BFMARB_ARB_M0 (1 << 2)
  211. #define FUSB300_BFMARB_ARB_S1 (1 << 1)
  212. #define FUSB300_BFMARB_ARB_S0 1
  213. /*
  214. * *Vendor Specific IO Control Register (offset = 320H)
  215. * */
  216. #define FUSB300_VSIC_VCTLOAD_N (1 << 8)
  217. #define FUSB300_VSIC_VCTL(x) (x & 0x3F)
  218. /*
  219. * *SOF Mask Timer (offset = 324H)
  220. * */
  221. #define FUSB300_SOF_MASK_TIMER_HS 0x044c
  222. #define FUSB300_SOF_MASK_TIMER_FS 0x2710
  223. /*
  224. * *Error Flag and Control Status (offset = 328H)
  225. * */
  226. #define FUSB300_EFCS_PM_STATE_U3 3
  227. #define FUSB300_EFCS_PM_STATE_U2 2
  228. #define FUSB300_EFCS_PM_STATE_U1 1
  229. #define FUSB300_EFCS_PM_STATE_U0 0
  230. /*
  231. * *Interrupt Group 0 Register (offset = 400H)
  232. * */
  233. #define FUSB300_IGR0_EP15_PRD_INT (1 << 31)
  234. #define FUSB300_IGR0_EP14_PRD_INT (1 << 30)
  235. #define FUSB300_IGR0_EP13_PRD_INT (1 << 29)
  236. #define FUSB300_IGR0_EP12_PRD_INT (1 << 28)
  237. #define FUSB300_IGR0_EP11_PRD_INT (1 << 27)
  238. #define FUSB300_IGR0_EP10_PRD_INT (1 << 26)
  239. #define FUSB300_IGR0_EP9_PRD_INT (1 << 25)
  240. #define FUSB300_IGR0_EP8_PRD_INT (1 << 24)
  241. #define FUSB300_IGR0_EP7_PRD_INT (1 << 23)
  242. #define FUSB300_IGR0_EP6_PRD_INT (1 << 22)
  243. #define FUSB300_IGR0_EP5_PRD_INT (1 << 21)
  244. #define FUSB300_IGR0_EP4_PRD_INT (1 << 20)
  245. #define FUSB300_IGR0_EP3_PRD_INT (1 << 19)
  246. #define FUSB300_IGR0_EP2_PRD_INT (1 << 18)
  247. #define FUSB300_IGR0_EP1_PRD_INT (1 << 17)
  248. #define FUSB300_IGR0_EPn_PRD_INT(n) (1 << (n + 16))
  249. #define FUSB300_IGR0_EP15_FIFO_INT (1 << 15)
  250. #define FUSB300_IGR0_EP14_FIFO_INT (1 << 14)
  251. #define FUSB300_IGR0_EP13_FIFO_INT (1 << 13)
  252. #define FUSB300_IGR0_EP12_FIFO_INT (1 << 12)
  253. #define FUSB300_IGR0_EP11_FIFO_INT (1 << 11)
  254. #define FUSB300_IGR0_EP10_FIFO_INT (1 << 10)
  255. #define FUSB300_IGR0_EP9_FIFO_INT (1 << 9)
  256. #define FUSB300_IGR0_EP8_FIFO_INT (1 << 8)
  257. #define FUSB300_IGR0_EP7_FIFO_INT (1 << 7)
  258. #define FUSB300_IGR0_EP6_FIFO_INT (1 << 6)
  259. #define FUSB300_IGR0_EP5_FIFO_INT (1 << 5)
  260. #define FUSB300_IGR0_EP4_FIFO_INT (1 << 4)
  261. #define FUSB300_IGR0_EP3_FIFO_INT (1 << 3)
  262. #define FUSB300_IGR0_EP2_FIFO_INT (1 << 2)
  263. #define FUSB300_IGR0_EP1_FIFO_INT (1 << 1)
  264. #define FUSB300_IGR0_EPn_FIFO_INT(n) (1 << n)
  265. /*
  266. * *Interrupt Group 1 Register (offset = 404H)
  267. * */
  268. #define FUSB300_IGR1_INTGRP5 (1 << 31)
  269. #define FUSB300_IGR1_VBUS_CHG_INT (1 << 30)
  270. #define FUSB300_IGR1_SYNF1_EMPTY_INT (1 << 29)
  271. #define FUSB300_IGR1_SYNF0_EMPTY_INT (1 << 28)
  272. #define FUSB300_IGR1_U3_EXIT_FAIL_INT (1 << 27)
  273. #define FUSB300_IGR1_U2_EXIT_FAIL_INT (1 << 26)
  274. #define FUSB300_IGR1_U1_EXIT_FAIL_INT (1 << 25)
  275. #define FUSB300_IGR1_U2_ENTRY_FAIL_INT (1 << 24)
  276. #define FUSB300_IGR1_U1_ENTRY_FAIL_INT (1 << 23)
  277. #define FUSB300_IGR1_U3_EXIT_INT (1 << 22)
  278. #define FUSB300_IGR1_U2_EXIT_INT (1 << 21)
  279. #define FUSB300_IGR1_U1_EXIT_INT (1 << 20)
  280. #define FUSB300_IGR1_U3_ENTRY_INT (1 << 19)
  281. #define FUSB300_IGR1_U2_ENTRY_INT (1 << 18)
  282. #define FUSB300_IGR1_U1_ENTRY_INT (1 << 17)
  283. #define FUSB300_IGR1_HOT_RST_INT (1 << 16)
  284. #define FUSB300_IGR1_WARM_RST_INT (1 << 15)
  285. #define FUSB300_IGR1_RESM_INT (1 << 14)
  286. #define FUSB300_IGR1_SUSP_INT (1 << 13)
  287. #define FUSB300_IGR1_HS_LPM_INT (1 << 12)
  288. #define FUSB300_IGR1_USBRST_INT (1 << 11)
  289. #define FUSB300_IGR1_DEV_MODE_CHG_INT (1 << 9)
  290. #define FUSB300_IGR1_CX_COMABT_INT (1 << 8)
  291. #define FUSB300_IGR1_CX_COMFAIL_INT (1 << 7)
  292. #define FUSB300_IGR1_CX_CMDEND_INT (1 << 6)
  293. #define FUSB300_IGR1_CX_OUT_INT (1 << 5)
  294. #define FUSB300_IGR1_CX_IN_INT (1 << 4)
  295. #define FUSB300_IGR1_CX_SETUP_INT (1 << 3)
  296. #define FUSB300_IGR1_INTGRP4 (1 << 2)
  297. #define FUSB300_IGR1_INTGRP3 (1 << 1)
  298. #define FUSB300_IGR1_INTGRP2 (1 << 0)
  299. /*
  300. * *Interrupt Group 2 Register (offset = 408H)
  301. * */
  302. #define FUSB300_IGR2_EP6_STR_ACCEPT_INT (1 << 29)
  303. #define FUSB300_IGR2_EP6_STR_RESUME_INT (1 << 28)
  304. #define FUSB300_IGR2_EP6_STR_REQ_INT (1 << 27)
  305. #define FUSB300_IGR2_EP6_STR_NOTRDY_INT (1 << 26)
  306. #define FUSB300_IGR2_EP6_STR_PRIME_INT (1 << 25)
  307. #define FUSB300_IGR2_EP5_STR_ACCEPT_INT (1 << 24)
  308. #define FUSB300_IGR2_EP5_STR_RESUME_INT (1 << 23)
  309. #define FUSB300_IGR2_EP5_STR_REQ_INT (1 << 22)
  310. #define FUSB300_IGR2_EP5_STR_NOTRDY_INT (1 << 21)
  311. #define FUSB300_IGR2_EP5_STR_PRIME_INT (1 << 20)
  312. #define FUSB300_IGR2_EP4_STR_ACCEPT_INT (1 << 19)
  313. #define FUSB300_IGR2_EP4_STR_RESUME_INT (1 << 18)
  314. #define FUSB300_IGR2_EP4_STR_REQ_INT (1 << 17)
  315. #define FUSB300_IGR2_EP4_STR_NOTRDY_INT (1 << 16)
  316. #define FUSB300_IGR2_EP4_STR_PRIME_INT (1 << 15)
  317. #define FUSB300_IGR2_EP3_STR_ACCEPT_INT (1 << 14)
  318. #define FUSB300_IGR2_EP3_STR_RESUME_INT (1 << 13)
  319. #define FUSB300_IGR2_EP3_STR_REQ_INT (1 << 12)
  320. #define FUSB300_IGR2_EP3_STR_NOTRDY_INT (1 << 11)
  321. #define FUSB300_IGR2_EP3_STR_PRIME_INT (1 << 10)
  322. #define FUSB300_IGR2_EP2_STR_ACCEPT_INT (1 << 9)
  323. #define FUSB300_IGR2_EP2_STR_RESUME_INT (1 << 8)
  324. #define FUSB300_IGR2_EP2_STR_REQ_INT (1 << 7)
  325. #define FUSB300_IGR2_EP2_STR_NOTRDY_INT (1 << 6)
  326. #define FUSB300_IGR2_EP2_STR_PRIME_INT (1 << 5)
  327. #define FUSB300_IGR2_EP1_STR_ACCEPT_INT (1 << 4)
  328. #define FUSB300_IGR2_EP1_STR_RESUME_INT (1 << 3)
  329. #define FUSB300_IGR2_EP1_STR_REQ_INT (1 << 2)
  330. #define FUSB300_IGR2_EP1_STR_NOTRDY_INT (1 << 1)
  331. #define FUSB300_IGR2_EP1_STR_PRIME_INT (1 << 0)
  332. #define FUSB300_IGR2_EP_STR_ACCEPT_INT(n) (1 << (5 * n - 1))
  333. #define FUSB300_IGR2_EP_STR_RESUME_INT(n) (1 << (5 * n - 2))
  334. #define FUSB300_IGR2_EP_STR_REQ_INT(n) (1 << (5 * n - 3))
  335. #define FUSB300_IGR2_EP_STR_NOTRDY_INT(n) (1 << (5 * n - 4))
  336. #define FUSB300_IGR2_EP_STR_PRIME_INT(n) (1 << (5 * n - 5))
  337. /*
  338. * *Interrupt Group 3 Register (offset = 40CH)
  339. * */
  340. #define FUSB300_IGR3_EP12_STR_ACCEPT_INT (1 << 29)
  341. #define FUSB300_IGR3_EP12_STR_RESUME_INT (1 << 28)
  342. #define FUSB300_IGR3_EP12_STR_REQ_INT (1 << 27)
  343. #define FUSB300_IGR3_EP12_STR_NOTRDY_INT (1 << 26)
  344. #define FUSB300_IGR3_EP12_STR_PRIME_INT (1 << 25)
  345. #define FUSB300_IGR3_EP11_STR_ACCEPT_INT (1 << 24)
  346. #define FUSB300_IGR3_EP11_STR_RESUME_INT (1 << 23)
  347. #define FUSB300_IGR3_EP11_STR_REQ_INT (1 << 22)
  348. #define FUSB300_IGR3_EP11_STR_NOTRDY_INT (1 << 21)
  349. #define FUSB300_IGR3_EP11_STR_PRIME_INT (1 << 20)
  350. #define FUSB300_IGR3_EP10_STR_ACCEPT_INT (1 << 19)
  351. #define FUSB300_IGR3_EP10_STR_RESUME_INT (1 << 18)
  352. #define FUSB300_IGR3_EP10_STR_REQ_INT (1 << 17)
  353. #define FUSB300_IGR3_EP10_STR_NOTRDY_INT (1 << 16)
  354. #define FUSB300_IGR3_EP10_STR_PRIME_INT (1 << 15)
  355. #define FUSB300_IGR3_EP9_STR_ACCEPT_INT (1 << 14)
  356. #define FUSB300_IGR3_EP9_STR_RESUME_INT (1 << 13)
  357. #define FUSB300_IGR3_EP9_STR_REQ_INT (1 << 12)
  358. #define FUSB300_IGR3_EP9_STR_NOTRDY_INT (1 << 11)
  359. #define FUSB300_IGR3_EP9_STR_PRIME_INT (1 << 10)
  360. #define FUSB300_IGR3_EP8_STR_ACCEPT_INT (1 << 9)
  361. #define FUSB300_IGR3_EP8_STR_RESUME_INT (1 << 8)
  362. #define FUSB300_IGR3_EP8_STR_REQ_INT (1 << 7)
  363. #define FUSB300_IGR3_EP8_STR_NOTRDY_INT (1 << 6)
  364. #define FUSB300_IGR3_EP8_STR_PRIME_INT (1 << 5)
  365. #define FUSB300_IGR3_EP7_STR_ACCEPT_INT (1 << 4)
  366. #define FUSB300_IGR3_EP7_STR_RESUME_INT (1 << 3)
  367. #define FUSB300_IGR3_EP7_STR_REQ_INT (1 << 2)
  368. #define FUSB300_IGR3_EP7_STR_NOTRDY_INT (1 << 1)
  369. #define FUSB300_IGR3_EP7_STR_PRIME_INT (1 << 0)
  370. #define FUSB300_IGR3_EP_STR_ACCEPT_INT(n) (1 << (5 * (n - 6) - 1))
  371. #define FUSB300_IGR3_EP_STR_RESUME_INT(n) (1 << (5 * (n - 6) - 2))
  372. #define FUSB300_IGR3_EP_STR_REQ_INT(n) (1 << (5 * (n - 6) - 3))
  373. #define FUSB300_IGR3_EP_STR_NOTRDY_INT(n) (1 << (5 * (n - 6) - 4))
  374. #define FUSB300_IGR3_EP_STR_PRIME_INT(n) (1 << (5 * (n - 6) - 5))
  375. /*
  376. * *Interrupt Group 4 Register (offset = 410H)
  377. * */
  378. #define FUSB300_IGR4_EP15_RX0_INT (1 << 31)
  379. #define FUSB300_IGR4_EP14_RX0_INT (1 << 30)
  380. #define FUSB300_IGR4_EP13_RX0_INT (1 << 29)
  381. #define FUSB300_IGR4_EP12_RX0_INT (1 << 28)
  382. #define FUSB300_IGR4_EP11_RX0_INT (1 << 27)
  383. #define FUSB300_IGR4_EP10_RX0_INT (1 << 26)
  384. #define FUSB300_IGR4_EP9_RX0_INT (1 << 25)
  385. #define FUSB300_IGR4_EP8_RX0_INT (1 << 24)
  386. #define FUSB300_IGR4_EP7_RX0_INT (1 << 23)
  387. #define FUSB300_IGR4_EP6_RX0_INT (1 << 22)
  388. #define FUSB300_IGR4_EP5_RX0_INT (1 << 21)
  389. #define FUSB300_IGR4_EP4_RX0_INT (1 << 20)
  390. #define FUSB300_IGR4_EP3_RX0_INT (1 << 19)
  391. #define FUSB300_IGR4_EP2_RX0_INT (1 << 18)
  392. #define FUSB300_IGR4_EP1_RX0_INT (1 << 17)
  393. #define FUSB300_IGR4_EP_RX0_INT(x) (1 << (x + 16))
  394. #define FUSB300_IGR4_EP15_STR_ACCEPT_INT (1 << 14)
  395. #define FUSB300_IGR4_EP15_STR_RESUME_INT (1 << 13)
  396. #define FUSB300_IGR4_EP15_STR_REQ_INT (1 << 12)
  397. #define FUSB300_IGR4_EP15_STR_NOTRDY_INT (1 << 11)
  398. #define FUSB300_IGR4_EP15_STR_PRIME_INT (1 << 10)
  399. #define FUSB300_IGR4_EP14_STR_ACCEPT_INT (1 << 9)
  400. #define FUSB300_IGR4_EP14_STR_RESUME_INT (1 << 8)
  401. #define FUSB300_IGR4_EP14_STR_REQ_INT (1 << 7)
  402. #define FUSB300_IGR4_EP14_STR_NOTRDY_INT (1 << 6)
  403. #define FUSB300_IGR4_EP14_STR_PRIME_INT (1 << 5)
  404. #define FUSB300_IGR4_EP13_STR_ACCEPT_INT (1 << 4)
  405. #define FUSB300_IGR4_EP13_STR_RESUME_INT (1 << 3)
  406. #define FUSB300_IGR4_EP13_STR_REQ_INT (1 << 2)
  407. #define FUSB300_IGR4_EP13_STR_NOTRDY_INT (1 << 1)
  408. #define FUSB300_IGR4_EP13_STR_PRIME_INT (1 << 0)
  409. #define FUSB300_IGR4_EP_STR_ACCEPT_INT(n) (1 << (5 * (n - 12) - 1))
  410. #define FUSB300_IGR4_EP_STR_RESUME_INT(n) (1 << (5 * (n - 12) - 2))
  411. #define FUSB300_IGR4_EP_STR_REQ_INT(n) (1 << (5 * (n - 12) - 3))
  412. #define FUSB300_IGR4_EP_STR_NOTRDY_INT(n) (1 << (5 * (n - 12) - 4))
  413. #define FUSB300_IGR4_EP_STR_PRIME_INT(n) (1 << (5 * (n - 12) - 5))
  414. /*
  415. * *Interrupt Group 5 Register (offset = 414H)
  416. * */
  417. #define FUSB300_IGR5_EP_STL_INT(n) (1 << n)
  418. /*
  419. * *Interrupt Enable Group 0 Register (offset = 420H)
  420. * */
  421. #define FUSB300_IGER0_EEP15_PRD_INT (1 << 31)
  422. #define FUSB300_IGER0_EEP14_PRD_INT (1 << 30)
  423. #define FUSB300_IGER0_EEP13_PRD_INT (1 << 29)
  424. #define FUSB300_IGER0_EEP12_PRD_INT (1 << 28)
  425. #define FUSB300_IGER0_EEP11_PRD_INT (1 << 27)
  426. #define FUSB300_IGER0_EEP10_PRD_INT (1 << 26)
  427. #define FUSB300_IGER0_EEP9_PRD_INT (1 << 25)
  428. #define FUSB300_IGER0_EP8_PRD_INT (1 << 24)
  429. #define FUSB300_IGER0_EEP7_PRD_INT (1 << 23)
  430. #define FUSB300_IGER0_EEP6_PRD_INT (1 << 22)
  431. #define FUSB300_IGER0_EEP5_PRD_INT (1 << 21)
  432. #define FUSB300_IGER0_EEP4_PRD_INT (1 << 20)
  433. #define FUSB300_IGER0_EEP3_PRD_INT (1 << 19)
  434. #define FUSB300_IGER0_EEP2_PRD_INT (1 << 18)
  435. #define FUSB300_IGER0_EEP1_PRD_INT (1 << 17)
  436. #define FUSB300_IGER0_EEPn_PRD_INT(n) (1 << (n + 16))
  437. #define FUSB300_IGER0_EEP15_FIFO_INT (1 << 15)
  438. #define FUSB300_IGER0_EEP14_FIFO_INT (1 << 14)
  439. #define FUSB300_IGER0_EEP13_FIFO_INT (1 << 13)
  440. #define FUSB300_IGER0_EEP12_FIFO_INT (1 << 12)
  441. #define FUSB300_IGER0_EEP11_FIFO_INT (1 << 11)
  442. #define FUSB300_IGER0_EEP10_FIFO_INT (1 << 10)
  443. #define FUSB300_IGER0_EEP9_FIFO_INT (1 << 9)
  444. #define FUSB300_IGER0_EEP8_FIFO_INT (1 << 8)
  445. #define FUSB300_IGER0_EEP7_FIFO_INT (1 << 7)
  446. #define FUSB300_IGER0_EEP6_FIFO_INT (1 << 6)
  447. #define FUSB300_IGER0_EEP5_FIFO_INT (1 << 5)
  448. #define FUSB300_IGER0_EEP4_FIFO_INT (1 << 4)
  449. #define FUSB300_IGER0_EEP3_FIFO_INT (1 << 3)
  450. #define FUSB300_IGER0_EEP2_FIFO_INT (1 << 2)
  451. #define FUSB300_IGER0_EEP1_FIFO_INT (1 << 1)
  452. #define FUSB300_IGER0_EEPn_FIFO_INT(n) (1 << n)
  453. /*
  454. * *Interrupt Enable Group 1 Register (offset = 424H)
  455. * */
  456. #define FUSB300_IGER1_EINT_GRP5 (1 << 31)
  457. #define FUSB300_IGER1_VBUS_CHG_INT (1 << 30)
  458. #define FUSB300_IGER1_SYNF1_EMPTY_INT (1 << 29)
  459. #define FUSB300_IGER1_SYNF0_EMPTY_INT (1 << 28)
  460. #define FUSB300_IGER1_U3_EXIT_FAIL_INT (1 << 27)
  461. #define FUSB300_IGER1_U2_EXIT_FAIL_INT (1 << 26)
  462. #define FUSB300_IGER1_U1_EXIT_FAIL_INT (1 << 25)
  463. #define FUSB300_IGER1_U2_ENTRY_FAIL_INT (1 << 24)
  464. #define FUSB300_IGER1_U1_ENTRY_FAIL_INT (1 << 23)
  465. #define FUSB300_IGER1_U3_EXIT_INT (1 << 22)
  466. #define FUSB300_IGER1_U2_EXIT_INT (1 << 21)
  467. #define FUSB300_IGER1_U1_EXIT_INT (1 << 20)
  468. #define FUSB300_IGER1_U3_ENTRY_INT (1 << 19)
  469. #define FUSB300_IGER1_U2_ENTRY_INT (1 << 18)
  470. #define FUSB300_IGER1_U1_ENTRY_INT (1 << 17)
  471. #define FUSB300_IGER1_HOT_RST_INT (1 << 16)
  472. #define FUSB300_IGER1_WARM_RST_INT (1 << 15)
  473. #define FUSB300_IGER1_RESM_INT (1 << 14)
  474. #define FUSB300_IGER1_SUSP_INT (1 << 13)
  475. #define FUSB300_IGER1_LPM_INT (1 << 12)
  476. #define FUSB300_IGER1_HS_RST_INT (1 << 11)
  477. #define FUSB300_IGER1_EDEV_MODE_CHG_INT (1 << 9)
  478. #define FUSB300_IGER1_CX_COMABT_INT (1 << 8)
  479. #define FUSB300_IGER1_CX_COMFAIL_INT (1 << 7)
  480. #define FUSB300_IGER1_CX_CMDEND_INT (1 << 6)
  481. #define FUSB300_IGER1_CX_OUT_INT (1 << 5)
  482. #define FUSB300_IGER1_CX_IN_INT (1 << 4)
  483. #define FUSB300_IGER1_CX_SETUP_INT (1 << 3)
  484. #define FUSB300_IGER1_INTGRP4 (1 << 2)
  485. #define FUSB300_IGER1_INTGRP3 (1 << 1)
  486. #define FUSB300_IGER1_INTGRP2 (1 << 0)
  487. /*
  488. * *Interrupt Enable Group 2 Register (offset = 428H)
  489. * */
  490. #define FUSB300_IGER2_EEP_STR_ACCEPT_INT(n) (1 << (5 * n - 1))
  491. #define FUSB300_IGER2_EEP_STR_RESUME_INT(n) (1 << (5 * n - 2))
  492. #define FUSB300_IGER2_EEP_STR_REQ_INT(n) (1 << (5 * n - 3))
  493. #define FUSB300_IGER2_EEP_STR_NOTRDY_INT(n) (1 << (5 * n - 4))
  494. #define FUSB300_IGER2_EEP_STR_PRIME_INT(n) (1 << (5 * n - 5))
  495. /*
  496. * *Interrupt Enable Group 3 Register (offset = 42CH)
  497. * */
  498. #define FUSB300_IGER3_EEP_STR_ACCEPT_INT(n) (1 << (5 * (n - 6) - 1))
  499. #define FUSB300_IGER3_EEP_STR_RESUME_INT(n) (1 << (5 * (n - 6) - 2))
  500. #define FUSB300_IGER3_EEP_STR_REQ_INT(n) (1 << (5 * (n - 6) - 3))
  501. #define FUSB300_IGER3_EEP_STR_NOTRDY_INT(n) (1 << (5 * (n - 6) - 4))
  502. #define FUSB300_IGER3_EEP_STR_PRIME_INT(n) (1 << (5 * (n - 6) - 5))
  503. /*
  504. * *Interrupt Enable Group 4 Register (offset = 430H)
  505. * */
  506. #define FUSB300_IGER4_EEP_RX0_INT(n) (1 << (n + 16))
  507. #define FUSB300_IGER4_EEP_STR_ACCEPT_INT(n) (1 << (5 * (n - 6) - 1))
  508. #define FUSB300_IGER4_EEP_STR_RESUME_INT(n) (1 << (5 * (n - 6) - 2))
  509. #define FUSB300_IGER4_EEP_STR_REQ_INT(n) (1 << (5 * (n - 6) - 3))
  510. #define FUSB300_IGER4_EEP_STR_NOTRDY_INT(n) (1 << (5 * (n - 6) - 4))
  511. #define FUSB300_IGER4_EEP_STR_PRIME_INT(n) (1 << (5 * (n - 6) - 5))
  512. /* EP PRD Ready (EP_PRD_RDY, offset = 504H) */
  513. #define FUSB300_EPPRDR_EP15_PRD_RDY (1 << 15)
  514. #define FUSB300_EPPRDR_EP14_PRD_RDY (1 << 14)
  515. #define FUSB300_EPPRDR_EP13_PRD_RDY (1 << 13)
  516. #define FUSB300_EPPRDR_EP12_PRD_RDY (1 << 12)
  517. #define FUSB300_EPPRDR_EP11_PRD_RDY (1 << 11)
  518. #define FUSB300_EPPRDR_EP10_PRD_RDY (1 << 10)
  519. #define FUSB300_EPPRDR_EP9_PRD_RDY (1 << 9)
  520. #define FUSB300_EPPRDR_EP8_PRD_RDY (1 << 8)
  521. #define FUSB300_EPPRDR_EP7_PRD_RDY (1 << 7)
  522. #define FUSB300_EPPRDR_EP6_PRD_RDY (1 << 6)
  523. #define FUSB300_EPPRDR_EP5_PRD_RDY (1 << 5)
  524. #define FUSB300_EPPRDR_EP4_PRD_RDY (1 << 4)
  525. #define FUSB300_EPPRDR_EP3_PRD_RDY (1 << 3)
  526. #define FUSB300_EPPRDR_EP2_PRD_RDY (1 << 2)
  527. #define FUSB300_EPPRDR_EP1_PRD_RDY (1 << 1)
  528. #define FUSB300_EPPRDR_EP_PRD_RDY(n) (1 << n)
  529. /* AHB Bus Control Register (offset = 514H) */
  530. #define FUSB300_AHBBCR_S1_SPLIT_ON (1 << 17)
  531. #define FUSB300_AHBBCR_S0_SPLIT_ON (1 << 16)
  532. #define FUSB300_AHBBCR_S1_1entry (0 << 12)
  533. #define FUSB300_AHBBCR_S1_4entry (3 << 12)
  534. #define FUSB300_AHBBCR_S1_8entry (5 << 12)
  535. #define FUSB300_AHBBCR_S1_16entry (7 << 12)
  536. #define FUSB300_AHBBCR_S0_1entry (0 << 8)
  537. #define FUSB300_AHBBCR_S0_4entry (3 << 8)
  538. #define FUSB300_AHBBCR_S0_8entry (5 << 8)
  539. #define FUSB300_AHBBCR_S0_16entry (7 << 8)
  540. #define FUSB300_AHBBCR_M1_BURST_SINGLE (0 << 4)
  541. #define FUSB300_AHBBCR_M1_BURST_INCR (1 << 4)
  542. #define FUSB300_AHBBCR_M1_BURST_INCR4 (3 << 4)
  543. #define FUSB300_AHBBCR_M1_BURST_INCR8 (5 << 4)
  544. #define FUSB300_AHBBCR_M1_BURST_INCR16 (7 << 4)
  545. #define FUSB300_AHBBCR_M0_BURST_SINGLE 0
  546. #define FUSB300_AHBBCR_M0_BURST_INCR 1
  547. #define FUSB300_AHBBCR_M0_BURST_INCR4 3
  548. #define FUSB300_AHBBCR_M0_BURST_INCR8 5
  549. #define FUSB300_AHBBCR_M0_BURST_INCR16 7
  550. #define FUSB300_IGER5_EEP_STL_INT(n) (1 << n)
  551. /* WORD 0 Data Structure of PRD Table */
  552. #define FUSB300_EPPRD0_M (1 << 30)
  553. #define FUSB300_EPPRD0_O (1 << 29)
  554. /* The finished prd */
  555. #define FUSB300_EPPRD0_F (1 << 28)
  556. #define FUSB300_EPPRD0_I (1 << 27)
  557. #define FUSB300_EPPRD0_A (1 << 26)
  558. /* To decide HW point to first prd at next time */
  559. #define FUSB300_EPPRD0_L (1 << 25)
  560. #define FUSB300_EPPRD0_H (1 << 24)
  561. #define FUSB300_EPPRD0_BTC(n) (n & 0xFFFFFF)
  562. /*----------------------------------------------------------------------*/
  563. #define FUSB300_MAX_NUM_EP 16
  564. #define FUSB300_FIFO_ENTRY_NUM 8
  565. #define FUSB300_MAX_FIFO_ENTRY 8
  566. #define SS_CTL_MAX_PACKET_SIZE 0x200
  567. #define SS_BULK_MAX_PACKET_SIZE 0x400
  568. #define SS_INT_MAX_PACKET_SIZE 0x400
  569. #define SS_ISO_MAX_PACKET_SIZE 0x400
  570. #define HS_BULK_MAX_PACKET_SIZE 0x200
  571. #define HS_CTL_MAX_PACKET_SIZE 0x40
  572. #define HS_INT_MAX_PACKET_SIZE 0x400
  573. #define HS_ISO_MAX_PACKET_SIZE 0x400
  574. struct fusb300_ep_info {
  575. u8 epnum;
  576. u8 type;
  577. u8 interval;
  578. u8 dir_in;
  579. u16 maxpacket;
  580. u16 addrofs;
  581. u16 bw_num;
  582. };
  583. struct fusb300_request {
  584. struct usb_request req;
  585. struct list_head queue;
  586. };
  587. struct fusb300_ep {
  588. struct usb_ep ep;
  589. struct fusb300 *fusb300;
  590. struct list_head queue;
  591. unsigned stall:1;
  592. unsigned wedged:1;
  593. unsigned use_dma:1;
  594. unsigned char epnum;
  595. unsigned char type;
  596. };
  597. struct fusb300 {
  598. spinlock_t lock;
  599. void __iomem *reg;
  600. unsigned long irq_trigger;
  601. struct usb_gadget gadget;
  602. struct usb_gadget_driver *driver;
  603. struct fusb300_ep *ep[FUSB300_MAX_NUM_EP];
  604. struct usb_request *ep0_req; /* for internal request */
  605. __le16 ep0_data;
  606. u32 ep0_length; /* for internal request */
  607. u8 ep0_dir; /* 0/0x80 out/in */
  608. u8 fifo_entry_num; /* next start fifo entry */
  609. u32 addrofs; /* next fifo address offset */
  610. u8 reenum; /* if re-enumeration */
  611. };
  612. #define to_fusb300(g) (container_of((g), struct fusb300, gadget))
  613. #endif