usb_aotg_woodpecker.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832
  1. /*
  2. * Copyright (c) 2020 Actions Corporation.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /**
  7. * @file
  8. * @brief USB Actions OTG controller (woodpecker) driver private definitions
  9. *
  10. * This file contains the Actions OTG USB controller (woodpecker) driver private
  11. * definitions.
  12. */
  13. #ifndef __USB_AOTG_WOODPECKER_H__
  14. #define __USB_AOTG_WOODPECKER_H__
  15. /* USB IN EP index */
  16. enum usb_aotg_in_ep_idx {
  17. USB_AOTG_IN_EP_0 = 0,
  18. USB_AOTG_IN_EP_1,
  19. USB_AOTG_IN_EP_2,
  20. USB_AOTG_IN_EP_3,
  21. USB_AOTG_IN_EP_NUM
  22. };
  23. /* USB OUT EP index */
  24. enum usb_aotg_out_ep_idx {
  25. USB_AOTG_OUT_EP_0 = 0,
  26. USB_AOTG_OUT_EP_1,
  27. USB_AOTG_OUT_EP_2,
  28. USB_AOTG_OUT_EP_NUM
  29. };
  30. /*********************************** Common **********************************/
  31. /* FIFO Clock */
  32. #define USB_MEM_CLK CMU_MEMCLKSRC
  33. #define USB_MEM_CLK_URAM 13
  34. /* USB AOTG IRQ line */
  35. #define USB_AOTG_IRQ IRQ_ID_USB
  36. /* USB DM: GPIO10 */
  37. #define USB_DM_GPIO 0xC0090028
  38. #define USB_DM_VALUE 0x4004
  39. /* USB DP: GPIO11 */
  40. #define USB_DP_GPIO 0xC009002C
  41. #define USB_DP_VALUE 0x4004
  42. /*********************************** Global **********************************/
  43. /* USB AOTG Base Address */
  44. #define USB_AOTG_BASE 0xC0080000
  45. /** Debug */
  46. #define USBDEBUG (USB_AOTG_BASE + 0x404)
  47. #define USBDEBUG_EN 4
  48. #define USBDEBUG_MODE_MASK 0x0F
  49. /** Line Status */
  50. #define LINESTATUS (USB_AOTG_BASE + 0x419)
  51. #define LINE_DM 4
  52. #define LINE_DP 3
  53. #define LINESTATE_MASK (0x3 << 3)
  54. #define LINESTATE_DM (1 << LINE_DM)
  55. #define LINESTATE_DP (1 << LINE_DP)
  56. #define OTGRESET 0
  57. /** DPDM */
  58. #define DPDMCTRL (USB_AOTG_BASE + 0x41A)
  59. /* plug-in (connect/disconnect) */
  60. #define PLUGIN 6
  61. /* Line status detect enable (default: enable) */
  62. #define LSDETEN 4
  63. /* 500K pull-up enable */
  64. #define DM_PULL_UP 3
  65. #define DP_PULL_UP 2
  66. /* 15K pull-down disable */
  67. #define DM_PULL_DOWN 1
  68. #define DP_PULL_DOWN 0
  69. #define DPDM_DEVICE (0x1F)
  70. #define DPDM_HOST (0x10)
  71. /** Idpin & Vbus */
  72. #define IDVBUSCTRL (USB_AOTG_BASE + 0x418)
  73. #define SOFT_IDPIN 3
  74. #define SOFT_IDEN 2
  75. #define IDVBUS_DEVICE (0x0C)
  76. #define IDVBUS_HOST (0x04)
  77. /** Auto In mode IN Token timer */
  78. #define AUTOINTIMER (USB_AOTG_BASE + 0x41E)
  79. /** USB Control and Status */
  80. #define USBCS (USB_AOTG_BASE + 0x1A3)
  81. /* Soft disconnect */
  82. #define USBCS_DISCONN 6
  83. /* Remote wakeup */
  84. #define USBCS_WAKEUP 5
  85. #define USBCS_SPEED 1
  86. #define USBCS_LS 0
  87. /** Device Address */
  88. #define FNADDR (USB_AOTG_BASE + 0x1A6)
  89. /* USB Clock Gate */
  90. #define USBCLKGATE (USB_AOTG_BASE + 0x1A7)
  91. #define CLKGATE_SUSPEND 0
  92. /** USB OTG FSM State */
  93. #define USBSTATE (USB_AOTG_BASE + 0x1BD)
  94. /* Alias */
  95. #define OTGSTATE USBSTATE
  96. #define OTG_A_IDLE 0x0
  97. #define OTG_A_WAIT_BCON 0x2
  98. #define OTG_A_HOST 0x3
  99. #define OTG_A_SUSPEND 0x4
  100. #define OTG_B_IDLE 0x8
  101. #define OTG_B_PERIPHERAL 0x9
  102. /** USB OTG FSM Control */
  103. #define USBCTRL (USB_AOTG_BASE + 0x1BE)
  104. /* Alias */
  105. #define OTGCTRL USBCTRL
  106. #define OTGCTRL_FORCE 7
  107. #define OTGCTRL_BUSREQ 0
  108. /** USB Status */
  109. #define USBSTATUS (USB_AOTG_BASE + 0x1BF)
  110. /* 0: mini-A; 1: mini-B */
  111. #define USBSTATUS_ID 6
  112. #define USBSTATUS_CONN 1
  113. /************************************ IRQ ************************************/
  114. /** USB Core */
  115. #define USBIEN (USB_AOTG_BASE + 0x198)
  116. #define USBIEN_NTR 6
  117. #define USBIEN_HS 5
  118. #define USBIEN_RESET 4
  119. #define USBIEN_SUSPEND 3
  120. #define USBIEN_TOKEN 2
  121. #define USBIEN_SOF 1
  122. #define USBIEN_SETUP 0
  123. #define USBIRQ (USB_AOTG_BASE + 0x18C)
  124. #define USBIRQ_NTR 6
  125. /* High-speed */
  126. #define USBIRQ_HS 5
  127. /* USB Bus Reset */
  128. #define USBIRQ_RESET 4
  129. /* Suspend Signal */
  130. #define USBIRQ_SUSPEND 3
  131. /* SETUP Token */
  132. #define USBIRQ_TOKEN 2
  133. /* SOF Packet */
  134. #define USBIRQ_SOF 1
  135. /* SETUP Data */
  136. #define USBIRQ_SETUP 0
  137. /** OTG FSM */
  138. #define OTGIEN (USB_AOTG_BASE + 0x1C0)
  139. /* a_peripheral/b_peripheral */
  140. #define OTGIEN_PERIPHERAL 4
  141. /* a_host/b_host */
  142. #define OTGIEN_LOCSOF 2
  143. /* a_idle/b_idle */
  144. #define OTGIEN_IDLE 0
  145. #define OTGIRQ (USB_AOTG_BASE + 0x1BC)
  146. #define OTGIRQ_PERIPHERAL 4
  147. #define OTGIRQ_LOCSOF 2
  148. #define OTGIRQ_IDLE 0
  149. /** Specific OTG FSM IRQ */
  150. #define OTGSTATE_IEN (USB_AOTG_BASE + 0x410)
  151. #define OTGSTATE_IRQ (USB_AOTG_BASE + 0x411)
  152. #define OTGSTATE_A_WAIT_BCON 1
  153. #define OTGSTATE_A_SUSPEND 0
  154. /** USB External Interrupt request */
  155. #define USBEIRQ (USB_AOTG_BASE + 0x400)
  156. /* Alias: same register */
  157. #define USBEIEN USBEIRQ
  158. /* External */
  159. #define USBEIRQ_EXTERN 7
  160. /* Wakeup */
  161. #define USBEIRQ_WAKEUP 6
  162. /* Resume */
  163. #define USBEIRQ_RESUME 5
  164. /* Connnect/disconnect */
  165. #define USBEIRQ_CONDISC 4
  166. /* External */
  167. #define USBEIEN_EXTERN 3
  168. /* Wakeup */
  169. #define USBEIEN_WAKEUP 2
  170. /* Resume */
  171. #define USBEIEN_RESUME 1
  172. /* Connnect/disconnect */
  173. #define USBEIEN_CONDISC 0
  174. #define USBEIEN_MASK (0x0f)
  175. #define USBEIRQ_MASK (0xf0)
  176. /** Interrupt Vector */
  177. #define IVECT (USB_AOTG_BASE + 0x1A0)
  178. /* Device */
  179. /* Setup Data */
  180. #define UIV_SUDAV 0x00
  181. #define UIV_SOF 0x04
  182. /* Setup Token */
  183. #define UIV_SUTOK 0x08
  184. #define UIV_SUSPEND 0x0c
  185. #define UIV_USBRST 0x10
  186. #define UIV_HSPEED 0x14
  187. /* Endpoint */
  188. #define UIV_HCOUT0ERR 0x16
  189. #define UIV_EP0IN 0x18
  190. #define UIV_HCIN0ERR 0x1a
  191. #define UIV_EP0OUT 0x1c
  192. #define UIV_EP0PING 0x20
  193. #define UIV_HCOUT1ERR 0x22
  194. #define UIV_EP1IN 0x24
  195. #define UIV_HCIN1ERR 0x26
  196. #define UIV_EP1OUT 0x28
  197. #define UIV_EP1PING 0x2c
  198. #define UIV_HCOUT2ERR 0x2e
  199. #define UIV_EP2IN 0x30
  200. #define UIV_HCIN2ERR 0x32
  201. #define UIV_EP2OUT 0x34
  202. #define UIV_EP2PING 0x38
  203. #define UIV_HCOUT3ERR 0x3a
  204. #define UIV_EP3IN 0x3c
  205. #define UIV_HCIN3ERR 0x3e
  206. #define UIV_EP3OUT 0x40
  207. #define UIV_EP3PING 0x44
  208. #define UIV_OTGIRQ 0xd8
  209. /* IN Token */
  210. #define UIV_INTOKEN 0xe0
  211. /* OUT Token */
  212. #define UIV_OUTTOKEN 0xe4
  213. /* Controller */
  214. #define UIV_RESUME 0xe6
  215. #define UIV_CONDISC 0xe8
  216. /* OTG */
  217. #define UIV_OTGSTATE 0xea
  218. /* EP OUT Short Packet */
  219. #define UIV_EPOUTSHTPKT 0xec
  220. #define UIV_HCINEND 0xee
  221. #define UIV_HCOUTEMPTY 0xf0
  222. #define UIV_NTR 0xf2
  223. #define UIV_EPIN_VEC2ADDR(vector) ((vector - UIV_EP0IN) / 12)
  224. #define UIV_EPOUT_VEC2ADDR(vector) ((vector - UIV_EP0OUT) / 12)
  225. #define UIV_HCINERR_VEC2ADDR(vector) ((vector - UIV_HCIN0ERR) / 12)
  226. #define UIV_HCOUTERR_VEC2ADDR(vector) ((vector - UIV_HCOUT0ERR) / 12)
  227. /** Endpoint Interrupt request */
  228. /* OUT IRQ */
  229. #define OUTIEN (USB_AOTG_BASE + 0x196)
  230. #define OUTIRQ (USB_AOTG_BASE + 0x18A)
  231. #define IRQ_EP0OUT 0
  232. #define IRQ_EP1OUT 1
  233. #define IRQ_EP2OUT 2
  234. #define IRQ_EPxOUT(ep) (ep)
  235. /** OUT Endpoints Short Packet Control */
  236. #define OUT_SHTPKT (USB_AOTG_BASE + 0x403)
  237. #define IRQ_EP2OUT_SHTPKT 6
  238. #define IRQ_EP1OUT_SHTPKT 5
  239. #define IEN_EP2OUT_SHTPKT 2
  240. #define IEN_EP1OUT_SHTPKT 1
  241. /* IN IRQ */
  242. #define INIEN (USB_AOTG_BASE + 0x194)
  243. #define INIRQ (USB_AOTG_BASE + 0x188)
  244. #define IRQ_EP0IN 0
  245. #define IRQ_EP1IN 1
  246. #define IRQ_EP2IN 2
  247. #define IRQ_EP3IN 3
  248. #define IRQ_EPxIN(ep) (ep)
  249. /** IN buffer empty IRQ/IEN */
  250. #define INEMPTY_IRQ (USB_AOTG_BASE + 0x406)
  251. #define INEMPTY_IEN (USB_AOTG_BASE + 0x406)
  252. #define IRQ_IN3EMPTY 6
  253. #define IRQ_IN2EMPTY 5
  254. #define IRQ_IN1EMPTY 4
  255. #define IEN_IN3EMPTY 2
  256. #define IEN_IN2EMPTY 1
  257. #define IEN_IN1EMPTY 0
  258. #define IRQ_INxEMPTY(ep) (ep + 3)
  259. #define IEN_INxEMPTY(ep) (ep - 1)
  260. #define INEMPTY_IRQ_MASK (0x70)
  261. #define INEMPTY_IEN_MASK (0x07)
  262. #define INEMPTY_IRQ_SHIFT 4
  263. #define INEMPTY_IEN_SHIFT 0
  264. /* shift to base 0 */
  265. #define INEMPTY_IRQ2ADDR(bit) (bit + 1)
  266. #define INEMPTY_IEN2ADDR(bit) (bit + 1)
  267. /** IN Token IRQ */
  268. #define IN_TOKIEN (USB_AOTG_BASE + 0x19C)
  269. #define IN_TOKIRQ (USB_AOTG_BASE + 0x190)
  270. #define EP0IN_TOKEN 0
  271. #define EP1IN_TOKEN 1
  272. #define EP2IN_TOKEN 2
  273. #define EP3IN_TOKEN 3
  274. #define EPIN_TOKEN_NUM 4
  275. #define EPIN_TOKEN_MASK 0x0F
  276. /** OUT Token IRQ */
  277. #define OUT_TOKIEN (USB_AOTG_BASE + 0x19D)
  278. #define OUT_TOKIRQ (USB_AOTG_BASE + 0x191)
  279. #define EP0OUT_TOKEN 0
  280. #define EP1OUT_TOKEN 1
  281. #define EP2OUT_TOKEN 2
  282. #define EPOUT_TOKEN_NUM 3
  283. #define EPOUT_TOKEN_MASK 0x07
  284. /************************************ FIFO ***********************************/
  285. /* FIFO start address */
  286. #define FIFO_START 0x0
  287. /* Total FIFO size (except for ep0) */
  288. #define FIFO_TOTAL 896
  289. /*
  290. * Arbitrary allocaction, need to optimize!
  291. * WARNNING: ep0 fifo ([200, 280)) cannot be re-allocated (hardware limit)!
  292. *
  293. * ep1in: 192B [0x0, 0xC0)
  294. * ep1out: 192B [0xC0, 0x180)
  295. * ep2in: 192B [0x280, 0x340)
  296. * ep0: 128 [200, 280)
  297. * ep2out: 192B [0x340, 0x400)
  298. * ep3in: 128B [0x180, 0x200)
  299. */
  300. #define EP1IN_FIFO_START FIFO_START
  301. #define EP1OUT_FIFO_START (FIFO_START + 0xC0)
  302. #define EP2IN_FIFO_START (FIFO_START + 0x280)
  303. #define EP2OUT_FIFO_START (FIFO_START + 0x340)
  304. #define EP3IN_FIFO_START (FIFO_START + 0x180)
  305. /** FIFO Control */
  306. #define FIFOCTRL (USB_AOTG_BASE + 0x1A8)
  307. /* FIFO Auto */
  308. #define FIFOCTRL_AUTO 5
  309. /* FIFO Direction */
  310. #define FIFOCTRL_IO_IN 4
  311. /* Endpoint address */
  312. #define FIFOCTRL_NUM_MASK 0x0F
  313. /** FIFO Data */
  314. #define FIFO1DAT (USB_AOTG_BASE + 0x084)
  315. #define FIFO2DAT (USB_AOTG_BASE + 0x088)
  316. #define FIFO3DAT (USB_AOTG_BASE + 0x08C)
  317. #define FIFOxDAT(ep) (FIFO1DAT + (ep - 1) * 4)
  318. /** FIFO Address */
  319. #define EP1OUT_STADDR (USB_AOTG_BASE + 0x304)
  320. #define EP2OUT_STADDR (USB_AOTG_BASE + 0x308)
  321. #define EPxOUT_STADDR(ep) (EP1OUT_STADDR + (ep - 1) * 4)
  322. #define EP1IN_STADDR (USB_AOTG_BASE + 0x344)
  323. #define EP2IN_STADDR (USB_AOTG_BASE + 0x348)
  324. #define EP3IN_STADDR (USB_AOTG_BASE + 0x34C)
  325. #define EPxIN_STADDR(ep) (EP1IN_STADDR + (ep - 1) * 4)
  326. /** Ep0 In Data */
  327. #define EP0INDATA (USB_AOTG_BASE + 0x100)
  328. #define EP0IN_FIFO EP0INDATA
  329. /** Ep0 Out Data */
  330. #define EP0OUTDATA (USB_AOTG_BASE + 0x140)
  331. #define EP0OUT_FIFO EP0OUTDATA
  332. /** Setup Data */
  333. #define SETUPDAT0 (USB_AOTG_BASE + 0x180)
  334. #define SETUPDAT1 (USB_AOTG_BASE + 0x181)
  335. #define SETUPDAT2 (USB_AOTG_BASE + 0x182)
  336. #define SETUPDAT3 (USB_AOTG_BASE + 0x183)
  337. #define SETUPDAT4 (USB_AOTG_BASE + 0x184)
  338. #define SETUPDAT5 (USB_AOTG_BASE + 0x185)
  339. #define SETUPDAT6 (USB_AOTG_BASE + 0x186)
  340. #define SETUPDAT7 (USB_AOTG_BASE + 0x187)
  341. #define SETUP_FIFO SETUPDAT0
  342. /** Byte Counter */
  343. #define OUT0BC (USB_AOTG_BASE + 0x000)
  344. #define IN0BC (USB_AOTG_BASE + 0x001)
  345. /* Out Endpoint */
  346. #define OUT1BCL (USB_AOTG_BASE + 0x008)
  347. #define OUT1BCH (USB_AOTG_BASE + 0x009)
  348. #define OUT1BC OUT1BCL
  349. #define OUT2BCL (USB_AOTG_BASE + 0x010)
  350. #define OUT2BCH (USB_AOTG_BASE + 0x011)
  351. #define OUT2BC OUT2BCL
  352. #define OUTxBC(ep) (OUT1BC + (ep - 1) * 8)
  353. /* In Endpoint */
  354. #define IN1BCL (USB_AOTG_BASE + 0x00C)
  355. #define IN1BCH (USB_AOTG_BASE + 0x00D)
  356. #define IN1BC IN1BCL
  357. #define IN2BCL (USB_AOTG_BASE + 0x014)
  358. #define IN2BCH (USB_AOTG_BASE + 0x015)
  359. #define IN2BC IN2BCL
  360. #define IN3BCL (USB_AOTG_BASE + 0x01C)
  361. #define IN3BCH (USB_AOTG_BASE + 0x01D)
  362. #define IN3BC IN3BCL
  363. #define INxBC(ep) (IN1BC + (ep - 1) * 8)
  364. /************************************ HCD ***********************************/
  365. /** Host Endpoint Control */
  366. #define HCEP0CTRL (USB_AOTG_BASE + 0x0C0)
  367. #define HCOUT0CTRL HCEP0CTRL
  368. #define HCOUT1CTRL (USB_AOTG_BASE + 0x0C4)
  369. #define HCOUT2CTRL (USB_AOTG_BASE + 0x0C8)
  370. #define HCOUT3CTRL (USB_AOTG_BASE + 0x0CC)
  371. #define HCOUTxCTRL(ep) (HCEP0CTRL + ep * 4)
  372. #define HCIN0CTRL HCEP0CTRL
  373. #define HCIN1CTRL (USB_AOTG_BASE + 0x0C6)
  374. #define HCIN2CTRL (USB_AOTG_BASE + 0x0CA)
  375. #define HCINxCTRL(ep) ((ep == 0) ? HCIN0CTRL : (HCIN1CTRL + (ep - 1) * 4))
  376. /* default: 0 */
  377. #define HCEPCTRL_EP_ADDR(ep) (ep & 0x0F)
  378. /** Host Endpoint Error */
  379. #define HCOUT0ERR (USB_AOTG_BASE + 0x0C1)
  380. #define HCOUT1ERR (USB_AOTG_BASE + 0x0C5)
  381. #define HCOUT2ERR (USB_AOTG_BASE + 0x0C9)
  382. #define HCOUT3ERR (USB_AOTG_BASE + 0x0CD)
  383. #define HCOUTxERR(ep) (HCOUT0ERR + ep * 4)
  384. #define HCIN0ERR (USB_AOTG_BASE + 0x0C3)
  385. #define HCIN1ERR (USB_AOTG_BASE + 0x0C7)
  386. #define HCIN2ERR (USB_AOTG_BASE + 0x0CB)
  387. #define HCINxERR(ep) (HCIN0ERR + ep * 4)
  388. /* HCEPERR_DOPING: only for ep-out */
  389. #define HCEPERR_DOPING 6
  390. #define HCEPERR_RESEND 5
  391. #define HCEPERR_TYPE_MASK (0x7 << 2)
  392. #define HCEPERR_CNT_MASK 0x3
  393. /* Error types */
  394. #define NO_ERR (0x0 << 2)
  395. #define ERR_CRC (0x1 << 2)
  396. #define ERR_TOGGLE (0x2 << 2)
  397. #define ERR_STALL (0x3 << 2)
  398. #define ERR_TIMEOUT (0x4 << 2)
  399. #define ERR_PID (0x5 << 2)
  400. #define ERR_OVERRUN (0x6 << 2)
  401. #define ERR_UNDERRUN (0x7 << 2)
  402. /* Error count maximum */
  403. #define ERR_COUNT_MAX 10
  404. #define HCINEPERRIRQ (USB_AOTG_BASE + 0x1B4)
  405. #define HCOUTEPERRIRQ (USB_AOTG_BASE + 0x1B6)
  406. #define HCEPxERRIRQ(ep) (ep)
  407. #define HCINEPERRIEN (USB_AOTG_BASE + 0x1B8)
  408. #define HCOUTEPERRIEN (USB_AOTG_BASE + 0x1BA)
  409. #define HCEPxERRIEN(ep) (ep)
  410. /** Host IN Endpoint Control */
  411. #define HCINCTRL (USB_AOTG_BASE + 0x402)
  412. #define HCINx_START(ep) (ep * 2 - 1)
  413. /* set: stop IN token when a short packet received */
  414. #define HCINx_SHORT(ep) ((ep - 1) * 2)
  415. /** Host IN End interrupt */
  416. #define HCINENDINT (USB_AOTG_BASE + 0x41F)
  417. #define IRQ_HCIN2END 5
  418. #define IRQ_HCIN1END 4
  419. #define IEN_HCIN2END 1
  420. #define IEN_HCIN1END 0
  421. /** Host IN packet count */
  422. #define HCIN1CNTL (USB_AOTG_BASE + 0x414)
  423. #define HCIN1CNTH (USB_AOTG_BASE + 0x415)
  424. #define HCIN1CNT HCIN1CNTL
  425. #define HCIN2CNTL (USB_AOTG_BASE + 0x416)
  426. #define HCIN2CNTH (USB_AOTG_BASE + 0x417)
  427. #define HCIN2CNT HCIN2CNTL
  428. #define HCINxCNT(ep) (HCIN1CNT + (ep - 1) * 2)
  429. #define HCINxCNTL(ep) (HCIN1CNTL + (ep - 1) * 2)
  430. #define HCINxCNTH(ep) (HCIN1CNTH + (ep - 1) * 2)
  431. /** Host Port Control */
  432. #define HCPORTCTRL (USB_AOTG_BASE + 0x1AB)
  433. /* default: RST_55MS */
  434. #define RST_10MS (0x0 << 6)
  435. #define RST_55MS (0x1 << 6)
  436. #define RST_1_6MS (0x2 << 6)
  437. /* Port Reset */
  438. #define PORTRST 5
  439. /* Test_J */
  440. #define PORTTST_J (0x1 << 0)
  441. /* Test_K */
  442. #define PORTTST_K (0x2 << 0)
  443. /* Test_SE0_NAK */
  444. #define PORTTST_SE0 (0x4 << 0)
  445. /* Test_Packet */
  446. #define PORTTST_PKT (0x8 << 0)
  447. /* Test_Force_Enable */
  448. #define PORTTST_FE (0x10 << 0)
  449. /** Host Frame */
  450. #define HCFRMNL (USB_AOTG_BASE + 0x1AC)
  451. #define HCFRMNH (USB_AOTG_BASE + 0x1AD)
  452. #define HCFRMN HCFRMNL
  453. #define HCFRMREMAINL (USB_AOTG_BASE + 0x1AE)
  454. #define HCFRMREMAINH (USB_AOTG_BASE + 0x1AF)
  455. #define HCFRMREMAIN HCFRMREMAINL
  456. /************************************ Endp ***********************************/
  457. /** Endpoint 0 Control and Status */
  458. #define EP0CS (USB_AOTG_BASE + 0x002)
  459. #define EP0CS_SETTOGGLE 6
  460. #define EP0CS_CLRTOGGLE 5
  461. #define EP0CS_HCSET 4
  462. #define EP0CS_OUTBUSY 3
  463. #define EP0CS_INBUSY 2
  464. /* Endpoint 0 NAK */
  465. #define EP0CS_NAK 1
  466. /* Endpoint 0 STALL */
  467. #define EP0CS_STALL 0
  468. /** Endpoint Control and Status */
  469. #define OUT1CS (USB_AOTG_BASE + 0x00B)
  470. #define OUT2CS (USB_AOTG_BASE + 0x013)
  471. #define OUTxCS(ep) (OUT1CS + (ep - 1) * 8)
  472. #define IN1CS (USB_AOTG_BASE + 0x00F)
  473. #define IN2CS (USB_AOTG_BASE + 0x017)
  474. #define IN3CS (USB_AOTG_BASE + 0x01F)
  475. #define INxCS(ep) (IN1CS + (ep - 1) * 8)
  476. #define EPCS_AUTO 4
  477. #define EPCS_NPAK_MASK 0x0C
  478. #define EPCS_NPAK_00 (0x0 < 2)
  479. #define EPCS_NPAK_01 (0x1 < 2)
  480. #define EPCS_NPAK_10 (0x2 < 2)
  481. #define EPCS_NPAK_11 (0x3 < 2)
  482. #define EPCS_NPAK 2
  483. #define EPCS_BUSY 1
  484. #define EPCS_ERR 0
  485. /** Endpoint Control */
  486. #define OUT1CTRL (USB_AOTG_BASE + 0x00A)
  487. #define OUT2CTRL (USB_AOTG_BASE + 0x012)
  488. #define OUT3CTRL (USB_AOTG_BASE + 0x01A)
  489. #define OUTxCTRL(ep) (OUT1CTRL + (ep - 1) * 8)
  490. #define IN1CTRL (USB_AOTG_BASE + 0x00E)
  491. #define IN2CTRL (USB_AOTG_BASE + 0x016)
  492. #define IN3CTRL (USB_AOTG_BASE + 0x01E)
  493. #define INxCTRL(ep) (IN1CTRL + (ep - 1) * 8)
  494. #define EPCTRL_VALID 7
  495. #define EPCTRL_STALL 6
  496. #define EPCTRL_TYPE 0x0C
  497. #define EPCTRL_BUF 0x03
  498. /* 3 ISO packets per microframe */
  499. #define EPCTRL_ISOC_3 5
  500. /* 2 ISO packets per microframe */
  501. #define EPCTRL_ISOC_2 4
  502. /** NAK Control for OUT Endpoints */
  503. #define NAKOUTCTRL (USB_AOTG_BASE + 0x401)
  504. #define EP2_NAK 1
  505. #define EP1_NAK 0
  506. /** Endpoint Reset */
  507. #define EPRST (USB_AOTG_BASE + 0x1A2)
  508. /* Endpoint FIFO Reset */
  509. #define EPRST_FIFORST 6
  510. /* Endpoint Toggle Reset */
  511. #define EPRST_TOGRST 5
  512. /* Endpoint Direction */
  513. #define EPRST_IO_IN 4
  514. /* Endpoint address */
  515. #define EPRST_NUM_MASK 0x0F
  516. /** Ep max packet size */
  517. /* Ep0 max packet size: not configure */
  518. #define OUT0MAXPKT (USB_AOTG_BASE + 0x1E0)
  519. #define EP0MAXPKT OUT0MAXPKT
  520. /* Ep-out max packet size */
  521. #define OUT1MAXPKTL (USB_AOTG_BASE + 0x1E2)
  522. #define OUT1MAXPKTH (USB_AOTG_BASE + 0x1E3)
  523. #define OUT1MAXPKT OUT1MAXPKTL
  524. #define OUT2MAXPKTL (USB_AOTG_BASE + 0x1E4)
  525. #define OUT2MAXPKTH (USB_AOTG_BASE + 0x1E5)
  526. #define OUT2MAXPKT OUT2MAXPKTL
  527. #define OUTxMAXPKT(ep) (OUT1MAXPKT + (ep - 1) * 2)
  528. /* Ep-in max packet size */
  529. #define IN1MAXPKTL (USB_AOTG_BASE + 0x3E2)
  530. #define IN1MAXPKTH (USB_AOTG_BASE + 0x3E3)
  531. #define IN1MAXPKT IN1MAXPKTL
  532. #define IN2MAXPKTL (USB_AOTG_BASE + 0x3E4)
  533. #define IN2MAXPKTH (USB_AOTG_BASE + 0x3E5)
  534. #define IN2MAXPKT IN2MAXPKTL
  535. #define IN3MAXPKTL (USB_AOTG_BASE + 0x3E6)
  536. #define IN3MAXPKTH (USB_AOTG_BASE + 0x3E7)
  537. #define IN3MAXPKT IN3MAXPKTL
  538. #define INxMAXPKT(ep) (IN1MAXPKT + (ep - 1) * 2)
  539. /********************************* Functions *********************************/
  540. /*
  541. * Turn USB controller power on
  542. */
  543. static inline void usb_aotg_power_on(void)
  544. {
  545. #define SPLL_CLK_48M (BIT(0) | BIT(6))
  546. /* setup spll CK48M; bit0: spll enable, bit6: spll 48M clock enable */
  547. if ((sys_read32(SPLL_CTL) & SPLL_CLK_48M) == SPLL_CLK_48M) {
  548. return;
  549. }
  550. sys_write32(sys_read32(SPLL_CTL) | SPLL_CLK_48M, SPLL_CTL);
  551. }
  552. /*
  553. * Turn USB controller power off
  554. */
  555. static inline void usb_aotg_power_off(void)
  556. {
  557. }
  558. static inline void usb_aotg_reset_specific(void)
  559. {
  560. }
  561. static inline void usb_aotg_disable_specific(void)
  562. {
  563. }
  564. static inline void aotg_dc_phy_init(void)
  565. {
  566. }
  567. static inline int aotg_dc_epout_alloc_fifo_specific(uint8_t ep_idx)
  568. {
  569. switch (ep_idx) {
  570. case USB_AOTG_OUT_EP_1:
  571. usb_write32(EP1OUT_STADDR, EP1OUT_FIFO_START);
  572. break;
  573. case USB_AOTG_OUT_EP_2:
  574. usb_write32(EP2OUT_STADDR, EP2OUT_FIFO_START);
  575. break;
  576. default:
  577. return -EINVAL;
  578. }
  579. return 0;
  580. }
  581. static inline int aotg_dc_epin_alloc_fifo_specific(uint8_t ep_idx)
  582. {
  583. switch (ep_idx) {
  584. case USB_AOTG_IN_EP_1:
  585. usb_write32(EP1IN_STADDR, EP1IN_FIFO_START);
  586. break;
  587. case USB_AOTG_IN_EP_2:
  588. usb_write32(EP2IN_STADDR, EP2IN_FIFO_START);
  589. break;
  590. case USB_AOTG_IN_EP_3:
  591. usb_write32(EP3IN_STADDR, EP3IN_FIFO_START);
  592. break;
  593. default:
  594. return -EINVAL;
  595. }
  596. return 0;
  597. }
  598. /*
  599. * Switch FIFO clock to make sure it is available for AOTG
  600. */
  601. static inline int aotg_dc_fifo_enable(void)
  602. {
  603. usb_set_bit32(USB_MEM_CLK, USB_MEM_CLK_URAM);
  604. return 0;
  605. }
  606. static inline int aotg_dc_fifo_disable(void)
  607. {
  608. usb_clear_bit32(USB_MEM_CLK, USB_MEM_CLK_URAM);
  609. return 0;
  610. }
  611. static inline int aotg_hc_epout_alloc_fifo_specific(uint8_t ep_idx)
  612. {
  613. switch (ep_idx) {
  614. case USB_AOTG_OUT_EP_1:
  615. usb_write32(EP1OUT_STADDR, EP1OUT_FIFO_START);
  616. break;
  617. case USB_AOTG_OUT_EP_2:
  618. usb_write32(EP2OUT_STADDR, EP2OUT_FIFO_START);
  619. break;
  620. default:
  621. return -EINVAL;
  622. }
  623. return 0;
  624. }
  625. static inline int aotg_hc_epin_alloc_fifo_specific(uint8_t ep_idx)
  626. {
  627. switch (ep_idx) {
  628. case USB_AOTG_IN_EP_1:
  629. usb_write32(EP1IN_STADDR, EP1IN_FIFO_START);
  630. break;
  631. case USB_AOTG_IN_EP_2:
  632. usb_write32(EP2IN_STADDR, EP2IN_FIFO_START);
  633. break;
  634. case USB_AOTG_IN_EP_3:
  635. usb_write32(EP3IN_STADDR, EP3IN_FIFO_START);
  636. break;
  637. default:
  638. return -EINVAL;
  639. }
  640. return 0;
  641. }
  642. static inline void aotg_hc_phy_init(void)
  643. {
  644. }
  645. /*
  646. * Switch FIFO clock to make sure it is available for AOTG
  647. */
  648. static inline int aotg_hc_fifo_enable(void)
  649. {
  650. usb_set_bit32(USB_MEM_CLK, USB_MEM_CLK_URAM);
  651. return 0;
  652. }
  653. static inline int aotg_hc_fifo_disable(void)
  654. {
  655. usb_clear_bit32(USB_MEM_CLK, USB_MEM_CLK_URAM);
  656. return 0;
  657. }
  658. static inline int usb_aotg_dpdm_init(void)
  659. {
  660. if (usb_read32(USB_DP_GPIO) != USB_DP_VALUE) {
  661. usb_write32(USB_DP_GPIO, USB_DP_VALUE);
  662. }
  663. if (usb_read32(USB_DM_GPIO) != USB_DM_VALUE) {
  664. usb_write32(USB_DM_GPIO, USB_DM_VALUE);
  665. }
  666. return 0;
  667. }
  668. static inline int usb_aotg_dpdm_exit(void)
  669. {
  670. usb_write32(USB_DP_GPIO, 0);
  671. usb_write32(USB_DM_GPIO, 0);
  672. return 0;
  673. }
  674. #endif /* __USB_AOTG_WOODPECKER_H__ */