usb_aotg_andesm.h 24 KB

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