usb_aotg_leopard.h 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048
  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 (leopard) driver private definitions
  9. *
  10. * This file contains the Actions OTG USB controller (leopard) driver private
  11. * definitions.
  12. */
  13. #ifndef __USB_AOTG_LEOPARD_H__
  14. #define __USB_AOTG_LEOPARD_H__
  15. #include <soc_regs.h>
  16. #include <soc_irq.h>
  17. /* USB IN EP index */
  18. enum usb_aotg_in_ep_idx {
  19. USB_AOTG_IN_EP_0 = 0,
  20. USB_AOTG_IN_EP_1,
  21. USB_AOTG_IN_EP_2,
  22. USB_AOTG_IN_EP_3,
  23. USB_AOTG_IN_EP_4,
  24. USB_AOTG_IN_EP_5,
  25. USB_AOTG_IN_EP_6,
  26. USB_AOTG_IN_EP_NUM
  27. };
  28. /* USB OUT EP index */
  29. enum usb_aotg_out_ep_idx {
  30. USB_AOTG_OUT_EP_0 = 0,
  31. USB_AOTG_OUT_EP_1,
  32. USB_AOTG_OUT_EP_2,
  33. USB_AOTG_OUT_EP_3,
  34. USB_AOTG_OUT_EP_4,
  35. USB_AOTG_OUT_EP_5,
  36. USB_AOTG_OUT_EP_6,
  37. USB_AOTG_OUT_EP_NUM
  38. };
  39. /*********************************** Common **********************************/
  40. /* FIFO Clock */
  41. #define USB_MEM_CLK_SRC CMU_MEMCLKSRC1
  42. #define USB_RAM_CLKSRC_BIT 8
  43. #define USB_MEM_CLK_EN CMU_MEMCLKEN1
  44. #define USB_RAM_CLKEN_BIT 8
  45. /* USB AOTG IRQ line */
  46. #define USB_AOTG_IRQ IRQ_ID_USB
  47. /* USB DP: GPIO75 */
  48. #define USB_DP_GPIO (0x40068000+0x12C)
  49. #define USB_DP_VALUE 0xb010
  50. /* USB DM: GPIO76 */
  51. #define USB_DM_GPIO (0x40068000+0x0130)
  52. #define USB_DM_VALUE 0xb010
  53. /*********************************** Global **********************************/
  54. /* USB AOTG Base Address */
  55. #define USB_AOTG_BASE 0x40050000
  56. /* USB AVDD Control */
  57. /* Debug */
  58. #define USBDEBUG (USB_AOTG_BASE + 0x427)
  59. #define USBDEBUG_EN 4
  60. #define USBDEBUG_MODE_MASK 0x1F
  61. /* Back door register */
  62. #define BKDOOR (USB_AOTG_BASE + 0x40D)
  63. #define HS_DISABLE 7
  64. /* Line Status */
  65. #define LINESTATUS (USB_AOTG_BASE + 0x422)
  66. #define LINE_DM 4
  67. #define LINE_DP 3
  68. #define LINESTATE_MASK (0x3 << 3)
  69. #define LINESTATE_DM (1 << LINE_DM)
  70. #define LINESTATE_DP (1 << LINE_DP)
  71. #define OTGRESET 0
  72. /* DPDM */
  73. #define DPDMCTRL (USB_AOTG_BASE + 0x421)
  74. /* plug-in (connect/disconnect) */
  75. #define PLUGIN 6
  76. /* Line status detect enable (default: enable) */
  77. #define LSDETEN 4
  78. /* 500K pull-up enable */
  79. #define DM_PULL_UP 3
  80. #define DP_PULL_UP 2
  81. /* 15K pull-down disable */
  82. #define DM_PULL_DOWN 1
  83. #define DP_PULL_DOWN 0
  84. #define DPDM_DEVICE (0x1F)
  85. #define DPDM_HOST (0x10)
  86. /** Idpin & Vbus */
  87. #define IDVBUSCTRL (USB_AOTG_BASE + 0x420)
  88. #define SOFT_IDPIN 3
  89. #define SOFT_IDEN 2
  90. #define IDVBUS_DEVICE (0x0C)
  91. #define IDVBUS_HOST (0x04)
  92. /** USB Control and Status */
  93. #define USBCS (USB_AOTG_BASE + 0x1A3)
  94. /* Soft disconnect */
  95. #define USBCS_DISCONN 6
  96. /* Remote wakeup */
  97. #define USBCS_WAKEUP 5
  98. #define USBCS_SPEED 1
  99. #define USBCS_LS 0
  100. /** Device Address */
  101. #define FNADDR (USB_AOTG_BASE + 0x1A6)
  102. /** USB OTG FSM State */
  103. #define USBSTATE (USB_AOTG_BASE + 0x1BD)
  104. /* Alias */
  105. #define OTGSTATE USBSTATE
  106. #define OTG_A_IDLE 0x0
  107. #define OTG_A_WAIT_BCON 0x2
  108. #define OTG_A_HOST 0x3
  109. #define OTG_A_SUSPEND 0x4
  110. #define OTG_B_IDLE 0x8
  111. #define OTG_B_PERIPHERAL 0x9
  112. /** USB OTG FSM Control */
  113. #define USBCTRL (USB_AOTG_BASE + 0x1BE)
  114. /* Alias */
  115. #define OTGCTRL USBCTRL
  116. #define OTGCTRL_FORCE 7
  117. #define OTGCTRL_BUSREQ 0
  118. /** USB Status */
  119. #define USBSTATUS (USB_AOTG_BASE + 0x1BF)
  120. /* 0: mini-A; 1: mini-B */
  121. #define USBSTATUS_ID 6
  122. #define USBSTATUS_CONN 1
  123. /************************************ IRQ ************************************/
  124. /** USB Core */
  125. #define USBIEN (USB_AOTG_BASE + 0x198)
  126. #define USBIEN_NTR 6
  127. #define USBIEN_HS 5
  128. #define USBIEN_RESET 4
  129. #define USBIEN_SUSPEND 3
  130. #define USBIEN_TOKEN 2
  131. #define USBIEN_SOF 1
  132. #define USBIEN_SETUP 0
  133. #define USBIRQ (USB_AOTG_BASE + 0x18C)
  134. #define USBIRQ_NTR 6
  135. /* High-speed */
  136. #define USBIRQ_HS 5
  137. /* USB Bus Reset */
  138. #define USBIRQ_RESET 4
  139. /* Suspend Signal */
  140. #define USBIRQ_SUSPEND 3
  141. /* SETUP Token */
  142. #define USBIRQ_TOKEN 2
  143. /* SOF Packet */
  144. #define USBIRQ_SOF 1
  145. /* SETUP Data */
  146. #define USBIRQ_SETUP 0
  147. /** OTGIEN */
  148. #define OTGIEN (USB_AOTG_BASE + 0x1C0)
  149. #define OTGIEN_PERIPHERAL 4
  150. #define OTGIEN_LOCSOF 2
  151. #define OTGIEN_IDLE 0
  152. #define OTGIRQ (USB_AOTG_BASE + 0x1BC)
  153. #define OTGIRQ_PERIPHERAL 4
  154. #define OTGIRQ_LOCSOF 2
  155. #define OTGIRQ_IDLE 0
  156. /** Specific OTG FSM IRQ */
  157. #define OTGSTATE_IEN (USB_AOTG_BASE + 0x405)
  158. #define OTGSTATE_IRQ (USB_AOTG_BASE + 0x404)
  159. #define OTGSTATE_B_WAIT_ACON 2
  160. #define OTGSTATE_A_WAIT_BCON 1
  161. #define OTGSTATE_A_SUSPEND 0
  162. /** USB External Interrupt request */
  163. #define USBEIRQ (USB_AOTG_BASE + 0x400)
  164. /* Alias: same register */
  165. #define USBEIEN USBEIRQ
  166. /* External */
  167. #define USBEIRQ_EXTERN 7
  168. /* Wakeup */
  169. #define USBEIRQ_WAKEUP 6
  170. /* Resume */
  171. #define USBEIRQ_RESUME 5
  172. /* Connnect/disconnect */
  173. #define USBEIRQ_CONDISC 4
  174. /* External */
  175. #define USBEIEN_EXTERN 3
  176. /* Wakeup */
  177. #define USBEIEN_WAKEUP 2
  178. /* Resume */
  179. #define USBEIEN_RESUME 1
  180. /* Connnect/disconnect */
  181. #define USBEIEN_CONDISC 0
  182. #define USBEIEN_MASK (0x0f)
  183. #define USBEIRQ_MASK (0xf0)
  184. /** Interrupt Vector */
  185. #define IVECT (USB_AOTG_BASE + 0x1A0)
  186. /* Device */
  187. /* Setup Data */
  188. #define UIV_SUDAV 0x00
  189. #define UIV_SOF 0x04
  190. /* Setup Token */
  191. #define UIV_SUTOK 0x08
  192. #define UIV_SUSPEND 0x0c
  193. #define UIV_USBRST 0x10
  194. /* leopard not sppuort high-speed transfer. */
  195. #define UIV_HSPEED 0x14
  196. /* Endpoint */
  197. #define UIV_HCOUT0ERR 0x16
  198. #define UIV_EP0IN 0x18
  199. #define UIV_HCIN0ERR 0x1a
  200. #define UIV_EP0OUT 0x1c
  201. #define UIV_EP0PING 0x20
  202. #define UIV_HCOUT1ERR 0x22
  203. #define UIV_EP1IN 0x24
  204. #define UIV_HCIN1ERR 0x26
  205. #define UIV_EP1OUT 0x28
  206. #define UIV_EP1PING 0x2c
  207. #define UIV_HCOUT2ERR 0x2e
  208. #define UIV_EP2IN 0x30
  209. #define UIV_HCIN2ERR 0x32
  210. #define UIV_EP2OUT 0x34
  211. #define UIV_EP2PING 0x38
  212. #define UIV_HCOUT3ERR 0x3a
  213. #define UIV_EP3IN 0x3c
  214. #define UIV_HCIN3ERR 0x3e
  215. #define UIV_EP3OUT 0x40
  216. #define UIV_EP3PING 0x44
  217. #define UIV_HCOUT4ERR 0x46
  218. #define UIV_EP4IN 0x48
  219. #define UIV_HCIN4ERR 0x4A
  220. #define UIV_EP4OUT 0x4C
  221. #define UIV_EP4PING 0x50
  222. #define UIV_HCOUT5ERR 0x52
  223. #define UIV_EP5IN 0x54
  224. #define UIV_HCIN5ERR 0x56
  225. #define UIV_EP5OUT 0x58
  226. #define UIV_EP5PING 0x5C
  227. #define UIV_HCOUT6ERR 0x5E
  228. #define UIV_EP6IN 0x60
  229. #define UIV_HCIN6ERR 0x62
  230. #define UIV_EP6OUT 0x64
  231. #define UIV_EP6PING 0x68
  232. /* IN Token */
  233. #define UIV_INTOKEN 0xe0
  234. /* OUT Token */
  235. #define UIV_OUTTOKEN 0xe4
  236. #define UIV_OTGIRQ 0xd8
  237. /* Controller */
  238. #define UIV_RESUME 0xe6
  239. #define UIV_CONDISC 0xe8
  240. /* OTG */
  241. #define UIV_OTGSTATE 0xea
  242. /* EP OUT Short Packet */
  243. #define UIV_EPOUTSHTPKT 0xec
  244. #define UIV_HCINEND 0xee
  245. #define UIV_HCOUTEMPTY 0xf0
  246. #define UIV_NTR 0xf2
  247. #define UIV_EPIN_VEC2ADDR(vector) ((vector - UIV_EP0IN) / 12)
  248. #define UIV_EPOUT_VEC2ADDR(vector) ((vector - UIV_EP0OUT) / 12)
  249. #define UIV_HCINERR_VEC2ADDR(vector) ((vector - UIV_HCIN0ERR) / 12)
  250. #define UIV_HCOUTERR_VEC2ADDR(vector) ((vector - UIV_HCOUT0ERR) / 12)
  251. /** Endpoint Interrupt request */
  252. /* OUT IRQ */
  253. #define OUT06IEN (USB_AOTG_BASE + 0x196)
  254. #define OUTIEN OUT06IEN
  255. #define OUT06IRQ (USB_AOTG_BASE + 0x18A)
  256. #define OUTIRQ OUT06IRQ
  257. #define IRQ_EP0OUT 0
  258. #define IRQ_EP1OUT 1
  259. #define IRQ_EP2OUT 2
  260. #define IRQ_EP3OUT 3
  261. #define IRQ_EPxOUT(ep) (ep)
  262. /** OUT Endpoints Short Packet Control */
  263. #define OUT_SHTPKT (USB_AOTG_BASE + 0x401)
  264. #define IRQ_EP6OUT_SHTPKT 6
  265. #define IRQ_EP5OUT_SHTPKT 5
  266. #define IRQ_EP4OUT_SHTPKT 4
  267. #define IRQ_EP3OUT_SHTPKT 3
  268. #define IRQ_EP2OUT_SHTPKT 2
  269. #define IRQ_EP1OUT_SHTPKT 1
  270. /* IN IRQ */
  271. #define IN06IEN (USB_AOTG_BASE + 0x194)
  272. #define INIEN IN06IEN
  273. #define IN06IRQ (USB_AOTG_BASE + 0x188)
  274. #define INIRQ IN06IRQ
  275. #define IRQ_EP0IN 0
  276. #define IRQ_EP1IN 1
  277. #define IRQ_EP2IN 2
  278. #define IRQ_EP3IN 3
  279. #define IRQ_EP4IN 4
  280. #define IRQ_EPxIN(ep) (ep)
  281. #define INEMPTY_IRQ (USB_AOTG_BASE + 0x402)
  282. #define IRQ_IN6EMPTY 6
  283. #define IRQ_IN5EMPTY 5
  284. #define IRQ_IN4EMPTY 4
  285. #define IRQ_IN3EMPTY 3
  286. #define IRQ_IN2EMPTY 2
  287. #define IRQ_IN1EMPTY 1
  288. #define INEMPTY_IEN (USB_AOTG_BASE + 0x403)
  289. #define IEN_IN6EMPTY 6
  290. #define IEN_IN5EMPTY 5
  291. #define IEN_IN4EMPTY 4
  292. #define IEN_IN3EMPTY 3
  293. #define IEN_IN2EMPTY 2
  294. #define IEN_IN1EMPTY 1
  295. #define IRQ_INxEMPTY(ep) (ep)
  296. #define IEN_INxEMPTY(ep) (ep)
  297. #define INEMPTY_IRQ_MASK (0x1e)
  298. #define INEMPTY_IEN_MASK (0x1e)
  299. #define INEMPTY_IRQ_SHIFT 1
  300. #define INEMPTY_IEN_SHIFT 1
  301. /* shift to base 0 */
  302. #define INEMPTY_IRQ2ADDR(bit) (bit + 1)
  303. #define INEMPTY_IEN2ADDR(bit) (bit + 1)
  304. /** IN Token IRQ */
  305. #define IN06TOKIEN (USB_AOTG_BASE + 0x19C)
  306. #define IN_TOKIEN IN06TOKIEN
  307. #define IN06TOKIRQ (USB_AOTG_BASE + 0x190)
  308. #define IN_TOKIRQ IN06TOKIRQ
  309. #define EP0IN_TOKEN 0
  310. #define EP1IN_TOKEN 1
  311. #define EP2IN_TOKEN 2
  312. #define EP3IN_TOKEN 3
  313. #define EP4IN_TOKEN 4
  314. #define EPIN_TOKEN_NUM 5
  315. #define EPIN_TOKEN_MASK 0x1F
  316. /** OUT Token IRQ */
  317. #define OUT06TOKIEN (USB_AOTG_BASE + 0x19D)
  318. #define OUT_TOKIEN OUT06TOKIEN
  319. #define OUT06TOKIRQ (USB_AOTG_BASE + 0x191)
  320. #define OUT_TOKIRQ OUT06TOKIRQ
  321. #define EP0OUT_TOKEN 0
  322. #define EP1OUT_TOKEN 1
  323. #define EP2OUT_TOKEN 2
  324. #define EP3OUT_TOKEN 3
  325. #define EP4OUT_TOKEN 4
  326. #define EPOUT_TOKEN_NUM 5
  327. #define EPOUT_TOKEN_MASK 0x1F
  328. /************************************ FIFO ***********************************/
  329. /*
  330. * AOTG USB Controller FIFO layout (add by order...)
  331. * Luckily, we don't need to take care of ep0 FIFO.
  332. *
  333. * URAM0 FIFO (only for ep1-in dma): 2KB [0x0, 0x800)
  334. * URAM1 FIFO (only for ep2-out dma): 2KB [0x800, 0x1000)
  335. * URAM2 FIFO (for ep1-out, ep2-in, ep3-in/out, ep4-in/out, ep5-in/out, ep6-in/out cpu): 4KB [0x1000, 0x1FFF)
  336. * URAM3 FIFO (only for ep0): 128-byte
  337. */
  338. /* FIFO start address */
  339. #define URAM0_FIFO_START 0x0
  340. #define URAM1_FIFO_START 0x800
  341. #define URAM2_FIFO_START 0x1000
  342. #define NORMAL_FIFO_START URAM2_FIFO_START
  343. /* Arbitrary single independent FIFO block size */
  344. #define NORMAL_FIFO_BLOCK 256
  345. /*
  346. * Arbitrary allocaction for NORMAL_FIFO_START, can be config flexible.
  347. */
  348. #define EP1IN_FIFO_START URAM0_FIFO_START
  349. #define EP2OUT_FIFO_START URAM1_FIFO_START
  350. #define EP1OUT_FIFO_START NORMAL_FIFO_START
  351. #define EP2IN_FIFO_START (NORMAL_FIFO_START + NORMAL_FIFO_BLOCK * 4)
  352. #define EP3OUT_FIFO_START (NORMAL_FIFO_START + NORMAL_FIFO_BLOCK * 8)
  353. #define EP3IN_FIFO_START (NORMAL_FIFO_START + NORMAL_FIFO_BLOCK * 9)
  354. #define EP4OUT_FIFO_START (NORMAL_FIFO_START + NORMAL_FIFO_BLOCK * 10)
  355. #define EP4IN_FIFO_START (NORMAL_FIFO_START + NORMAL_FIFO_BLOCK * 11)
  356. #define EP5OUT_FIFO_START (NORMAL_FIFO_START + NORMAL_FIFO_BLOCK * 12)
  357. #define EP5IN_FIFO_START (NORMAL_FIFO_START + NORMAL_FIFO_BLOCK * 13)
  358. #define EP6OUT_FIFO_START (NORMAL_FIFO_START + NORMAL_FIFO_BLOCK * 14)
  359. #define EP6IN_FIFO_START (NORMAL_FIFO_START + NORMAL_FIFO_BLOCK * 15)
  360. /** FIFO Control */
  361. #define FIFOCTRL (USB_AOTG_BASE + 0x1A8)
  362. /* FIFO Auto */
  363. #define FIFOCTRL_AUTO 5
  364. /* FIFO Direction */
  365. #define FIFOCTRL_IO_IN 4
  366. /* Endpoint address */
  367. #define FIFOCTRL_NUM_MASK 0x0F
  368. /** FIFO Data */
  369. #define FIFO1DAT (USB_AOTG_BASE + 0x084)
  370. #define FIFO2DAT (USB_AOTG_BASE + 0x088)
  371. #define FIFO3DAT (USB_AOTG_BASE + 0x08C)
  372. #define FIFO4DAT (USB_AOTG_BASE + 0x090)
  373. #define FIFO5DAT (USB_AOTG_BASE + 0x094)
  374. #define FIFO6DAT (USB_AOTG_BASE + 0x098)
  375. #define FIFOxDAT(ep) (FIFO1DAT + (ep - 1) * 4)
  376. /** FIFO OUT Address */
  377. #define EP1OUT_STADDR (USB_AOTG_BASE + 0x304)
  378. #define EP2OUT_STADDR (USB_AOTG_BASE + 0x308)
  379. #define EP3OUT_STADDR (USB_AOTG_BASE + 0x30C)
  380. #define EP4OUT_STADDR (USB_AOTG_BASE + 0x310)
  381. #define EP5OUT_STADDR (USB_AOTG_BASE + 0x314)
  382. #define EP6OUT_STADDR (USB_AOTG_BASE + 0x318)
  383. #define EPxOUT_STADDR(ep) (EP1OUT_STADDR + (ep - 1) * 4)
  384. /** FIFO IN Address */
  385. #define EP1IN_STADDR (USB_AOTG_BASE + 0x344)
  386. #define EP2IN_STADDR (USB_AOTG_BASE + 0x348)
  387. #define EP3IN_STADDR (USB_AOTG_BASE + 0x34C)
  388. #define EP4IN_STADDR (USB_AOTG_BASE + 0x350)
  389. #define EP5IN_STADDR (USB_AOTG_BASE + 0x354)
  390. #define EP6IN_STADDR (USB_AOTG_BASE + 0x358)
  391. #define EPxIN_STADDR(ep) (EP1IN_STADDR + (ep - 1) * 4)
  392. /** Ep0 In Data */
  393. #define EP0INDATA (USB_AOTG_BASE + 0x100)
  394. #define EP0IN_FIFO EP0INDATA
  395. /** Ep0 Out Data */
  396. #define EP0OUTDATA (USB_AOTG_BASE + 0x140)
  397. #define EP0OUT_FIFO EP0OUTDATA
  398. /** Setup Data */
  399. #define SETUPDAT0 (USB_AOTG_BASE + 0x180)
  400. #define SETUPDAT1 (USB_AOTG_BASE + 0x181)
  401. #define SETUPDAT2 (USB_AOTG_BASE + 0x182)
  402. #define SETUPDAT3 (USB_AOTG_BASE + 0x183)
  403. #define SETUPDAT4 (USB_AOTG_BASE + 0x184)
  404. #define SETUPDAT5 (USB_AOTG_BASE + 0x185)
  405. #define SETUPDAT6 (USB_AOTG_BASE + 0x186)
  406. #define SETUPDAT7 (USB_AOTG_BASE + 0x187)
  407. #define SETUP_FIFO SETUPDAT0
  408. /** Byte Counter */
  409. #define OUT0BC (USB_AOTG_BASE + 0x000)
  410. #define IN0BC (USB_AOTG_BASE + 0x001)
  411. /* Out Endpoint */
  412. #define OUT1BCL (USB_AOTG_BASE + 0x008)
  413. #define OUT1BCH (USB_AOTG_BASE + 0x009)
  414. #define OUT1BC OUT1BCL
  415. #define OUT2BCL (USB_AOTG_BASE + 0x010)
  416. #define OUT2BCH (USB_AOTG_BASE + 0x011)
  417. #define OUT2BC OUT2BCL
  418. #define OUT3BCL (USB_AOTG_BASE + 0x018)
  419. #define OUT3BCH (USB_AOTG_BASE + 0x019)
  420. #define OUT3BC OUT3BCL
  421. #define OUT4BCL (USB_AOTG_BASE + 0x020)
  422. #define OUT4BCH (USB_AOTG_BASE + 0x021)
  423. #define OUT4BC OUT4BCL
  424. #define OUT5BCL (USB_AOTG_BASE + 0x028)
  425. #define OUT5BCH (USB_AOTG_BASE + 0x029)
  426. #define OUT5BC OUT5BCL
  427. #define OUT6BCL (USB_AOTG_BASE + 0x030)
  428. #define OUT6BCH (USB_AOTG_BASE + 0x031)
  429. #define OUT6BC OUT6BCL
  430. #define OUTxBC(ep) (OUT1BC + (ep - 1) * 8)
  431. /* In Endpoint */
  432. #define IN1BCL (USB_AOTG_BASE + 0x00C)
  433. #define IN1BCH (USB_AOTG_BASE + 0x00D)
  434. #define IN1BC IN1BCL
  435. #define IN2BCL (USB_AOTG_BASE + 0x014)
  436. #define IN2BCH (USB_AOTG_BASE + 0x015)
  437. #define IN2BC IN2BCL
  438. #define IN3BCL (USB_AOTG_BASE + 0x01C)
  439. #define IN3BCH (USB_AOTG_BASE + 0x01D)
  440. #define IN3BC IN3BCL
  441. #define IN4BCL (USB_AOTG_BASE + 0x024)
  442. #define IN4BCH (USB_AOTG_BASE + 0x025)
  443. #define IN4BC IN4BCL
  444. #define IN5BCL (USB_AOTG_BASE + 0x02C)
  445. #define IN5BCH (USB_AOTG_BASE + 0x02D)
  446. #define IN5BC IN5BCL
  447. #define IN6BCL (USB_AOTG_BASE + 0x034)
  448. #define IN6BCH (USB_AOTG_BASE + 0x035)
  449. #define IN6BC IN6BCL
  450. #define INxBC(ep) (IN1BC + (ep - 1) * 8)
  451. #define INxBCL(ep) (IN1BCL + (ep - 1) * 8)
  452. #define INxBCH(ep) (IN1BCH + (ep - 1) * 8)
  453. /************************************ HCD ***********************************/
  454. /** Host Endpoint Control */
  455. #define HCEP0CTRL (USB_AOTG_BASE + 0x0C0)
  456. #define HCOUT0CTRL HCEP0CTRL
  457. #define HCOUT1CTRL (USB_AOTG_BASE + 0x0C4)
  458. #define HCOUT2CTRL (USB_AOTG_BASE + 0x0C8)
  459. #define HCOUT3CTRL (USB_AOTG_BASE + 0x0CC)
  460. #define HCOUT4CTRL (USB_AOTG_BASE + 0x0D0)
  461. #define HCOUTxCTRL(ep) (HCEP0CTRL + ep * 4)
  462. #define HCIN0CTRL HCEP0CTRL
  463. #define HCIN1CTRL (USB_AOTG_BASE + 0x0C6)
  464. #define HCIN2CTRL (USB_AOTG_BASE + 0x0CA)
  465. #define HCIN3CTRL (USB_AOTG_BASE + 0x0CE)
  466. #define HCIN4CTRL (USB_AOTG_BASE + 0x0D2)
  467. #define HCINxCTRL(ep) ((ep == 0) ? HCIN0CTRL : (HCIN1CTRL + (ep - 1) * 4))
  468. /* default: 0 */
  469. #define HCEPCTRL_EP_ADDR(ep) (ep & 0x0F)
  470. /** Host Endpoint Error */
  471. #define HCOUT0ERR (USB_AOTG_BASE + 0x0C1)
  472. #define HCOUT1ERR (USB_AOTG_BASE + 0x0C5)
  473. #define HCOUT2ERR (USB_AOTG_BASE + 0x0C9)
  474. #define HCOUT3ERR (USB_AOTG_BASE + 0x0CD)
  475. #define HCOUT4ERR (USB_AOTG_BASE + 0x0D1)
  476. #define HCOUTxERR(ep) (HCOUT0ERR + ep * 4)
  477. #define HCIN0ERR (USB_AOTG_BASE + 0x0C3)
  478. #define HCIN1ERR (USB_AOTG_BASE + 0x0C7)
  479. #define HCIN2ERR (USB_AOTG_BASE + 0x0CB)
  480. #define HCIN3ERR (USB_AOTG_BASE + 0x0CF)
  481. #define HCIN4ERR (USB_AOTG_BASE + 0x0D3)
  482. #define HCINxERR(ep) (HCIN0ERR + ep * 4)
  483. /* HCEPERR_DOPING: only for ep-out */
  484. #define HCEPERR_DOPING 6
  485. #define HCEPERR_RESEND 5
  486. #define HCEPERR_TYPE_MASK (0x7 << 2)
  487. #define HCEPERR_CNT_MASK 0x3
  488. /* Error types */
  489. #define NO_ERR (0x0 << 2)
  490. #define ERR_CRC (0x1 << 2)
  491. #define ERR_TOGGLE (0x2 << 2)
  492. #define ERR_STALL (0x3 << 2)
  493. #define ERR_TIMEOUT (0x4 << 2)
  494. #define ERR_PID (0x5 << 2)
  495. #define ERR_OVERRUN (0x6 << 2)
  496. #define ERR_UNDERRUN (0x7 << 2)
  497. /* Error count maximum */
  498. #define ERR_COUNT_MAX 10
  499. #define HCIN03ERRIRQ (USB_AOTG_BASE + 0x1B4)
  500. #define HCINEPERRIRQ HCIN03ERRIRQ
  501. #define HCOUT03ERRIRQ (USB_AOTG_BASE + 0x1B6)
  502. #define HCOUTEPERRIRQ HCOUT03ERRIRQ
  503. #define HCEPxERRIRQ(ep) (ep)
  504. #define HCIN03ERRIEN (USB_AOTG_BASE + 0x1B8)
  505. #define HCINEPERRIEN HCIN03ERRIEN
  506. #define HCOUT03ERRIEN (USB_AOTG_BASE + 0x1BA)
  507. #define HCOUTEPERRIEN HCOUT03ERRIEN
  508. #define HCEPxERRIEN(ep) (ep)
  509. /** Host IN Endpoint Control */
  510. #define HCINCTRL (USB_AOTG_BASE + 0x411)
  511. #define HCINx_START(ep) (ep)
  512. /* set: stop IN token when a short packet received */
  513. #define HCINx_SHORT(ep) ((ep - 1) * 2)
  514. /** Host IN End interrupt */
  515. #define HCINENDINT (USB_AOTG_BASE + 0x403)
  516. #define IRQ_HCIN4END 4
  517. #define IRQ_HCIN3END 3
  518. #define IRQ_HCIN2END 2
  519. #define IRQ_HCIN1END 1
  520. #define IEN_HCIN4END 4
  521. #define IEN_HCIN3END 3
  522. #define IEN_HCIN2END 2
  523. #define IEN_HCIN1END 1
  524. /** Host IN packet count */
  525. #define HCIN1CNTL (USB_AOTG_BASE + 0x412)
  526. #define HCIN1CNTH (USB_AOTG_BASE + 0x413)
  527. #define HCIN1CNT HCIN1CNTL
  528. #define HCIN2CNTL (USB_AOTG_BASE + 0x414)
  529. #define HCIN2CNTH (USB_AOTG_BASE + 0x415)
  530. #define HCIN2CNT HCIN2CNTL
  531. #define HCIN3CNTL (USB_AOTG_BASE + 0x416)
  532. #define HCIN3CNTH (USB_AOTG_BASE + 0x417)
  533. #define HCIN3CNT HCIN3CNTL
  534. #define HCIN4CNTL (USB_AOTG_BASE + 0x418)
  535. #define HCIN4CNTH (USB_AOTG_BASE + 0x419)
  536. #define HCIN4CNT HCIN4CNTL
  537. #define HCINxCNT(ep) (HCIN1CNT + (ep - 1) * 2)
  538. #define HCINxCNTL(ep) (HCIN1CNTL + (ep - 1) * 2)
  539. #define HCINxCNTH(ep) (HCIN1CNTH + (ep - 1) * 2)
  540. /** Host Port Control */
  541. #define HCPORTCTRL (USB_AOTG_BASE + 0x1AB)
  542. /* default: RST_55MS */
  543. #define RST_10MS (0x0 << 6)
  544. #define RST_55MS (0x1 << 6)
  545. #define RST_1_6MS (0x2 << 6)
  546. /* Port Reset */
  547. #define PORTRST 5
  548. /* Test_J */
  549. #define PORTTST_J (0x1 << 0)
  550. /* Test_K */
  551. #define PORTTST_K (0x2 << 0)
  552. /* Test_SE0_NAK */
  553. #define PORTTST_SE0 (0x4 << 0)
  554. /* Test_Packet */
  555. #define PORTTST_PKT (0x8 << 0)
  556. /* Test_Force_Enable */
  557. #define PORTTST_FE (0x10 << 0)
  558. /** Host Frame */
  559. #define HCFRMNL (USB_AOTG_BASE + 0x1AC)
  560. #define HCFRMNH (USB_AOTG_BASE + 0x1AD)
  561. #define HCFRMN HCFRMNL
  562. #define HCFRMREMAINL (USB_AOTG_BASE + 0x1AE)
  563. #define HCFRMREMAINH (USB_AOTG_BASE + 0x1AF)
  564. #define HCFRMREMAIN HCFRMREMAINL
  565. /************************************ Endp ***********************************/
  566. /** Endpoint 0 Control and Status */
  567. #define EP0CS (USB_AOTG_BASE + 0x002)
  568. #define EP0CS_SETTOGGLE 6
  569. #define EP0CS_CLRTOGGLE 5
  570. #define EP0CS_HCSET 4
  571. #define EP0CS_OUTBUSY 3
  572. #define EP0CS_INBUSY 2
  573. /* Endpoint 0 NAK */
  574. #define EP0CS_NAK 1
  575. /* Endpoint 0 STALL */
  576. #define EP0CS_STALL 0
  577. /** Endpoint Control and Status */
  578. #define OUT1CS (USB_AOTG_BASE + 0x00B)
  579. #define OUT2CS (USB_AOTG_BASE + 0x013)
  580. #define OUT3CS (USB_AOTG_BASE + 0x01B)
  581. #define OUT4CS (USB_AOTG_BASE + 0x023)
  582. #define OUT5CS (USB_AOTG_BASE + 0x02B)
  583. #define OUT6CS (USB_AOTG_BASE + 0x033)
  584. #define OUTxCS(ep) (OUT1CS + (ep - 1) * 8)
  585. #define IN1CS (USB_AOTG_BASE + 0x00F)
  586. #define IN2CS (USB_AOTG_BASE + 0x017)
  587. #define IN3CS (USB_AOTG_BASE + 0x01F)
  588. #define IN4CS (USB_AOTG_BASE + 0x027)
  589. #define IN5CS (USB_AOTG_BASE + 0x02F)
  590. #define IN6CS (USB_AOTG_BASE + 0x037)
  591. #define INxCS(ep) (IN1CS + (ep - 1) * 8)
  592. #define EPCS_AUTO 4
  593. #define EPCS_NPAK_MASK 0x0C
  594. #define EPCS_NPAK_00 (0x0 < 2)
  595. #define EPCS_NPAK_01 (0x1 < 2)
  596. #define EPCS_NPAK_10 (0x2 < 2)
  597. #define EPCS_NPAK_11 (0x3 < 2)
  598. #define EPCS_NPAK 2
  599. #define EPCS_BUSY 1
  600. #define EPCS_ERR 0
  601. /** Endpoint Control */
  602. #define OUT1CTRL (USB_AOTG_BASE + 0x00A)
  603. #define OUT2CTRL (USB_AOTG_BASE + 0x012)
  604. #define OUT3CTRL (USB_AOTG_BASE + 0x01A)
  605. #define OUT4CTRL (USB_AOTG_BASE + 0x022)
  606. #define OUT5CTRL (USB_AOTG_BASE + 0x02A)
  607. #define OUT6CTRL (USB_AOTG_BASE + 0x032)
  608. #define OUTxCTRL(ep) (OUT1CTRL + (ep - 1) * 8)
  609. #define IN1CTRL (USB_AOTG_BASE + 0x00E)
  610. #define IN2CTRL (USB_AOTG_BASE + 0x016)
  611. #define IN3CTRL (USB_AOTG_BASE + 0x01E)
  612. #define IN4CTRL (USB_AOTG_BASE + 0x026)
  613. #define IN5CTRL (USB_AOTG_BASE + 0x02E)
  614. #define IN6CTRL (USB_AOTG_BASE + 0x036)
  615. #define INxCTRL(ep) (IN1CTRL + (ep - 1) * 8)
  616. #define EPCTRL_VALID 7
  617. #define EPCTRL_STALL 6
  618. #define EPCTRL_TYPE 0x0C
  619. #define EPCTRL_BUF 0x03
  620. /* 3 ISO packets per microframe */
  621. #define EPCTRL_ISOC_3 5
  622. /* 2 ISO packets per microframe */
  623. #define EPCTRL_ISOC_2 4
  624. /** NAK Control for OUT Endpoints */
  625. #define NAKOUTCTRL (USB_AOTG_BASE + 0x40C)
  626. #define EP6_NAK 6
  627. #define EP5_NAK 5
  628. #define EP4_NAK 4
  629. #define EP3_NAK 3
  630. #define EP2_NAK 2
  631. #define EP1_NAK 1
  632. /** Endpoint Reset */
  633. #define EPRST (USB_AOTG_BASE + 0x1A2)
  634. /* Endpoint FIFO Reset */
  635. #define EPRST_FIFORST 6
  636. /* Endpoint Toggle Reset */
  637. #define EPRST_TOGRST 5
  638. /* Endpoint Direction */
  639. #define EPRST_IO_IN 4
  640. /* Endpoint address */
  641. #define EPRST_NUM_MASK 0x0F
  642. /** Ep max packet size */
  643. /* Ep0 max packet size: not configure */
  644. #define OUT0MAXPKT (USB_AOTG_BASE + 0x1E0)
  645. #define EP0MAXPKT OUT0MAXPKT
  646. /* Ep-out max packet size */
  647. #define OUT1MAXPKTL (USB_AOTG_BASE + 0x1E2)
  648. #define OUT1MAXPKTH (USB_AOTG_BASE + 0x1E3)
  649. #define OUT1MAXPKT OUT1MAXPKTL
  650. #define OUT2MAXPKTL (USB_AOTG_BASE + 0x1E4)
  651. #define OUT2MAXPKTH (USB_AOTG_BASE + 0x1E5)
  652. #define OUT2MAXPKT OUT2MAXPKTL
  653. #define OUT3MAXPKTL (USB_AOTG_BASE + 0x1E6)
  654. #define OUT3MAXPKTH (USB_AOTG_BASE + 0x1E7)
  655. #define OUT3MAXPKT OUT3MAXPKTL
  656. #define OUT4MAXPKTL (USB_AOTG_BASE + 0x1E8)
  657. #define OUT4MAXPKTH (USB_AOTG_BASE + 0x1E9)
  658. #define OUT4MAXPKT OUT4MAXPKTL
  659. #define OUT5MAXPKTL (USB_AOTG_BASE + 0x1EA)
  660. #define OUT5MAXPKTH (USB_AOTG_BASE + 0x1EB)
  661. #define OUT5MAXPKT OUT5MAXPKTL
  662. #define OUT6MAXPKTL (USB_AOTG_BASE + 0x1EC)
  663. #define OUT6MAXPKTH (USB_AOTG_BASE + 0x1ED)
  664. #define OUT6MAXPKT OUT6MAXPKTL
  665. #define OUTxMAXPKT(ep) (OUT1MAXPKT + (ep - 1) * 2)
  666. #define OUTxMAXPKTL(ep) (OUT1MAXPKTL + (ep - 1) * 2)
  667. #define OUTxMAXPKTH(ep) (OUT1MAXPKTH + (ep - 1) * 2)
  668. /* Ep-in max packet size */
  669. #define IN1MAXPKTL (USB_AOTG_BASE + 0x3E2)
  670. #define IN1MAXPKTH (USB_AOTG_BASE + 0x3E3)
  671. #define IN1MAXPKT IN1MAXPKTL
  672. #define IN2MAXPKTL (USB_AOTG_BASE + 0x3E4)
  673. #define IN2MAXPKTH (USB_AOTG_BASE + 0x3E5)
  674. #define IN2MAXPKT IN2MAXPKTL
  675. #define IN3MAXPKTL (USB_AOTG_BASE + 0x3E6)
  676. #define IN3MAXPKTH (USB_AOTG_BASE + 0x3E7)
  677. #define IN3MAXPKT IN3MAXPKTL
  678. #define IN4MAXPKTL (USB_AOTG_BASE + 0x3E8)
  679. #define IN4MAXPKTH (USB_AOTG_BASE + 0x3E9)
  680. #define IN4MAXPKT IN4MAXPKTL
  681. #define IN5MAXPKTL (USB_AOTG_BASE + 0x3EA)
  682. #define IN5MAXPKTH (USB_AOTG_BASE + 0x3EB)
  683. #define IN5MAXPKT IN5MAXPKTL
  684. #define IN6MAXPKTL (USB_AOTG_BASE + 0x3EC)
  685. #define IN6MAXPKTH (USB_AOTG_BASE + 0x3ED)
  686. #define IN6MAXPKT IN6MAXPKTL
  687. #define INxMAXPKT(ep) (IN1MAXPKT + (ep - 1) * 2)
  688. /************************************ PHY ************************************/
  689. /************************************ DMA ************************************/
  690. /* IN Endpoint DMA */
  691. #define IN1_DMACTL (USB_AOTG_BASE + 0x430)
  692. #define IN1_DMALEN1L (USB_AOTG_BASE + 0x434)
  693. #define IN1_DMALEN1M (USB_AOTG_BASE + 0x435)
  694. #define IN1_DMALEN1H (USB_AOTG_BASE + 0x436)
  695. #define IN1_DMALEN2L (USB_AOTG_BASE + 0x438)
  696. #define IN1_DMALEN2M (USB_AOTG_BASE + 0x439)
  697. #define IN1_DMALEN2H (USB_AOTG_BASE + 0x43A)
  698. #define IN1_DMAREMAIN1L (USB_AOTG_BASE + 0x43C)
  699. #define IN1_DMAREMAIN1M (USB_AOTG_BASE + 0x43D)
  700. #define IN1_DMAREMAIN1H (USB_AOTG_BASE + 0x43E)
  701. #define IN1_DMAREMAIN2L (USB_AOTG_BASE + 0x440)
  702. #define IN1_DMAREMAIN2M (USB_AOTG_BASE + 0x441)
  703. #define IN1_DMAREMAIN2H (USB_AOTG_BASE + 0x442)
  704. /* OUT Endpoint DMA */
  705. #define OUT2_DMACTL (USB_AOTG_BASE + 0x444)
  706. #define OUT2_DMALENL (USB_AOTG_BASE + 0x448)
  707. #define OUT2_DMALENM (USB_AOTG_BASE + 0x449)
  708. #define OUT2_DMALENH (USB_AOTG_BASE + 0x44A)
  709. #define OUT2_DMAREMAINL (USB_AOTG_BASE + 0x44C)
  710. #define OUT2_DMAREMAINM (USB_AOTG_BASE + 0x44D)
  711. #define OUT2_DMAREMAINH (USB_AOTG_BASE + 0x44E)
  712. /* 0: normal; 1: reset */
  713. #define DMACTL_FIFORST 7
  714. /* 0: burst8; 1: single */
  715. #define DMACTL_MODE 4
  716. /* 0: disabled; 1: enabled */
  717. #define DMACTL_AUTOLOAD 3
  718. /* 0: disabled; 1: enabled */
  719. #define DMACTL_START 0
  720. /********************************* Functions *********************************/
  721. /*
  722. * Turn USB controller power on
  723. */
  724. static inline void usb_aotg_power_on(void)
  725. {
  726. }
  727. /*
  728. * Turn USB controller power off
  729. */
  730. static inline void usb_aotg_power_off(void)
  731. {
  732. }
  733. /*
  734. * USB PHY configuration
  735. */
  736. static void usb_phy_setting(uint8_t reg, uint8_t value)
  737. {
  738. }
  739. static inline void usb_aotg_reset_specific(void)
  740. {
  741. }
  742. static inline void usb_aotg_disable_specific(void)
  743. {
  744. }
  745. static inline void aotg_dc_phy_init(void)
  746. {
  747. }
  748. static inline int aotg_dc_epout_alloc_fifo_specific(uint8_t ep_idx)
  749. {
  750. switch (ep_idx) {
  751. case USB_AOTG_OUT_EP_1:
  752. usb_write32(EP1OUT_STADDR, EP1OUT_FIFO_START);
  753. break;
  754. case USB_AOTG_OUT_EP_2:
  755. usb_write32(EP2OUT_STADDR, EP2OUT_FIFO_START);
  756. break;
  757. case USB_AOTG_OUT_EP_3:
  758. usb_write32(EP3OUT_STADDR, EP3OUT_FIFO_START);
  759. break;
  760. case USB_AOTG_OUT_EP_4:
  761. usb_write32(EP4OUT_STADDR, EP4OUT_FIFO_START);
  762. break;
  763. case USB_AOTG_OUT_EP_5:
  764. usb_write32(EP5OUT_STADDR, EP5OUT_FIFO_START);
  765. break;
  766. case USB_AOTG_OUT_EP_6:
  767. usb_write32(EP6OUT_STADDR, EP6OUT_FIFO_START);
  768. break;
  769. default:
  770. return -EINVAL;
  771. }
  772. return 0;
  773. }
  774. static inline int aotg_dc_epin_alloc_fifo_specific(uint8_t ep_idx)
  775. {
  776. switch (ep_idx) {
  777. case USB_AOTG_IN_EP_1:
  778. usb_write32(EP1IN_STADDR, EP1IN_FIFO_START);
  779. break;
  780. case USB_AOTG_IN_EP_2:
  781. usb_write32(EP2IN_STADDR, EP2IN_FIFO_START);
  782. break;
  783. case USB_AOTG_IN_EP_3:
  784. usb_write32(EP3IN_STADDR, EP3IN_FIFO_START);
  785. break;
  786. case USB_AOTG_IN_EP_4:
  787. usb_write32(EP4IN_STADDR, EP4IN_FIFO_START);
  788. break;
  789. case USB_AOTG_IN_EP_5:
  790. usb_write32(EP5IN_STADDR, EP5IN_FIFO_START);
  791. break;
  792. case USB_AOTG_IN_EP_6:
  793. usb_write32(EP6IN_STADDR, EP6IN_FIFO_START);
  794. break;
  795. default:
  796. return -EINVAL;
  797. }
  798. return 0;
  799. }
  800. /*
  801. * Switch FIFO clock to make sure it is available for AOTG
  802. */
  803. static inline int aotg_dc_fifo_enable(void)
  804. {
  805. usb_set_bit32(USB_MEM_CLK_EN, USB_RAM_CLKEN_BIT);
  806. usb_set_bit32(USB_MEM_CLK_SRC, USB_RAM_CLKSRC_BIT);
  807. return 0;
  808. }
  809. static inline int aotg_dc_fifo_disable(void)
  810. {
  811. usb_clear_bit32(USB_MEM_CLK_EN, USB_RAM_CLKEN_BIT);
  812. usb_clear_bit32(USB_MEM_CLK_SRC, USB_RAM_CLKSRC_BIT);
  813. return 0;
  814. }
  815. static inline void aotg_dc_force_fs(void)
  816. {
  817. usb_set_bit8(BKDOOR, HS_DISABLE);
  818. }
  819. static inline int aotg_hc_epout_alloc_fifo_specific(uint8_t ep_idx)
  820. {
  821. switch (ep_idx) {
  822. case USB_AOTG_OUT_EP_1:
  823. usb_write32(EP1OUT_STADDR, EP1OUT_FIFO_START);
  824. break;
  825. case USB_AOTG_OUT_EP_2:
  826. usb_write32(EP2OUT_STADDR, EP2OUT_FIFO_START);
  827. break;
  828. case USB_AOTG_OUT_EP_3:
  829. usb_write32(EP3OUT_STADDR, EP3OUT_FIFO_START);
  830. break;
  831. case USB_AOTG_OUT_EP_4:
  832. usb_write32(EP4OUT_STADDR, EP4OUT_FIFO_START);
  833. break;
  834. case USB_AOTG_OUT_EP_5:
  835. usb_write32(EP5OUT_STADDR, EP5OUT_FIFO_START);
  836. break;
  837. case USB_AOTG_OUT_EP_6:
  838. usb_write32(EP6OUT_STADDR, EP6OUT_FIFO_START);
  839. break;
  840. default:
  841. return -EINVAL;
  842. }
  843. return 0;
  844. }
  845. static inline int aotg_hc_epin_alloc_fifo_specific(uint8_t ep_idx)
  846. {
  847. switch (ep_idx) {
  848. case USB_AOTG_IN_EP_1:
  849. usb_write32(EP1IN_STADDR, EP1IN_FIFO_START);
  850. break;
  851. case USB_AOTG_IN_EP_2:
  852. usb_write32(EP2IN_STADDR, EP2IN_FIFO_START);
  853. break;
  854. case USB_AOTG_IN_EP_3:
  855. usb_write32(EP3IN_STADDR, EP3IN_FIFO_START);
  856. break;
  857. case USB_AOTG_IN_EP_4:
  858. usb_write32(EP4IN_STADDR, EP4IN_FIFO_START);
  859. break;
  860. case USB_AOTG_IN_EP_5:
  861. usb_write32(EP5IN_STADDR, EP5IN_FIFO_START);
  862. break;
  863. case USB_AOTG_IN_EP_6:
  864. usb_write32(EP6IN_STADDR, EP6IN_FIFO_START);
  865. break;
  866. default:
  867. return -EINVAL;
  868. }
  869. return 0;
  870. }
  871. static inline void aotg_hc_phy_init(void)
  872. {
  873. usb_phy_setting(0xe0, 0xa3);
  874. usb_phy_setting(0x84, 0x1a);
  875. usb_phy_setting(0xe7, 0x0b);
  876. usb_phy_setting(0xe7, 0x0f);
  877. usb_phy_setting(0xe3, 0x1e);
  878. usb_phy_setting(0x87, 0x94);
  879. usb_phy_setting(0x91, 0x08);
  880. }
  881. /*
  882. * Switch FIFO clock to make sure it is available for AOTG
  883. */
  884. static inline int aotg_hc_fifo_enable(void)
  885. {
  886. uint32_t value = usb_read32(USB_MEM_CLK_SRC);
  887. value |= (1<<8);
  888. usb_write32(USB_MEM_CLK_SRC, value);
  889. value = usb_read32(USB_MEM_CLK_EN);
  890. value |= (1<<8);
  891. usb_write32(USB_MEM_CLK_EN, value);
  892. return 0;
  893. }
  894. static inline int aotg_hc_fifo_disable(void)
  895. {
  896. uint32_t value = usb_read32(USB_MEM_CLK_SRC);
  897. value |= ~(1<<8);
  898. usb_write32(USB_MEM_CLK_SRC, value);
  899. value = usb_read32(USB_MEM_CLK_EN);
  900. value |= ~(1<<8);
  901. usb_write32(USB_MEM_CLK_EN, value);
  902. return 0;
  903. }
  904. static inline int usb_aotg_dpdm_init(void)
  905. {
  906. usb_write32(USB_DP_GPIO, USB_DP_VALUE);
  907. usb_write32(USB_DM_GPIO, USB_DM_VALUE);
  908. return 0;
  909. }
  910. static inline int usb_aotg_dpdm_exit(void)
  911. {
  912. return 0;
  913. }
  914. #endif /* __USB_AOTG_LEOPARD_H__ */