gadget.h 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * USBSS device controller driver header file
  4. *
  5. * Copyright (C) 2018-2019 Cadence.
  6. * Copyright (C) 2017-2018 NXP
  7. *
  8. * Author: Pawel Laszczak <pawell@cadence.com>
  9. * Pawel Jez <pjez@cadence.com>
  10. * Peter Chen <peter.chen@nxp.com>
  11. */
  12. #ifndef __LINUX_CDNS3_GADGET
  13. #define __LINUX_CDNS3_GADGET
  14. #include <linux/usb/gadget.h>
  15. /*
  16. * USBSS-DEV register interface.
  17. * This corresponds to the USBSS Device Controller Interface
  18. */
  19. /**
  20. * struct cdns3_usb_regs - device controller registers.
  21. * @usb_conf: Global Configuration.
  22. * @usb_sts: Global Status.
  23. * @usb_cmd: Global Command.
  24. * @usb_itpn: ITP/SOF number.
  25. * @usb_lpm: Global Command.
  26. * @usb_ien: USB Interrupt Enable.
  27. * @usb_ists: USB Interrupt Status.
  28. * @ep_sel: Endpoint Select.
  29. * @ep_traddr: Endpoint Transfer Ring Address.
  30. * @ep_cfg: Endpoint Configuration.
  31. * @ep_cmd: Endpoint Command.
  32. * @ep_sts: Endpoint Status.
  33. * @ep_sts_sid: Endpoint Status.
  34. * @ep_sts_en: Endpoint Status Enable.
  35. * @drbl: Doorbell.
  36. * @ep_ien: EP Interrupt Enable.
  37. * @ep_ists: EP Interrupt Status.
  38. * @usb_pwr: Global Power Configuration.
  39. * @usb_conf2: Global Configuration 2.
  40. * @usb_cap1: Capability 1.
  41. * @usb_cap2: Capability 2.
  42. * @usb_cap3: Capability 3.
  43. * @usb_cap4: Capability 4.
  44. * @usb_cap5: Capability 5.
  45. * @usb_cap6: Capability 6.
  46. * @usb_cpkt1: Custom Packet 1.
  47. * @usb_cpkt2: Custom Packet 2.
  48. * @usb_cpkt3: Custom Packet 3.
  49. * @ep_dma_ext_addr: Upper address for DMA operations.
  50. * @buf_addr: Address for On-chip Buffer operations.
  51. * @buf_data: Data for On-chip Buffer operations.
  52. * @buf_ctrl: On-chip Buffer Access Control.
  53. * @dtrans: DMA Transfer Mode.
  54. * @tdl_from_trb: Source of TD Configuration.
  55. * @tdl_beh: TDL Behavior Configuration.
  56. * @ep_tdl: Endpoint TDL.
  57. * @tdl_beh2: TDL Behavior 2 Configuration.
  58. * @dma_adv_td: DMA Advance TD Configuration.
  59. * @reserved1: Reserved.
  60. * @cfg_regs: Configuration.
  61. * @reserved2: Reserved.
  62. * @dma_axi_ctrl: AXI Control.
  63. * @dma_axi_id: AXI ID register.
  64. * @dma_axi_cap: AXI Capability.
  65. * @dma_axi_ctrl0: AXI Control 0.
  66. * @dma_axi_ctrl1: AXI Control 1.
  67. */
  68. struct cdns3_usb_regs {
  69. __le32 usb_conf;
  70. __le32 usb_sts;
  71. __le32 usb_cmd;
  72. __le32 usb_itpn;
  73. __le32 usb_lpm;
  74. __le32 usb_ien;
  75. __le32 usb_ists;
  76. __le32 ep_sel;
  77. __le32 ep_traddr;
  78. __le32 ep_cfg;
  79. __le32 ep_cmd;
  80. __le32 ep_sts;
  81. __le32 ep_sts_sid;
  82. __le32 ep_sts_en;
  83. __le32 drbl;
  84. __le32 ep_ien;
  85. __le32 ep_ists;
  86. __le32 usb_pwr;
  87. __le32 usb_conf2;
  88. __le32 usb_cap1;
  89. __le32 usb_cap2;
  90. __le32 usb_cap3;
  91. __le32 usb_cap4;
  92. __le32 usb_cap5;
  93. __le32 usb_cap6;
  94. __le32 usb_cpkt1;
  95. __le32 usb_cpkt2;
  96. __le32 usb_cpkt3;
  97. __le32 ep_dma_ext_addr;
  98. __le32 buf_addr;
  99. __le32 buf_data;
  100. __le32 buf_ctrl;
  101. __le32 dtrans;
  102. __le32 tdl_from_trb;
  103. __le32 tdl_beh;
  104. __le32 ep_tdl;
  105. __le32 tdl_beh2;
  106. __le32 dma_adv_td;
  107. __le32 reserved1[26];
  108. __le32 cfg_reg1;
  109. __le32 dbg_link1;
  110. __le32 dbg_link2;
  111. __le32 cfg_regs[74];
  112. __le32 reserved2[51];
  113. __le32 dma_axi_ctrl;
  114. __le32 dma_axi_id;
  115. __le32 dma_axi_cap;
  116. __le32 dma_axi_ctrl0;
  117. __le32 dma_axi_ctrl1;
  118. };
  119. /* USB_CONF - bitmasks */
  120. /* Reset USB device configuration. */
  121. #define USB_CONF_CFGRST BIT(0)
  122. /* Set Configuration. */
  123. #define USB_CONF_CFGSET BIT(1)
  124. /* Disconnect USB device in SuperSpeed. */
  125. #define USB_CONF_USB3DIS BIT(3)
  126. /* Disconnect USB device in HS/FS */
  127. #define USB_CONF_USB2DIS BIT(4)
  128. /* Little Endian access - default */
  129. #define USB_CONF_LENDIAN BIT(5)
  130. /*
  131. * Big Endian access. Driver assume that byte order for
  132. * SFRs access always is as Little Endian so this bit
  133. * is not used.
  134. */
  135. #define USB_CONF_BENDIAN BIT(6)
  136. /* Device software reset. */
  137. #define USB_CONF_SWRST BIT(7)
  138. /* Singular DMA transfer mode. Only for VER < DEV_VER_V3*/
  139. #define USB_CONF_DSING BIT(8)
  140. /* Multiple DMA transfers mode. Only for VER < DEV_VER_V3 */
  141. #define USB_CONF_DMULT BIT(9)
  142. /* DMA clock turn-off enable. */
  143. #define USB_CONF_DMAOFFEN BIT(10)
  144. /* DMA clock turn-off disable. */
  145. #define USB_CONF_DMAOFFDS BIT(11)
  146. /* Clear Force Full Speed. */
  147. #define USB_CONF_CFORCE_FS BIT(12)
  148. /* Set Force Full Speed. */
  149. #define USB_CONF_SFORCE_FS BIT(13)
  150. /* Device enable. */
  151. #define USB_CONF_DEVEN BIT(14)
  152. /* Device disable. */
  153. #define USB_CONF_DEVDS BIT(15)
  154. /* L1 LPM state entry enable (used in HS/FS mode). */
  155. #define USB_CONF_L1EN BIT(16)
  156. /* L1 LPM state entry disable (used in HS/FS mode). */
  157. #define USB_CONF_L1DS BIT(17)
  158. /* USB 2.0 clock gate disable. */
  159. #define USB_CONF_CLK2OFFEN BIT(18)
  160. /* USB 2.0 clock gate enable. */
  161. #define USB_CONF_CLK2OFFDS BIT(19)
  162. /* L0 LPM state entry request (used in HS/FS mode). */
  163. #define USB_CONF_LGO_L0 BIT(20)
  164. /* USB 3.0 clock gate disable. */
  165. #define USB_CONF_CLK3OFFEN BIT(21)
  166. /* USB 3.0 clock gate enable. */
  167. #define USB_CONF_CLK3OFFDS BIT(22)
  168. /* Bit 23 is reserved*/
  169. /* U1 state entry enable (used in SS mode). */
  170. #define USB_CONF_U1EN BIT(24)
  171. /* U1 state entry disable (used in SS mode). */
  172. #define USB_CONF_U1DS BIT(25)
  173. /* U2 state entry enable (used in SS mode). */
  174. #define USB_CONF_U2EN BIT(26)
  175. /* U2 state entry disable (used in SS mode). */
  176. #define USB_CONF_U2DS BIT(27)
  177. /* U0 state entry request (used in SS mode). */
  178. #define USB_CONF_LGO_U0 BIT(28)
  179. /* U1 state entry request (used in SS mode). */
  180. #define USB_CONF_LGO_U1 BIT(29)
  181. /* U2 state entry request (used in SS mode). */
  182. #define USB_CONF_LGO_U2 BIT(30)
  183. /* SS.Inactive state entry request (used in SS mode) */
  184. #define USB_CONF_LGO_SSINACT BIT(31)
  185. /* USB_STS - bitmasks */
  186. /*
  187. * Configuration status.
  188. * 1 - device is in the configured state.
  189. * 0 - device is not configured.
  190. */
  191. #define USB_STS_CFGSTS_MASK BIT(0)
  192. #define USB_STS_CFGSTS(p) ((p) & USB_STS_CFGSTS_MASK)
  193. /*
  194. * On-chip memory overflow.
  195. * 0 - On-chip memory status OK.
  196. * 1 - On-chip memory overflow.
  197. */
  198. #define USB_STS_OV_MASK BIT(1)
  199. #define USB_STS_OV(p) ((p) & USB_STS_OV_MASK)
  200. /*
  201. * SuperSpeed connection status.
  202. * 0 - USB in SuperSpeed mode disconnected.
  203. * 1 - USB in SuperSpeed mode connected.
  204. */
  205. #define USB_STS_USB3CONS_MASK BIT(2)
  206. #define USB_STS_USB3CONS(p) ((p) & USB_STS_USB3CONS_MASK)
  207. /*
  208. * DMA transfer configuration status.
  209. * 0 - single request.
  210. * 1 - multiple TRB chain
  211. * Supported only for controller version < DEV_VER_V3
  212. */
  213. #define USB_STS_DTRANS_MASK BIT(3)
  214. #define USB_STS_DTRANS(p) ((p) & USB_STS_DTRANS_MASK)
  215. /*
  216. * Device speed.
  217. * 0 - Undefined (value after reset).
  218. * 1 - Low speed
  219. * 2 - Full speed
  220. * 3 - High speed
  221. * 4 - Super speed
  222. */
  223. #define USB_STS_USBSPEED_MASK GENMASK(6, 4)
  224. #define USB_STS_USBSPEED(p) (((p) & USB_STS_USBSPEED_MASK) >> 4)
  225. #define USB_STS_LS (0x1 << 4)
  226. #define USB_STS_FS (0x2 << 4)
  227. #define USB_STS_HS (0x3 << 4)
  228. #define USB_STS_SS (0x4 << 4)
  229. #define DEV_UNDEFSPEED(p) (((p) & USB_STS_USBSPEED_MASK) == (0x0 << 4))
  230. #define DEV_LOWSPEED(p) (((p) & USB_STS_USBSPEED_MASK) == USB_STS_LS)
  231. #define DEV_FULLSPEED(p) (((p) & USB_STS_USBSPEED_MASK) == USB_STS_FS)
  232. #define DEV_HIGHSPEED(p) (((p) & USB_STS_USBSPEED_MASK) == USB_STS_HS)
  233. #define DEV_SUPERSPEED(p) (((p) & USB_STS_USBSPEED_MASK) == USB_STS_SS)
  234. /*
  235. * Endianness for SFR access.
  236. * 0 - Little Endian order (default after hardware reset).
  237. * 1 - Big Endian order
  238. */
  239. #define USB_STS_ENDIAN_MASK BIT(7)
  240. #define USB_STS_ENDIAN(p) ((p) & USB_STS_ENDIAN_MASK)
  241. /*
  242. * HS/FS clock turn-off status.
  243. * 0 - hsfs clock is always on.
  244. * 1 - hsfs clock turn-off in L2 (HS/FS mode) is enabled
  245. * (default after hardware reset).
  246. */
  247. #define USB_STS_CLK2OFF_MASK BIT(8)
  248. #define USB_STS_CLK2OFF(p) ((p) & USB_STS_CLK2OFF_MASK)
  249. /*
  250. * PCLK clock turn-off status.
  251. * 0 - pclk clock is always on.
  252. * 1 - pclk clock turn-off in U3 (SS mode) is enabled
  253. * (default after hardware reset).
  254. */
  255. #define USB_STS_CLK3OFF_MASK BIT(9)
  256. #define USB_STS_CLK3OFF(p) ((p) & USB_STS_CLK3OFF_MASK)
  257. /*
  258. * Controller in reset state.
  259. * 0 - Internal reset is active.
  260. * 1 - Internal reset is not active and controller is fully operational.
  261. */
  262. #define USB_STS_IN_RST_MASK BIT(10)
  263. #define USB_STS_IN_RST(p) ((p) & USB_STS_IN_RST_MASK)
  264. /*
  265. * Status of the "TDL calculation basing on TRB" feature.
  266. * 0 - disabled
  267. * 1 - enabled
  268. * Supported only for DEV_VER_V2 controller version.
  269. */
  270. #define USB_STS_TDL_TRB_ENABLED BIT(11)
  271. /*
  272. * Device enable Status.
  273. * 0 - USB device is disabled (VBUS input is disconnected from internal logic).
  274. * 1 - USB device is enabled (VBUS input is connected to the internal logic).
  275. */
  276. #define USB_STS_DEVS_MASK BIT(14)
  277. #define USB_STS_DEVS(p) ((p) & USB_STS_DEVS_MASK)
  278. /*
  279. * Address status.
  280. * 0 - USB device is default state.
  281. * 1 - USB device is at least in address state.
  282. */
  283. #define USB_STS_ADDRESSED_MASK BIT(15)
  284. #define USB_STS_ADDRESSED(p) ((p) & USB_STS_ADDRESSED_MASK)
  285. /*
  286. * L1 LPM state enable status (used in HS/FS mode).
  287. * 0 - Entering to L1 LPM state disabled.
  288. * 1 - Entering to L1 LPM state enabled.
  289. */
  290. #define USB_STS_L1ENS_MASK BIT(16)
  291. #define USB_STS_L1ENS(p) ((p) & USB_STS_L1ENS_MASK)
  292. /*
  293. * Internal VBUS connection status (used both in HS/FS and SS mode).
  294. * 0 - internal VBUS is not detected.
  295. * 1 - internal VBUS is detected.
  296. */
  297. #define USB_STS_VBUSS_MASK BIT(17)
  298. #define USB_STS_VBUSS(p) ((p) & USB_STS_VBUSS_MASK)
  299. /*
  300. * HS/FS LPM state (used in FS/HS mode).
  301. * 0 - L0 State
  302. * 1 - L1 State
  303. * 2 - L2 State
  304. * 3 - L3 State
  305. */
  306. #define USB_STS_LPMST_MASK GENMASK(19, 18)
  307. #define DEV_L0_STATE(p) (((p) & USB_STS_LPMST_MASK) == (0x0 << 18))
  308. #define DEV_L1_STATE(p) (((p) & USB_STS_LPMST_MASK) == (0x1 << 18))
  309. #define DEV_L2_STATE(p) (((p) & USB_STS_LPMST_MASK) == (0x2 << 18))
  310. #define DEV_L3_STATE(p) (((p) & USB_STS_LPMST_MASK) == (0x3 << 18))
  311. /*
  312. * Disable HS status (used in FS/HS mode).
  313. * 0 - the disconnect bit for HS/FS mode is set .
  314. * 1 - the disconnect bit for HS/FS mode is not set.
  315. */
  316. #define USB_STS_USB2CONS_MASK BIT(20)
  317. #define USB_STS_USB2CONS(p) ((p) & USB_STS_USB2CONS_MASK)
  318. /*
  319. * HS/FS mode connection status (used in FS/HS mode).
  320. * 0 - High Speed operations in USB2.0 (FS/HS) mode not disabled.
  321. * 1 - High Speed operations in USB2.0 (FS/HS).
  322. */
  323. #define USB_STS_DISABLE_HS_MASK BIT(21)
  324. #define USB_STS_DISABLE_HS(p) ((p) & USB_STS_DISABLE_HS_MASK)
  325. /*
  326. * U1 state enable status (used in SS mode).
  327. * 0 - Entering to U1 state disabled.
  328. * 1 - Entering to U1 state enabled.
  329. */
  330. #define USB_STS_U1ENS_MASK BIT(24)
  331. #define USB_STS_U1ENS(p) ((p) & USB_STS_U1ENS_MASK)
  332. /*
  333. * U2 state enable status (used in SS mode).
  334. * 0 - Entering to U2 state disabled.
  335. * 1 - Entering to U2 state enabled.
  336. */
  337. #define USB_STS_U2ENS_MASK BIT(25)
  338. #define USB_STS_U2ENS(p) ((p) & USB_STS_U2ENS_MASK)
  339. /*
  340. * SuperSpeed Link LTSSM state. This field reflects USBSS-DEV current
  341. * SuperSpeed link state
  342. */
  343. #define USB_STS_LST_MASK GENMASK(29, 26)
  344. #define DEV_LST_U0 (((p) & USB_STS_LST_MASK) == (0x0 << 26))
  345. #define DEV_LST_U1 (((p) & USB_STS_LST_MASK) == (0x1 << 26))
  346. #define DEV_LST_U2 (((p) & USB_STS_LST_MASK) == (0x2 << 26))
  347. #define DEV_LST_U3 (((p) & USB_STS_LST_MASK) == (0x3 << 26))
  348. #define DEV_LST_DISABLED (((p) & USB_STS_LST_MASK) == (0x4 << 26))
  349. #define DEV_LST_RXDETECT (((p) & USB_STS_LST_MASK) == (0x5 << 26))
  350. #define DEV_LST_INACTIVE (((p) & USB_STS_LST_MASK) == (0x6 << 26))
  351. #define DEV_LST_POLLING (((p) & USB_STS_LST_MASK) == (0x7 << 26))
  352. #define DEV_LST_RECOVERY (((p) & USB_STS_LST_MASK) == (0x8 << 26))
  353. #define DEV_LST_HOT_RESET (((p) & USB_STS_LST_MASK) == (0x9 << 26))
  354. #define DEV_LST_COMP_MODE (((p) & USB_STS_LST_MASK) == (0xa << 26))
  355. #define DEV_LST_LB_STATE (((p) & USB_STS_LST_MASK) == (0xb << 26))
  356. /*
  357. * DMA clock turn-off status.
  358. * 0 - DMA clock is always on (default after hardware reset).
  359. * 1 - DMA clock turn-off in U1, U2 and U3 (SS mode) is enabled.
  360. */
  361. #define USB_STS_DMAOFF_MASK BIT(30)
  362. #define USB_STS_DMAOFF(p) ((p) & USB_STS_DMAOFF_MASK)
  363. /*
  364. * SFR Endian status.
  365. * 0 - Little Endian order (default after hardware reset).
  366. * 1 - Big Endian order.
  367. */
  368. #define USB_STS_ENDIAN2_MASK BIT(31)
  369. #define USB_STS_ENDIAN2(p) ((p) & USB_STS_ENDIAN2_MASK)
  370. /* USB_CMD - bitmasks */
  371. /* Set Function Address */
  372. #define USB_CMD_SET_ADDR BIT(0)
  373. /*
  374. * Function Address This field is saved to the device only when the field
  375. * SET_ADDR is set '1 ' during write to USB_CMD register.
  376. * Software is responsible for entering the address of the device during
  377. * SET_ADDRESS request service. This field should be set immediately after
  378. * the SETUP packet is decoded, and prior to confirmation of the status phase
  379. */
  380. #define USB_CMD_FADDR_MASK GENMASK(7, 1)
  381. #define USB_CMD_FADDR(p) (((p) << 1) & USB_CMD_FADDR_MASK)
  382. /* Send Function Wake Device Notification TP (used only in SS mode). */
  383. #define USB_CMD_SDNFW BIT(8)
  384. /* Set Test Mode (used only in HS/FS mode). */
  385. #define USB_CMD_STMODE BIT(9)
  386. /* Test mode selector (used only in HS/FS mode) */
  387. #define USB_STS_TMODE_SEL_MASK GENMASK(11, 10)
  388. #define USB_STS_TMODE_SEL(p) (((p) << 10) & USB_STS_TMODE_SEL_MASK)
  389. /*
  390. * Send Latency Tolerance Message Device Notification TP (used only
  391. * in SS mode).
  392. */
  393. #define USB_CMD_SDNLTM BIT(12)
  394. /* Send Custom Transaction Packet (used only in SS mode) */
  395. #define USB_CMD_SPKT BIT(13)
  396. /*Device Notification 'Function Wake' - Interface value (only in SS mode. */
  397. #define USB_CMD_DNFW_INT_MASK GENMASK(23, 16)
  398. #define USB_STS_DNFW_INT(p) (((p) << 16) & USB_CMD_DNFW_INT_MASK)
  399. /*
  400. * Device Notification 'Latency Tolerance Message' -373 BELT value [7:0]
  401. * (used only in SS mode).
  402. */
  403. #define USB_CMD_DNLTM_BELT_MASK GENMASK(27, 16)
  404. #define USB_STS_DNLTM_BELT(p) (((p) << 16) & USB_CMD_DNLTM_BELT_MASK)
  405. /* USB_ITPN - bitmasks */
  406. /*
  407. * ITP(SS) / SOF (HS/FS) number
  408. * In SS mode this field represent number of last ITP received from host.
  409. * In HS/FS mode this field represent number of last SOF received from host.
  410. */
  411. #define USB_ITPN_MASK GENMASK(13, 0)
  412. #define USB_ITPN(p) ((p) & USB_ITPN_MASK)
  413. /* USB_LPM - bitmasks */
  414. /* Host Initiated Resume Duration. */
  415. #define USB_LPM_HIRD_MASK GENMASK(3, 0)
  416. #define USB_LPM_HIRD(p) ((p) & USB_LPM_HIRD_MASK)
  417. /* Remote Wakeup Enable (bRemoteWake). */
  418. #define USB_LPM_BRW BIT(4)
  419. /* USB_IEN - bitmasks */
  420. /* SS connection interrupt enable */
  421. #define USB_IEN_CONIEN BIT(0)
  422. /* SS disconnection interrupt enable. */
  423. #define USB_IEN_DISIEN BIT(1)
  424. /* USB SS warm reset interrupt enable. */
  425. #define USB_IEN_UWRESIEN BIT(2)
  426. /* USB SS hot reset interrupt enable */
  427. #define USB_IEN_UHRESIEN BIT(3)
  428. /* SS link U3 state enter interrupt enable (suspend).*/
  429. #define USB_IEN_U3ENTIEN BIT(4)
  430. /* SS link U3 state exit interrupt enable (wakeup). */
  431. #define USB_IEN_U3EXTIEN BIT(5)
  432. /* SS link U2 state enter interrupt enable.*/
  433. #define USB_IEN_U2ENTIEN BIT(6)
  434. /* SS link U2 state exit interrupt enable.*/
  435. #define USB_IEN_U2EXTIEN BIT(7)
  436. /* SS link U1 state enter interrupt enable.*/
  437. #define USB_IEN_U1ENTIEN BIT(8)
  438. /* SS link U1 state exit interrupt enable.*/
  439. #define USB_IEN_U1EXTIEN BIT(9)
  440. /* ITP/SOF packet detected interrupt enable.*/
  441. #define USB_IEN_ITPIEN BIT(10)
  442. /* Wakeup interrupt enable.*/
  443. #define USB_IEN_WAKEIEN BIT(11)
  444. /* Send Custom Packet interrupt enable.*/
  445. #define USB_IEN_SPKTIEN BIT(12)
  446. /* HS/FS mode connection interrupt enable.*/
  447. #define USB_IEN_CON2IEN BIT(16)
  448. /* HS/FS mode disconnection interrupt enable.*/
  449. #define USB_IEN_DIS2IEN BIT(17)
  450. /* USB reset (HS/FS mode) interrupt enable.*/
  451. #define USB_IEN_U2RESIEN BIT(18)
  452. /* LPM L2 state enter interrupt enable.*/
  453. #define USB_IEN_L2ENTIEN BIT(20)
  454. /* LPM L2 state exit interrupt enable.*/
  455. #define USB_IEN_L2EXTIEN BIT(21)
  456. /* LPM L1 state enter interrupt enable.*/
  457. #define USB_IEN_L1ENTIEN BIT(24)
  458. /* LPM L1 state exit interrupt enable.*/
  459. #define USB_IEN_L1EXTIEN BIT(25)
  460. /* Configuration reset interrupt enable.*/
  461. #define USB_IEN_CFGRESIEN BIT(26)
  462. /* Start of the USB SS warm reset interrupt enable.*/
  463. #define USB_IEN_UWRESSIEN BIT(28)
  464. /* End of the USB SS warm reset interrupt enable.*/
  465. #define USB_IEN_UWRESEIEN BIT(29)
  466. #define USB_IEN_INIT (USB_IEN_U2RESIEN | USB_ISTS_DIS2I | USB_IEN_CON2IEN \
  467. | USB_IEN_UHRESIEN | USB_IEN_UWRESIEN | USB_IEN_DISIEN \
  468. | USB_IEN_CONIEN | USB_IEN_U3EXTIEN | USB_IEN_L2ENTIEN \
  469. | USB_IEN_L2EXTIEN | USB_IEN_L1ENTIEN | USB_IEN_U3ENTIEN)
  470. /* USB_ISTS - bitmasks */
  471. /* SS Connection detected. */
  472. #define USB_ISTS_CONI BIT(0)
  473. /* SS Disconnection detected. */
  474. #define USB_ISTS_DISI BIT(1)
  475. /* UUSB warm reset detectede. */
  476. #define USB_ISTS_UWRESI BIT(2)
  477. /* USB hot reset detected. */
  478. #define USB_ISTS_UHRESI BIT(3)
  479. /* U3 link state enter detected (suspend).*/
  480. #define USB_ISTS_U3ENTI BIT(4)
  481. /* U3 link state exit detected (wakeup). */
  482. #define USB_ISTS_U3EXTI BIT(5)
  483. /* U2 link state enter detected.*/
  484. #define USB_ISTS_U2ENTI BIT(6)
  485. /* U2 link state exit detected.*/
  486. #define USB_ISTS_U2EXTI BIT(7)
  487. /* U1 link state enter detected.*/
  488. #define USB_ISTS_U1ENTI BIT(8)
  489. /* U1 link state exit detected.*/
  490. #define USB_ISTS_U1EXTI BIT(9)
  491. /* ITP/SOF packet detected.*/
  492. #define USB_ISTS_ITPI BIT(10)
  493. /* Wakeup detected.*/
  494. #define USB_ISTS_WAKEI BIT(11)
  495. /* Send Custom Packet detected.*/
  496. #define USB_ISTS_SPKTI BIT(12)
  497. /* HS/FS mode connection detected.*/
  498. #define USB_ISTS_CON2I BIT(16)
  499. /* HS/FS mode disconnection detected.*/
  500. #define USB_ISTS_DIS2I BIT(17)
  501. /* USB reset (HS/FS mode) detected.*/
  502. #define USB_ISTS_U2RESI BIT(18)
  503. /* LPM L2 state enter detected.*/
  504. #define USB_ISTS_L2ENTI BIT(20)
  505. /* LPM L2 state exit detected.*/
  506. #define USB_ISTS_L2EXTI BIT(21)
  507. /* LPM L1 state enter detected.*/
  508. #define USB_ISTS_L1ENTI BIT(24)
  509. /* LPM L1 state exit detected.*/
  510. #define USB_ISTS_L1EXTI BIT(25)
  511. /* USB configuration reset detected.*/
  512. #define USB_ISTS_CFGRESI BIT(26)
  513. /* Start of the USB warm reset detected.*/
  514. #define USB_ISTS_UWRESSI BIT(28)
  515. /* End of the USB warm reset detected.*/
  516. #define USB_ISTS_UWRESEI BIT(29)
  517. /* USB_SEL - bitmasks */
  518. #define EP_SEL_EPNO_MASK GENMASK(3, 0)
  519. /* Endpoint number. */
  520. #define EP_SEL_EPNO(p) ((p) & EP_SEL_EPNO_MASK)
  521. /* Endpoint direction bit - 0 - OUT, 1 - IN. */
  522. #define EP_SEL_DIR BIT(7)
  523. #define select_ep_in(nr) (EP_SEL_EPNO(p) | EP_SEL_DIR)
  524. #define select_ep_out (EP_SEL_EPNO(p))
  525. /* EP_TRADDR - bitmasks */
  526. /* Transfer Ring address. */
  527. #define EP_TRADDR_TRADDR(p) ((p))
  528. /* EP_CFG - bitmasks */
  529. /* Endpoint enable */
  530. #define EP_CFG_ENABLE BIT(0)
  531. /*
  532. * Endpoint type.
  533. * 1 - isochronous
  534. * 2 - bulk
  535. * 3 - interrupt
  536. */
  537. #define EP_CFG_EPTYPE_MASK GENMASK(2, 1)
  538. #define EP_CFG_EPTYPE(p) (((p) << 1) & EP_CFG_EPTYPE_MASK)
  539. /* Stream support enable (only in SS mode). */
  540. #define EP_CFG_STREAM_EN BIT(3)
  541. /* TDL check (only in SS mode for BULK EP). */
  542. #define EP_CFG_TDL_CHK BIT(4)
  543. /* SID check (only in SS mode for BULK OUT EP). */
  544. #define EP_CFG_SID_CHK BIT(5)
  545. /* DMA transfer endianness. */
  546. #define EP_CFG_EPENDIAN BIT(7)
  547. /* Max burst size (used only in SS mode). */
  548. #define EP_CFG_MAXBURST_MASK GENMASK(11, 8)
  549. #define EP_CFG_MAXBURST(p) (((p) << 8) & EP_CFG_MAXBURST_MASK)
  550. /* ISO max burst. */
  551. #define EP_CFG_MULT_MASK GENMASK(15, 14)
  552. #define EP_CFG_MULT(p) (((p) << 14) & EP_CFG_MULT_MASK)
  553. /* ISO max burst. */
  554. #define EP_CFG_MAXPKTSIZE_MASK GENMASK(26, 16)
  555. #define EP_CFG_MAXPKTSIZE(p) (((p) << 16) & EP_CFG_MAXPKTSIZE_MASK)
  556. /* Max number of buffered packets. */
  557. #define EP_CFG_BUFFERING_MASK GENMASK(31, 27)
  558. #define EP_CFG_BUFFERING(p) (((p) << 27) & EP_CFG_BUFFERING_MASK)
  559. /* EP_CMD - bitmasks */
  560. /* Endpoint reset. */
  561. #define EP_CMD_EPRST BIT(0)
  562. /* Endpoint STALL set. */
  563. #define EP_CMD_SSTALL BIT(1)
  564. /* Endpoint STALL clear. */
  565. #define EP_CMD_CSTALL BIT(2)
  566. /* Send ERDY TP. */
  567. #define EP_CMD_ERDY BIT(3)
  568. /* Request complete. */
  569. #define EP_CMD_REQ_CMPL BIT(5)
  570. /* Transfer descriptor ready. */
  571. #define EP_CMD_DRDY BIT(6)
  572. /* Data flush. */
  573. #define EP_CMD_DFLUSH BIT(7)
  574. /*
  575. * Transfer Descriptor Length write (used only for Bulk Stream capable
  576. * endpoints in SS mode).
  577. * Bit Removed from DEV_VER_V3 controller version.
  578. */
  579. #define EP_CMD_STDL BIT(8)
  580. /*
  581. * Transfer Descriptor Length (used only in SS mode for bulk endpoints).
  582. * Bits Removed from DEV_VER_V3 controller version.
  583. */
  584. #define EP_CMD_TDL_MASK GENMASK(15, 9)
  585. #define EP_CMD_TDL_SET(p) (((p) << 9) & EP_CMD_TDL_MASK)
  586. #define EP_CMD_TDL_GET(p) (((p) & EP_CMD_TDL_MASK) >> 9)
  587. /* ERDY Stream ID value (used in SS mode). */
  588. #define EP_CMD_ERDY_SID_MASK GENMASK(31, 16)
  589. #define EP_CMD_ERDY_SID(p) (((p) << 16) & EP_CMD_ERDY_SID_MASK)
  590. /* EP_STS - bitmasks */
  591. /* Setup transfer complete. */
  592. #define EP_STS_SETUP BIT(0)
  593. /* Endpoint STALL status. */
  594. #define EP_STS_STALL(p) ((p) & BIT(1))
  595. /* Interrupt On Complete. */
  596. #define EP_STS_IOC BIT(2)
  597. /* Interrupt on Short Packet. */
  598. #define EP_STS_ISP BIT(3)
  599. /* Transfer descriptor missing. */
  600. #define EP_STS_DESCMIS BIT(4)
  601. /* Stream Rejected (used only in SS mode) */
  602. #define EP_STS_STREAMR BIT(5)
  603. /* EXIT from MOVE DATA State (used only for stream transfers in SS mode). */
  604. #define EP_STS_MD_EXIT BIT(6)
  605. /* TRB error. */
  606. #define EP_STS_TRBERR BIT(7)
  607. /* Not ready (used only in SS mode). */
  608. #define EP_STS_NRDY BIT(8)
  609. /* DMA busy bit. */
  610. #define EP_STS_DBUSY BIT(9)
  611. /* Endpoint Buffer Empty */
  612. #define EP_STS_BUFFEMPTY(p) ((p) & BIT(10))
  613. /* Current Cycle Status */
  614. #define EP_STS_CCS(p) ((p) & BIT(11))
  615. /* Prime (used only in SS mode. */
  616. #define EP_STS_PRIME BIT(12)
  617. /* Stream error (used only in SS mode). */
  618. #define EP_STS_SIDERR BIT(13)
  619. /* OUT size mismatch. */
  620. #define EP_STS_OUTSMM BIT(14)
  621. /* ISO transmission error. */
  622. #define EP_STS_ISOERR BIT(15)
  623. /* Host Packet Pending (only for SS mode). */
  624. #define EP_STS_HOSTPP(p) ((p) & BIT(16))
  625. /* Stream Protocol State Machine State (only for Bulk stream endpoints). */
  626. #define EP_STS_SPSMST_MASK GENMASK(18, 17)
  627. #define EP_STS_SPSMST_DISABLED(p) (((p) & EP_STS_SPSMST_MASK) >> 17)
  628. #define EP_STS_SPSMST_IDLE(p) (((p) & EP_STS_SPSMST_MASK) >> 17)
  629. #define EP_STS_SPSMST_START_STREAM(p) (((p) & EP_STS_SPSMST_MASK) >> 17)
  630. #define EP_STS_SPSMST_MOVE_DATA(p) (((p) & EP_STS_SPSMST_MASK) >> 17)
  631. /* Interrupt On Transfer complete. */
  632. #define EP_STS_IOT BIT(19)
  633. /* OUT queue endpoint number. */
  634. #define EP_STS_OUTQ_NO_MASK GENMASK(27, 24)
  635. #define EP_STS_OUTQ_NO(p) (((p) & EP_STS_OUTQ_NO_MASK) >> 24)
  636. /* OUT queue valid flag. */
  637. #define EP_STS_OUTQ_VAL_MASK BIT(28)
  638. #define EP_STS_OUTQ_VAL(p) ((p) & EP_STS_OUTQ_VAL_MASK)
  639. /* SETUP WAIT. */
  640. #define EP_STS_STPWAIT BIT(31)
  641. /* EP_STS_SID - bitmasks */
  642. /* Stream ID (used only in SS mode). */
  643. #define EP_STS_SID_MASK GENMASK(15, 0)
  644. #define EP_STS_SID(p) ((p) & EP_STS_SID_MASK)
  645. /* EP_STS_EN - bitmasks */
  646. /* SETUP interrupt enable. */
  647. #define EP_STS_EN_SETUPEN BIT(0)
  648. /* OUT transfer missing descriptor enable. */
  649. #define EP_STS_EN_DESCMISEN BIT(4)
  650. /* Stream Rejected enable. */
  651. #define EP_STS_EN_STREAMREN BIT(5)
  652. /* Move Data Exit enable.*/
  653. #define EP_STS_EN_MD_EXITEN BIT(6)
  654. /* TRB enable. */
  655. #define EP_STS_EN_TRBERREN BIT(7)
  656. /* NRDY enable. */
  657. #define EP_STS_EN_NRDYEN BIT(8)
  658. /* Prime enable. */
  659. #define EP_STS_EN_PRIMEEEN BIT(12)
  660. /* Stream error enable. */
  661. #define EP_STS_EN_SIDERREN BIT(13)
  662. /* OUT size mismatch enable. */
  663. #define EP_STS_EN_OUTSMMEN BIT(14)
  664. /* ISO transmission error enable. */
  665. #define EP_STS_EN_ISOERREN BIT(15)
  666. /* Interrupt on Transmission complete enable. */
  667. #define EP_STS_EN_IOTEN BIT(19)
  668. /* Setup Wait interrupt enable. */
  669. #define EP_STS_EN_STPWAITEN BIT(31)
  670. /* DRBL- bitmasks */
  671. #define DB_VALUE_BY_INDEX(index) (1 << (index))
  672. #define DB_VALUE_EP0_OUT BIT(0)
  673. #define DB_VALUE_EP0_IN BIT(16)
  674. /* EP_IEN - bitmasks */
  675. #define EP_IEN(index) (1 << (index))
  676. #define EP_IEN_EP_OUT0 BIT(0)
  677. #define EP_IEN_EP_IN0 BIT(16)
  678. /* EP_ISTS - bitmasks */
  679. #define EP_ISTS(index) (1 << (index))
  680. #define EP_ISTS_EP_OUT0 BIT(0)
  681. #define EP_ISTS_EP_IN0 BIT(16)
  682. /* USB_PWR- bitmasks */
  683. /*Power Shut Off capability enable*/
  684. #define PUSB_PWR_PSO_EN BIT(0)
  685. /*Power Shut Off capability disable*/
  686. #define PUSB_PWR_PSO_DS BIT(1)
  687. /*
  688. * Enables turning-off Reference Clock.
  689. * This bit is optional and implemented only when support for OTG is
  690. * implemented (indicated by OTG_READY bit set to '1').
  691. */
  692. #define PUSB_PWR_STB_CLK_SWITCH_EN BIT(8)
  693. /*
  694. * Status bit indicating that operation required by STB_CLK_SWITCH_EN write
  695. * is completed
  696. */
  697. #define PUSB_PWR_STB_CLK_SWITCH_DONE BIT(9)
  698. /* This bit informs if Fast Registers Access is enabled. */
  699. #define PUSB_PWR_FST_REG_ACCESS_STAT BIT(30)
  700. /* Fast Registers Access Enable. */
  701. #define PUSB_PWR_FST_REG_ACCESS BIT(31)
  702. /* USB_CONF2- bitmasks */
  703. /*
  704. * Writing 1 disables TDL calculation basing on TRB feature in controller
  705. * for DMULT mode.
  706. * Bit supported only for DEV_VER_V2 version.
  707. */
  708. #define USB_CONF2_DIS_TDL_TRB BIT(1)
  709. /*
  710. * Writing 1 enables TDL calculation basing on TRB feature in controller
  711. * for DMULT mode.
  712. * Bit supported only for DEV_VER_V2 version.
  713. */
  714. #define USB_CONF2_EN_TDL_TRB BIT(2)
  715. /* USB_CAP1- bitmasks */
  716. /*
  717. * SFR Interface type
  718. * These field reflects type of SFR interface implemented:
  719. * 0x0 - OCP
  720. * 0x1 - AHB,
  721. * 0x2 - PLB
  722. * 0x3 - AXI
  723. * 0x4-0xF - reserved
  724. */
  725. #define USB_CAP1_SFR_TYPE_MASK GENMASK(3, 0)
  726. #define DEV_SFR_TYPE_OCP(p) (((p) & USB_CAP1_SFR_TYPE_MASK) == 0x0)
  727. #define DEV_SFR_TYPE_AHB(p) (((p) & USB_CAP1_SFR_TYPE_MASK) == 0x1)
  728. #define DEV_SFR_TYPE_PLB(p) (((p) & USB_CAP1_SFR_TYPE_MASK) == 0x2)
  729. #define DEV_SFR_TYPE_AXI(p) (((p) & USB_CAP1_SFR_TYPE_MASK) == 0x3)
  730. /*
  731. * SFR Interface width
  732. * These field reflects width of SFR interface implemented:
  733. * 0x0 - 8 bit interface,
  734. * 0x1 - 16 bit interface,
  735. * 0x2 - 32 bit interface
  736. * 0x3 - 64 bit interface
  737. * 0x4-0xF - reserved
  738. */
  739. #define USB_CAP1_SFR_WIDTH_MASK GENMASK(7, 4)
  740. #define DEV_SFR_WIDTH_8(p) (((p) & USB_CAP1_SFR_WIDTH_MASK) == (0x0 << 4))
  741. #define DEV_SFR_WIDTH_16(p) (((p) & USB_CAP1_SFR_WIDTH_MASK) == (0x1 << 4))
  742. #define DEV_SFR_WIDTH_32(p) (((p) & USB_CAP1_SFR_WIDTH_MASK) == (0x2 << 4))
  743. #define DEV_SFR_WIDTH_64(p) (((p) & USB_CAP1_SFR_WIDTH_MASK) == (0x3 << 4))
  744. /*
  745. * DMA Interface type
  746. * These field reflects type of DMA interface implemented:
  747. * 0x0 - OCP
  748. * 0x1 - AHB,
  749. * 0x2 - PLB
  750. * 0x3 - AXI
  751. * 0x4-0xF - reserved
  752. */
  753. #define USB_CAP1_DMA_TYPE_MASK GENMASK(11, 8)
  754. #define DEV_DMA_TYPE_OCP(p) (((p) & USB_CAP1_DMA_TYPE_MASK) == (0x0 << 8))
  755. #define DEV_DMA_TYPE_AHB(p) (((p) & USB_CAP1_DMA_TYPE_MASK) == (0x1 << 8))
  756. #define DEV_DMA_TYPE_PLB(p) (((p) & USB_CAP1_DMA_TYPE_MASK) == (0x2 << 8))
  757. #define DEV_DMA_TYPE_AXI(p) (((p) & USB_CAP1_DMA_TYPE_MASK) == (0x3 << 8))
  758. /*
  759. * DMA Interface width
  760. * These field reflects width of DMA interface implemented:
  761. * 0x0 - reserved,
  762. * 0x1 - reserved,
  763. * 0x2 - 32 bit interface
  764. * 0x3 - 64 bit interface
  765. * 0x4-0xF - reserved
  766. */
  767. #define USB_CAP1_DMA_WIDTH_MASK GENMASK(15, 12)
  768. #define DEV_DMA_WIDTH_32(p) (((p) & USB_CAP1_DMA_WIDTH_MASK) == (0x2 << 12))
  769. #define DEV_DMA_WIDTH_64(p) (((p) & USB_CAP1_DMA_WIDTH_MASK) == (0x3 << 12))
  770. /*
  771. * USB3 PHY Interface type
  772. * These field reflects type of USB3 PHY interface implemented:
  773. * 0x0 - USB PIPE,
  774. * 0x1 - RMMI,
  775. * 0x2-0xF - reserved
  776. */
  777. #define USB_CAP1_U3PHY_TYPE_MASK GENMASK(19, 16)
  778. #define DEV_U3PHY_PIPE(p) (((p) & USB_CAP1_U3PHY_TYPE_MASK) == (0x0 << 16))
  779. #define DEV_U3PHY_RMMI(p) (((p) & USB_CAP1_U3PHY_TYPE_MASK) == (0x1 << 16))
  780. /*
  781. * USB3 PHY Interface width
  782. * These field reflects width of USB3 PHY interface implemented:
  783. * 0x0 - 8 bit PIPE interface,
  784. * 0x1 - 16 bit PIPE interface,
  785. * 0x2 - 32 bit PIPE interface,
  786. * 0x3 - 64 bit PIPE interface
  787. * 0x4-0xF - reserved
  788. * Note: When SSIC interface is implemented this field shows the width of
  789. * internal PIPE interface. The RMMI interface is always 20bit wide.
  790. */
  791. #define USB_CAP1_U3PHY_WIDTH_MASK GENMASK(23, 20)
  792. #define DEV_U3PHY_WIDTH_8(p) \
  793. (((p) & USB_CAP1_U3PHY_WIDTH_MASK) == (0x0 << 20))
  794. #define DEV_U3PHY_WIDTH_16(p) \
  795. (((p) & USB_CAP1_U3PHY_WIDTH_MASK) == (0x1 << 16))
  796. #define DEV_U3PHY_WIDTH_32(p) \
  797. (((p) & USB_CAP1_U3PHY_WIDTH_MASK) == (0x2 << 20))
  798. #define DEV_U3PHY_WIDTH_64(p) \
  799. (((p) & USB_CAP1_U3PHY_WIDTH_MASK) == (0x3 << 16))
  800. /*
  801. * USB2 PHY Interface enable
  802. * These field informs if USB2 PHY interface is implemented:
  803. * 0x0 - interface NOT implemented,
  804. * 0x1 - interface implemented
  805. */
  806. #define USB_CAP1_U2PHY_EN(p) ((p) & BIT(24))
  807. /*
  808. * USB2 PHY Interface type
  809. * These field reflects type of USB2 PHY interface implemented:
  810. * 0x0 - UTMI,
  811. * 0x1 - ULPI
  812. */
  813. #define DEV_U2PHY_ULPI(p) ((p) & BIT(25))
  814. /*
  815. * USB2 PHY Interface width
  816. * These field reflects width of USB2 PHY interface implemented:
  817. * 0x0 - 8 bit interface,
  818. * 0x1 - 16 bit interface,
  819. * Note: The ULPI interface is always 8bit wide.
  820. */
  821. #define DEV_U2PHY_WIDTH_16(p) ((p) & BIT(26))
  822. /*
  823. * OTG Ready
  824. * 0x0 - pure device mode
  825. * 0x1 - some features and ports for CDNS USB OTG controller are implemented.
  826. */
  827. #define USB_CAP1_OTG_READY(p) ((p) & BIT(27))
  828. /*
  829. * When set, indicates that controller supports automatic internal TDL
  830. * calculation basing on the size provided in TRB (TRB[22:17]) for DMULT mode
  831. * Supported only for DEV_VER_V2 controller version.
  832. */
  833. #define USB_CAP1_TDL_FROM_TRB(p) ((p) & BIT(28))
  834. /* USB_CAP2- bitmasks */
  835. /*
  836. * The actual size of the connected On-chip RAM memory in kB:
  837. * - 0 means 256 kB (max supported mem size)
  838. * - value other than 0 reflects the mem size in kB
  839. */
  840. #define USB_CAP2_ACTUAL_MEM_SIZE(p) ((p) & GENMASK(7, 0))
  841. /*
  842. * Max supported mem size
  843. * These field reflects width of on-chip RAM address bus width,
  844. * which determines max supported mem size:
  845. * 0x0-0x7 - reserved,
  846. * 0x8 - support for 4kB mem,
  847. * 0x9 - support for 8kB mem,
  848. * 0xA - support for 16kB mem,
  849. * 0xB - support for 32kB mem,
  850. * 0xC - support for 64kB mem,
  851. * 0xD - support for 128kB mem,
  852. * 0xE - support for 256kB mem,
  853. * 0xF - reserved
  854. */
  855. #define USB_CAP2_MAX_MEM_SIZE(p) ((p) & GENMASK(11, 8))
  856. /* USB_CAP3- bitmasks */
  857. #define EP_IS_IMPLEMENTED(reg, index) ((reg) & (1 << (index)))
  858. /* USB_CAP4- bitmasks */
  859. #define EP_SUPPORT_ISO(reg, index) ((reg) & (1 << (index)))
  860. /* USB_CAP5- bitmasks */
  861. #define EP_SUPPORT_STREAM(reg, index) ((reg) & (1 << (index)))
  862. /* USB_CAP6- bitmasks */
  863. /* The USBSS-DEV Controller Internal build number. */
  864. #define GET_DEV_BASE_VERSION(p) ((p) & GENMASK(23, 0))
  865. /* The USBSS-DEV Controller version number. */
  866. #define GET_DEV_CUSTOM_VERSION(p) ((p) & GENMASK(31, 24))
  867. #define DEV_VER_NXP_V1 0x00024502
  868. #define DEV_VER_TI_V1 0x00024509
  869. #define DEV_VER_V2 0x0002450C
  870. #define DEV_VER_V3 0x0002450d
  871. /* DBG_LINK1- bitmasks */
  872. /*
  873. * LFPS_MIN_DET_U1_EXIT value This parameter configures the minimum
  874. * time required for decoding the received LFPS as an LFPS.U1_Exit.
  875. */
  876. #define DBG_LINK1_LFPS_MIN_DET_U1_EXIT(p) ((p) & GENMASK(7, 0))
  877. /*
  878. * LFPS_MIN_GEN_U1_EXIT value This parameter configures the minimum time for
  879. * phytxelecidle deassertion when LFPS.U1_Exit
  880. */
  881. #define DBG_LINK1_LFPS_MIN_GEN_U1_EXIT_MASK GENMASK(15, 8)
  882. #define DBG_LINK1_LFPS_MIN_GEN_U1_EXIT(p) (((p) << 8) & GENMASK(15, 8))
  883. /*
  884. * RXDET_BREAK_DIS value This parameter configures terminating the Far-end
  885. * Receiver termination detection sequence:
  886. * 0: it is possible that USBSS_DEV will terminate Farend receiver
  887. * termination detection sequence
  888. * 1: USBSS_DEV will not terminate Far-end receiver termination
  889. * detection sequence
  890. */
  891. #define DBG_LINK1_RXDET_BREAK_DIS BIT(16)
  892. /* LFPS_GEN_PING value This parameter configures the LFPS.Ping generation */
  893. #define DBG_LINK1_LFPS_GEN_PING(p) (((p) << 17) & GENMASK(21, 17))
  894. /*
  895. * Set the LFPS_MIN_DET_U1_EXIT value Writing '1' to this bit writes the
  896. * LFPS_MIN_DET_U1_EXIT field value to the device. This bit is automatically
  897. * cleared. Writing '0' has no effect
  898. */
  899. #define DBG_LINK1_LFPS_MIN_DET_U1_EXIT_SET BIT(24)
  900. /*
  901. * Set the LFPS_MIN_GEN_U1_EXIT value. Writing '1' to this bit writes the
  902. * LFPS_MIN_GEN_U1_EXIT field value to the device. This bit is automatically
  903. * cleared. Writing '0' has no effect
  904. */
  905. #define DBG_LINK1_LFPS_MIN_GEN_U1_EXIT_SET BIT(25)
  906. /*
  907. * Set the RXDET_BREAK_DIS value Writing '1' to this bit writes
  908. * the RXDET_BREAK_DIS field value to the device. This bit is automatically
  909. * cleared. Writing '0' has no effect
  910. */
  911. #define DBG_LINK1_RXDET_BREAK_DIS_SET BIT(26)
  912. /*
  913. * Set the LFPS_GEN_PING_SET value Writing '1' to this bit writes
  914. * the LFPS_GEN_PING field value to the device. This bit is automatically
  915. * cleared. Writing '0' has no effect."
  916. */
  917. #define DBG_LINK1_LFPS_GEN_PING_SET BIT(27)
  918. /* DMA_AXI_CTRL- bitmasks */
  919. /* The mawprot pin configuration. */
  920. #define DMA_AXI_CTRL_MARPROT(p) ((p) & GENMASK(2, 0))
  921. /* The marprot pin configuration. */
  922. #define DMA_AXI_CTRL_MAWPROT(p) (((p) & GENMASK(2, 0)) << 16)
  923. #define DMA_AXI_CTRL_NON_SECURE 0x02
  924. #define gadget_to_cdns3_device(g) (container_of(g, struct cdns3_device, gadget))
  925. #define ep_to_cdns3_ep(ep) (container_of(ep, struct cdns3_endpoint, endpoint))
  926. /*-------------------------------------------------------------------------*/
  927. /*
  928. * USBSS-DEV DMA interface.
  929. */
  930. #define TRBS_PER_SEGMENT 40
  931. #define ISO_MAX_INTERVAL 10
  932. #if TRBS_PER_SEGMENT < 2
  933. #error "Incorrect TRBS_PER_SEGMENT. Minimal Transfer Ring size is 2."
  934. #endif
  935. /*
  936. *Only for ISOC endpoints - maximum number of TRBs is calculated as
  937. * pow(2, bInterval-1) * number of usb requests. It is limitation made by
  938. * driver to save memory. Controller must prepare TRB for each ITP even
  939. * if bInterval > 1. It's the reason why driver needs so many TRBs for
  940. * isochronous endpoints.
  941. */
  942. #define TRBS_PER_ISOC_SEGMENT (ISO_MAX_INTERVAL * 8)
  943. #define GET_TRBS_PER_SEGMENT(ep_type) ((ep_type) == USB_ENDPOINT_XFER_ISOC ? \
  944. TRBS_PER_ISOC_SEGMENT : TRBS_PER_SEGMENT)
  945. /**
  946. * struct cdns3_trb - represent Transfer Descriptor block.
  947. * @buffer: pointer to buffer data
  948. * @length: length of data
  949. * @control: control flags.
  950. *
  951. * This structure describes transfer block serviced by DMA module.
  952. */
  953. struct cdns3_trb {
  954. __le32 buffer;
  955. __le32 length;
  956. __le32 control;
  957. };
  958. #define TRB_SIZE (sizeof(struct cdns3_trb))
  959. #define TRB_RING_SIZE (TRB_SIZE * TRBS_PER_SEGMENT)
  960. #define TRB_ISO_RING_SIZE (TRB_SIZE * TRBS_PER_ISOC_SEGMENT)
  961. #define TRB_CTRL_RING_SIZE (TRB_SIZE * 2)
  962. /* TRB bit mask */
  963. #define TRB_TYPE_BITMASK GENMASK(15, 10)
  964. #define TRB_TYPE(p) ((p) << 10)
  965. #define TRB_FIELD_TO_TYPE(p) (((p) & TRB_TYPE_BITMASK) >> 10)
  966. /* TRB type IDs */
  967. /* bulk, interrupt, isoc , and control data stage */
  968. #define TRB_NORMAL 1
  969. /* TRB for linking ring segments */
  970. #define TRB_LINK 6
  971. /* Cycle bit - indicates TRB ownership by driver or hw*/
  972. #define TRB_CYCLE BIT(0)
  973. /*
  974. * When set to '1', the device will toggle its interpretation of the Cycle bit
  975. */
  976. #define TRB_TOGGLE BIT(1)
  977. /*
  978. * Short Packet (SP). OUT EPs at DMULT=1 only. Indicates if the TRB was
  979. * processed while USB short packet was received. No more buffers defined by
  980. * the TD will be used. DMA will automatically advance to next TD.
  981. * - Shall be set to 0 by Software when putting TRB on the Transfer Ring
  982. * - Shall be set to 1 by Controller when Short Packet condition for this TRB
  983. * is detected independent if ISP is set or not.
  984. */
  985. #define TRB_SP BIT(1)
  986. /* Interrupt on short packet*/
  987. #define TRB_ISP BIT(2)
  988. /*Setting this bit enables FIFO DMA operation mode*/
  989. #define TRB_FIFO_MODE BIT(3)
  990. /* Set PCIe no snoop attribute */
  991. #define TRB_CHAIN BIT(4)
  992. /* Interrupt on completion */
  993. #define TRB_IOC BIT(5)
  994. /* stream ID bitmasks. */
  995. #define TRB_STREAM_ID_BITMASK GENMASK(31, 16)
  996. #define TRB_STREAM_ID(p) ((p) << 16)
  997. #define TRB_FIELD_TO_STREAMID(p) (((p) & TRB_STREAM_ID_BITMASK) >> 16)
  998. /* Size of TD expressed in USB packets for HS/FS mode. */
  999. #define TRB_TDL_HS_SIZE(p) (((p) << 16) & GENMASK(31, 16))
  1000. #define TRB_TDL_HS_SIZE_GET(p) (((p) & GENMASK(31, 16)) >> 16)
  1001. /* transfer_len bitmasks. */
  1002. #define TRB_LEN(p) ((p) & GENMASK(16, 0))
  1003. /* Size of TD expressed in USB packets for SS mode. */
  1004. #define TRB_TDL_SS_SIZE(p) (((p) << 17) & GENMASK(23, 17))
  1005. #define TRB_TDL_SS_SIZE_GET(p) (((p) & GENMASK(23, 17)) >> 17)
  1006. /* transfer_len bitmasks - bits 31:24 */
  1007. #define TRB_BURST_LEN(p) (((p) << 24) & GENMASK(31, 24))
  1008. #define TRB_BURST_LEN_GET(p) (((p) & GENMASK(31, 24)) >> 24)
  1009. /* Data buffer pointer bitmasks*/
  1010. #define TRB_BUFFER(p) ((p) & GENMASK(31, 0))
  1011. /*-------------------------------------------------------------------------*/
  1012. /* Driver numeric constants */
  1013. /* Such declaration should be added to ch9.h */
  1014. #define USB_DEVICE_MAX_ADDRESS 127
  1015. /* Endpoint init values */
  1016. #define CDNS3_EP_MAX_PACKET_LIMIT 1024
  1017. #define CDNS3_EP_MAX_STREAMS 15
  1018. #define CDNS3_EP0_MAX_PACKET_LIMIT 512
  1019. /* All endpoints including EP0 */
  1020. #define CDNS3_ENDPOINTS_MAX_COUNT 32
  1021. #define CDNS3_EP_ZLP_BUF_SIZE 1024
  1022. #define CDNS3_EP_BUF_SIZE 2 /* KB */
  1023. #define CDNS3_EP_ISO_HS_MULT 3
  1024. #define CDNS3_EP_ISO_SS_BURST 3
  1025. #define CDNS3_MAX_NUM_DESCMISS_BUF 32
  1026. #define CDNS3_DESCMIS_BUF_SIZE 2048 /* Bytes */
  1027. #define CDNS3_WA2_NUM_BUFFERS 128
  1028. /*-------------------------------------------------------------------------*/
  1029. /* Used structs */
  1030. struct cdns3_device;
  1031. /**
  1032. * struct cdns3_endpoint - extended device side representation of USB endpoint.
  1033. * @endpoint: usb endpoint
  1034. * @pending_req_list: list of requests queuing on transfer ring.
  1035. * @deferred_req_list: list of requests waiting for queuing on transfer ring.
  1036. * @wa2_descmiss_req_list: list of requests internally allocated by driver.
  1037. * @trb_pool: transfer ring - array of transaction buffers
  1038. * @trb_pool_dma: dma address of transfer ring
  1039. * @cdns3_dev: device associated with this endpoint
  1040. * @name: a human readable name e.g. ep1out
  1041. * @flags: specify the current state of endpoint
  1042. * @descmis_req: internal transfer object used for getting data from on-chip
  1043. * buffer. It can happen only if function driver doesn't send usb_request
  1044. * object on time.
  1045. * @dir: endpoint direction
  1046. * @num: endpoint number (1 - 15)
  1047. * @type: set to bmAttributes & USB_ENDPOINT_XFERTYPE_MASK
  1048. * @interval: interval between packets used for ISOC endpoint.
  1049. * @free_trbs: number of free TRBs in transfer ring
  1050. * @num_trbs: number of all TRBs in transfer ring
  1051. * @pcs: producer cycle state
  1052. * @ccs: consumer cycle state
  1053. * @enqueue: enqueue index in transfer ring
  1054. * @dequeue: dequeue index in transfer ring
  1055. * @trb_burst_size: number of burst used in trb.
  1056. */
  1057. struct cdns3_endpoint {
  1058. struct usb_ep endpoint;
  1059. struct list_head pending_req_list;
  1060. struct list_head deferred_req_list;
  1061. struct list_head wa2_descmiss_req_list;
  1062. int wa2_counter;
  1063. struct cdns3_trb *trb_pool;
  1064. dma_addr_t trb_pool_dma;
  1065. struct cdns3_device *cdns3_dev;
  1066. char name[20];
  1067. #define EP_ENABLED BIT(0)
  1068. #define EP_STALLED BIT(1)
  1069. #define EP_STALL_PENDING BIT(2)
  1070. #define EP_WEDGE BIT(3)
  1071. #define EP_TRANSFER_STARTED BIT(4)
  1072. #define EP_UPDATE_EP_TRBADDR BIT(5)
  1073. #define EP_PENDING_REQUEST BIT(6)
  1074. #define EP_RING_FULL BIT(7)
  1075. #define EP_CLAIMED BIT(8)
  1076. #define EP_DEFERRED_DRDY BIT(9)
  1077. #define EP_QUIRK_ISO_OUT_EN BIT(10)
  1078. #define EP_QUIRK_END_TRANSFER BIT(11)
  1079. #define EP_QUIRK_EXTRA_BUF_DET BIT(12)
  1080. #define EP_QUIRK_EXTRA_BUF_EN BIT(13)
  1081. u32 flags;
  1082. struct cdns3_request *descmis_req;
  1083. u8 dir;
  1084. u8 num;
  1085. u8 type;
  1086. int interval;
  1087. int free_trbs;
  1088. int num_trbs;
  1089. u8 pcs;
  1090. u8 ccs;
  1091. int enqueue;
  1092. int dequeue;
  1093. u8 trb_burst_size;
  1094. unsigned int wa1_set:1;
  1095. struct cdns3_trb *wa1_trb;
  1096. unsigned int wa1_trb_index;
  1097. unsigned int wa1_cycle_bit:1;
  1098. };
  1099. /**
  1100. * struct cdns3_aligned_buf - represent aligned buffer used for DMA transfer
  1101. * @buf: aligned to 8 bytes data buffer. Buffer address used in
  1102. * TRB shall be aligned to 8.
  1103. * @dma: dma address
  1104. * @size: size of buffer
  1105. * @in_use: inform if this buffer is associated with usb_request
  1106. * @list: used to adding instance of this object to list
  1107. */
  1108. struct cdns3_aligned_buf {
  1109. void *buf;
  1110. dma_addr_t dma;
  1111. u32 size;
  1112. int in_use:1;
  1113. struct list_head list;
  1114. };
  1115. /**
  1116. * struct cdns3_request - extended device side representation of usb_request
  1117. * object .
  1118. * @request: generic usb_request object describing single I/O request.
  1119. * @priv_ep: extended representation of usb_ep object
  1120. * @trb: the first TRB association with this request
  1121. * @start_trb: number of the first TRB in transfer ring
  1122. * @end_trb: number of the last TRB in transfer ring
  1123. * @aligned_buf: object holds information about aligned buffer associated whit
  1124. * this endpoint
  1125. * @flags: flag specifying special usage of request
  1126. * @list: used by internally allocated request to add to wa2_descmiss_req_list.
  1127. */
  1128. struct cdns3_request {
  1129. struct usb_request request;
  1130. struct cdns3_endpoint *priv_ep;
  1131. struct cdns3_trb *trb;
  1132. int start_trb;
  1133. int end_trb;
  1134. struct cdns3_aligned_buf *aligned_buf;
  1135. #define REQUEST_PENDING BIT(0)
  1136. #define REQUEST_INTERNAL BIT(1)
  1137. #define REQUEST_INTERNAL_CH BIT(2)
  1138. #define REQUEST_ZLP BIT(3)
  1139. #define REQUEST_UNALIGNED BIT(4)
  1140. u32 flags;
  1141. struct list_head list;
  1142. };
  1143. #define to_cdns3_request(r) (container_of(r, struct cdns3_request, request))
  1144. /*Stages used during enumeration process.*/
  1145. #define CDNS3_SETUP_STAGE 0x0
  1146. #define CDNS3_DATA_STAGE 0x1
  1147. #define CDNS3_STATUS_STAGE 0x2
  1148. /**
  1149. * struct cdns3_device - represent USB device.
  1150. * @dev: pointer to device structure associated whit this controller
  1151. * @sysdev: pointer to the DMA capable device
  1152. * @gadget: device side representation of the peripheral controller
  1153. * @gadget_driver: pointer to the gadget driver
  1154. * @dev_ver: device controller version.
  1155. * @lock: for synchronizing
  1156. * @regs: base address for device side registers
  1157. * @setup_buf: used while processing usb control requests
  1158. * @setup_dma: dma address for setup_buf
  1159. * @zlp_buf - zlp buffer
  1160. * @ep0_stage: ep0 stage during enumeration process.
  1161. * @ep0_data_dir: direction for control transfer
  1162. * @eps: array of pointers to all endpoints with exclusion ep0
  1163. * @aligned_buf_list: list of aligned buffers internally allocated by driver
  1164. * @aligned_buf_wq: workqueue freeing no longer used aligned buf.
  1165. * @selected_ep: actually selected endpoint. It's used only to improve
  1166. * performance.
  1167. * @isoch_delay: value from Set Isoch Delay request. Only valid on SS/SSP.
  1168. * @u1_allowed: allow device transition to u1 state
  1169. * @u2_allowed: allow device transition to u2 state
  1170. * @is_selfpowered: device is self powered
  1171. * @setup_pending: setup packet is processing by gadget driver
  1172. * @hw_configured_flag: hardware endpoint configuration was set.
  1173. * @wake_up_flag: allow device to remote up the host
  1174. * @status_completion_no_call: indicate that driver is waiting for status s
  1175. * stage completion. It's used in deferred SET_CONFIGURATION request.
  1176. * @onchip_buffers: number of available on-chip buffers.
  1177. * @onchip_used_size: actual size of on-chip memory assigned to endpoints.
  1178. * @pending_status_wq: workqueue handling status stage for deferred requests.
  1179. * @pending_status_request: request for which status stage was deferred
  1180. */
  1181. struct cdns3_device {
  1182. struct device *dev;
  1183. struct device *sysdev;
  1184. struct usb_gadget gadget;
  1185. struct usb_gadget_driver *gadget_driver;
  1186. #define CDNS_REVISION_V0 0x00024501
  1187. #define CDNS_REVISION_V1 0x00024509
  1188. u32 dev_ver;
  1189. /* generic spin-lock for drivers */
  1190. spinlock_t lock;
  1191. struct cdns3_usb_regs __iomem *regs;
  1192. struct usb_ctrlrequest *setup_buf;
  1193. dma_addr_t setup_dma;
  1194. void *zlp_buf;
  1195. u8 ep0_stage;
  1196. int ep0_data_dir;
  1197. struct cdns3_endpoint *eps[CDNS3_ENDPOINTS_MAX_COUNT];
  1198. struct list_head aligned_buf_list;
  1199. struct work_struct aligned_buf_wq;
  1200. u32 selected_ep;
  1201. u16 isoch_delay;
  1202. unsigned wait_for_setup:1;
  1203. unsigned u1_allowed:1;
  1204. unsigned u2_allowed:1;
  1205. unsigned is_selfpowered:1;
  1206. unsigned setup_pending:1;
  1207. int hw_configured_flag:1;
  1208. int wake_up_flag:1;
  1209. unsigned status_completion_no_call:1;
  1210. int out_mem_is_allocated;
  1211. struct work_struct pending_status_wq;
  1212. struct usb_request *pending_status_request;
  1213. /*in KB */
  1214. u16 onchip_buffers;
  1215. u16 onchip_used_size;
  1216. };
  1217. void cdns3_set_register_bit(void __iomem *ptr, u32 mask);
  1218. dma_addr_t cdns3_trb_virt_to_dma(struct cdns3_endpoint *priv_ep,
  1219. struct cdns3_trb *trb);
  1220. enum usb_device_speed cdns3_get_speed(struct cdns3_device *priv_dev);
  1221. void cdns3_pending_setup_status_handler(struct work_struct *work);
  1222. void cdns3_hw_reset_eps_config(struct cdns3_device *priv_dev);
  1223. void cdns3_set_hw_configuration(struct cdns3_device *priv_dev);
  1224. void cdns3_select_ep(struct cdns3_device *priv_dev, u32 ep);
  1225. void cdns3_allow_enable_l1(struct cdns3_device *priv_dev, int enable);
  1226. struct usb_request *cdns3_next_request(struct list_head *list);
  1227. int cdns3_ep_run_transfer(struct cdns3_endpoint *priv_ep,
  1228. struct usb_request *request);
  1229. void cdns3_rearm_transfer(struct cdns3_endpoint *priv_ep, u8 rearm);
  1230. int cdns3_allocate_trb_pool(struct cdns3_endpoint *priv_ep);
  1231. u8 cdns3_ep_addr_to_index(u8 ep_addr);
  1232. int cdns3_gadget_ep_set_wedge(struct usb_ep *ep);
  1233. int cdns3_gadget_ep_set_halt(struct usb_ep *ep, int value);
  1234. void __cdns3_gadget_ep_set_halt(struct cdns3_endpoint *priv_ep);
  1235. int __cdns3_gadget_ep_clear_halt(struct cdns3_endpoint *priv_ep);
  1236. struct usb_request *cdns3_gadget_ep_alloc_request(struct usb_ep *ep,
  1237. gfp_t gfp_flags);
  1238. void cdns3_gadget_ep_free_request(struct usb_ep *ep,
  1239. struct usb_request *request);
  1240. int cdns3_gadget_ep_dequeue(struct usb_ep *ep, struct usb_request *request);
  1241. void cdns3_gadget_giveback(struct cdns3_endpoint *priv_ep,
  1242. struct cdns3_request *priv_req,
  1243. int status);
  1244. int cdns3_init_ep0(struct cdns3_device *priv_dev,
  1245. struct cdns3_endpoint *priv_ep);
  1246. void cdns3_ep0_config(struct cdns3_device *priv_dev);
  1247. void cdns3_ep_config(struct cdns3_endpoint *priv_ep);
  1248. void cdns3_check_ep0_interrupt_proceed(struct cdns3_device *priv_dev, int dir);
  1249. int __cdns3_gadget_wakeup(struct cdns3_device *priv_dev);
  1250. #endif /* __LINUX_CDNS3_GADGET */