ch56x_usbhs.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. /*
  2. * Copyright (c) 2006-2023, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2022-08-22 Emuzit first version
  9. */
  10. #ifndef __CH56X_USBHS_H__
  11. #define __CH56X_USBHS_H__
  12. #include "soc.h"
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16. #ifdef SOC_SERIES_CH569
  17. #define UEP_ADDRESS_MAX 7
  18. #define UEP_RT_DMA_MASK 0x1fff0
  19. #else
  20. #define UEP_ADDRESS_MAX 4
  21. #define UEP_RT_DMA_MASK 0x0fffc
  22. #endif
  23. union _usb_ctrl
  24. {
  25. uint8_t reg;
  26. struct
  27. {
  28. uint8_t dma_en : 1; // RW, USB DMA and DMA interrupt enable bit
  29. uint8_t clr_all : 1; // RW, Empty USB interrupt flag and FIFO
  30. uint8_t reset_sie : 1; // RW, Forcibly reset the USB SIE
  31. uint8_t int_busy : 1; // RW, Auto pause enable bit @ RB_USB_IF_TRANSFER
  32. uint8_t pu_en : 1; // RW, device & pull-up-R enable, DEVICE mode
  33. uint8_t sptp_mask : 2; // RW, USB bus signal transfer rate selection bit
  34. uint8_t mode : 1; // RW, USB working mode selection bit
  35. };
  36. };
  37. #define RB_USB_DMA_EN 0x01
  38. #define RB_USB_CLR_ALL 0x02
  39. #define RB_USB_RESET_SIE 0x04
  40. #define RB_USB_INT_BUSY 0x08
  41. #define RB_DEV_PU_EN 0x10
  42. #define RB_USB_SPTP_MASK 0x60
  43. #define RB_USB_MODE 0x80
  44. #define USBHS_FULL_SPEED 0
  45. #define USBHS_HIGH_SPEED 1
  46. #define USBHS_LOW_SPEED 2
  47. #define USBHS_DEVICE_MODE 0
  48. #define USBHS_HOST_MODE 1
  49. #define RB_SPTP_FULL_SPEED (USBHS_FULL_SPEED << 5)
  50. #define RB_SPTP_HIGH_SPEED (USBHS_HIGH_SPEED << 5)
  51. #define RB_SPTP_LOW_SPEED (USBHS_LOW_SPEED << 5)
  52. #define RB_USB_DEVICE_MODE (USBHS_DEVICE_MODE << 7)
  53. #define RB_USB_HOST_MODE (USBHS_HOST_MODE << 7)
  54. union _usb_int_en
  55. {
  56. uint8_t reg;
  57. struct
  58. {
  59. uint8_t busrst : 1; // RW, USB bus reset event IE, DEVICE mode
  60. uint8_t trans : 1; // RW, USB transfer complete interrupt enable
  61. uint8_t suspend : 1; // RW, USB bus suspend/wake-up event IE
  62. uint8_t sof : 1; // RW, SOF packet/timing interrupt enable
  63. uint8_t fifoov : 1; // RW, Internal FIFO overflow interrupt enable
  64. #ifdef SOC_SERIES_CH569
  65. uint8_t setupact : 1; // RW, SETUP transaction complete interrupt
  66. uint8_t isoact : 1; // RW, ISOchronous token received IE
  67. uint8_t dev_nak : 1; // RW, NAK interrupt enable, DEVICE mode
  68. #else
  69. uint8_t resv_5 : 1;
  70. uint8_t dev_nak : 1; // RW, NAK interrupt enable, DEVICE mode
  71. uint8_t dev_sof : 1; // RW, SOF packet received IE, DEVICE mode
  72. #endif
  73. };
  74. struct
  75. {
  76. uint8_t detect : 1; // RW, USB device connect/disconnect IE, HOST mode
  77. uint8_t stuff_1 : 7;
  78. };
  79. };
  80. #define RB_USB_IE_BUSRST 0x01
  81. #define RB_USB_IE_DETECT 0x01
  82. #define RB_USB_IE_TRANS 0x02
  83. #define RB_USB_IE_SUSPEND 0x04
  84. #define RB_USB_IE_SOF 0x08
  85. #define RB_USB_IE_FIFOOV 0x10
  86. #ifdef SOC_SERIES_CH569
  87. #define RB_USB_IE_SETUPACT 0x20
  88. #define RB_USB_IE_ISOACT 0x40
  89. #define RB_USB_IE_DEV_NAK 0x80
  90. #else
  91. #define RB_USB_IE_DEV_NAK 0x40
  92. #define RB_USB_IE_DEV_SOF 0x80
  93. #endif
  94. union _usb_suspend
  95. {
  96. uint8_t reg;
  97. struct
  98. {
  99. uint8_t resv_0 : 1;
  100. uint8_t dev_wakeup : 1; // RW, Remote wake-up control bit
  101. uint8_t resv_2 : 6;
  102. };
  103. };
  104. #define RB_DEV_WAKEUP 0x02
  105. union _usb_spd_type
  106. {
  107. uint8_t reg;
  108. struct
  109. {
  110. uint8_t speed_mask : 2; // RO, Actual transfer speed
  111. uint8_t resv_2 : 6;
  112. };
  113. };
  114. #define RB_USBSPEED_MASK 0x03 // same USBHS_FULL_SPEED...
  115. union _usb_mis_st
  116. {
  117. uint8_t reg;
  118. struct
  119. {
  120. uint8_t split_en : 1; // RO, SPLIT packet transmission enabled, HOST mode
  121. uint8_t attach : 1; // RO, USB device connection status bit, HOST mode
  122. uint8_t bus_suspend : 1; // RO, USB suspend status bit
  123. uint8_t bus_reset : 1; // RO, USB bus reset status bit
  124. uint8_t fifo_rdy : 1; // RO, USB receive FIFO data ready status bit
  125. uint8_t sie_free : 1; // RO, Free status bit of USB protocol processor
  126. uint8_t sof_act : 1; // RO, SOF packet transfer status bit, HOST mode
  127. uint8_t sof_pres : 1; // RO, SOF packet presage status bit, HOST mode
  128. };
  129. };
  130. #define RB_HOST_SPLIT_EN 0x01
  131. #define RB_USB_ATTACH 0x02
  132. #define RB_USBBUS_SUSPEND 0x04
  133. #define RB_USBBUS_RESET 0x08
  134. #define RB_USB_FIFO_RDY 0x10
  135. #define RB_USB_SIE_FREE 0x20
  136. #define RB_USB_SOF_ACT 0x40
  137. #define RB_USB_SOF_PRES 0x80
  138. union _usb_int_fg
  139. {
  140. uint8_t reg;
  141. struct
  142. {
  143. uint8_t busrst : 1; // RW1, USB bus reset event IF, DEVICE mode
  144. uint8_t transfer : 1; // RW1, USB transmission complete interrupt flag
  145. uint8_t suspend : 1; // RW1, USB bus suspend/wake-up event IF
  146. uint8_t hst_sof : 1; // RW1, SOF timing interrupt flag bit, HOST mode
  147. uint8_t fifoov : 1; // RW1, USB FIFO overflow interrupt flag
  148. uint8_t setupact : 1; // RW1, SETUP transaction complete IF (CH569)
  149. uint8_t isoact : 1; // RW1, ISOchronous token received IF (CH569)
  150. uint8_t resv_7 : 1;
  151. };
  152. struct
  153. {
  154. uint8_t detect : 1; // RW1, USB device connect/disconnect IF, HOST mode
  155. uint8_t stuff_1 : 7;
  156. };
  157. };
  158. #define RB_USB_IF_BUSRST 0x01
  159. #define RB_USB_IF_DETECT 0x01
  160. #define RB_USB_IF_TRANSFER 0x02
  161. #define RB_USB_IF_SUSPEND 0x04
  162. #define RB_USB_IF_HST_SOF 0x08
  163. #define RB_USB_IF_FIFOOV 0x10
  164. #define RB_USB_IF_SETUPACT 0x20
  165. #define RB_USB_IF_ISOACT 0x40
  166. union _usb_int_st
  167. {
  168. uint8_t reg;
  169. struct
  170. {
  171. uint8_t host_res_mask : 4; // RO, Current response PID, HOST mode
  172. uint8_t dev_token_mask : 2; // RO, Current token PID, DEVICE mode
  173. uint8_t st_togok : 1; // RO, Current transmit DATA0/1 sync state
  174. uint8_t st_nak : 1; // RO, NAK response status bit, DEVICE mode
  175. };
  176. struct
  177. {
  178. uint8_t dev_endp_mask : 4; // RO, Current endpoint number, DEVICE mode
  179. uint8_t stuff_4 : 4;
  180. };
  181. };
  182. #define RB_HOST_RES_MASK 0x0f
  183. #define RB_DEV_ENDP_MASK 0x0f
  184. #define RB_DEV_TOKEN_MASK 0x30
  185. #define RB_USB_ST_TOGOK 0x40
  186. #define RB_USB_ST_NAK 0x80
  187. #define DEV_TOKEN_OUT 0
  188. #define DEV_TOKEN_SOF 1
  189. #define DEV_TOKEN_IN 2
  190. #define DEV_TOKEN_SETUP 3 // CH567/CH568
  191. #define RB_DEV_TOKEN_OUT (DEV_TOKEN_OUT << 4)
  192. #define RB_DEV_TOKEN_SOF (DEV_TOKEN_SOF << 4)
  193. #define RB_DEV_TOKEN_IN (DEV_TOKEN_IN << 4)
  194. /*
  195. * RB_UEPn_ RB_UEPn_ RB_UEPn_ R32_UEPn_DMA as starting address, low to high
  196. * RX_EN TX_EN BUF_MOD
  197. * 0 0 x Endpoint is disabled, UEPn_DMA not used
  198. * 1 0 0 1st address of RX (OUT) buffer is R32_UEPn_RX_DMA
  199. * 1 0 1 RB_UEP_R_TOG_MASK=0, use R32_UEPn_RX_DMA
  200. * RB_UEP_R_TOG_MASK=1, use R32_UEPn_TX_DMA
  201. * 0 1 0 1st address of TX (IN) buffer is R32_UEPn_TX_DMA
  202. * 0 1 1 RB_UEP_T_TOG_MASK=0, use R32_UEPn_TX_DMA
  203. * RB_UEP_T_TOG_MASK=1, use R32_UEPn_RX_DMA
  204. */
  205. #define RB_UEP_BUF_MOD 0x01
  206. #define RB_UEP_TX_EN 0x04
  207. #define RB_UEP_RX_EN 0x08
  208. /* UEP_MOD offset 0 */
  209. #define RB_UEP4_BUF_MOD 0x01
  210. #define RB_UEP4_TX_EN 0x04
  211. #define RB_UEP4_RX_EN 0x08
  212. #define RB_UEP1_BUF_MOD 0x10
  213. #define RB_UEP1_TX_EN 0x40
  214. #define RB_UEP1_RX_EN 0x80
  215. /* UEP_MOD offset 1 */
  216. #define RB_UEP2_BUF_MOD 0x01
  217. #define RB_UEP2_TX_EN 0x04
  218. #define RB_UEP2_RX_EN 0x08
  219. #define RB_UEP3_BUF_MOD 0x10
  220. #define RB_UEP3_TX_EN 0x40
  221. #define RB_UEP3_RX_EN 0x80
  222. /* UEP_MOD offset 2 */
  223. #define RB_UEP5_BUF_MOD 0x01
  224. #define RB_UEP5_TX_EN 0x04
  225. #define RB_UEP5_RX_EN 0x08
  226. #define RB_UEP6_BUF_MOD 0x10
  227. #define RB_UEP6_TX_EN 0x40
  228. #define RB_UEP6_RX_EN 0x80
  229. /* UEP_MOD offset 3 */
  230. #define RB_UEP7_BUF_MOD 0x01
  231. #define RB_UEP7_TX_EN 0x04
  232. #define RB_UEP7_RX_EN 0x08
  233. /* each nibble is an ep index map : {hi_lo_nibble(1), reg_offset(3)} */
  234. #define UEP_MOD_MAP 0x3a209180
  235. #define uep_mod_offset(ep) (((UEP_MOD_MAP >> (ep * 4)) & 3))
  236. #define uep_mod_shift(ep) (((UEP_MOD_MAP >> (ep * 4)) & 8) ? 4 : 0)
  237. union _uep_rt_ctrl
  238. {
  239. uint8_t reg;
  240. struct
  241. {
  242. uint8_t res_mask : 2; // RW, response control bits
  243. uint8_t res_no : 1; // RW, not expecting response
  244. uint8_t tog_mask : 2; // RW, transmit/expect DATAx
  245. uint8_t autotog : 1; // RW, auto DATAx toggle (not for EP0)
  246. uint8_t resv_6 : 2;
  247. };
  248. };
  249. #define RB_UEP_RES_MASK 0x03
  250. #define RB_UEP_RES_NO 0x04
  251. #define RB_UEP_TOG_MASK 0x18
  252. #define RB_UEP_AUTOTOG 0x20
  253. #define UEP_RES_ACK 0
  254. #define UEP_RES_NYET 1
  255. #define UEP_RES_NAK 2
  256. #define UEP_RES_STALL 3
  257. #define UEP_TOG_DATA0 0
  258. #define UEP_TOG_DATA1 1
  259. #define UEP_TOG_DATA2 2
  260. #define UEP_TOG_MDATA 3
  261. #define RB_UEP_RES_ACK (UEP_RES_ACK << 0)
  262. #define RB_UEP_RES_NYET (UEP_RES_NYET << 0)
  263. #define RB_UEP_RES_NAK (UEP_RES_NAK << 0)
  264. #define RB_UEP_RES_STALL (UEP_RES_STALL << 0)
  265. #define RB_UEP_TOG_DATA0 (UEP_TOG_DATA0 << 3)
  266. #define RB_UEP_TOG_DATA1 (UEP_TOG_DATA1 << 3)
  267. #define RB_UEP_TOG_DATA2 (UEP_TOG_DATA2 << 3)
  268. #define RB_UEP_TOG_MDATA (UEP_TOG_MDATA << 3)
  269. union _uh_rt_ctrl
  270. {
  271. uint8_t reg;
  272. struct
  273. {
  274. uint8_t res_mask : 2; // RW, response control bits
  275. uint8_t res_no : 1; // RW, not expecting response
  276. uint8_t tog_mask : 2; // RW, expected DATAx
  277. uint8_t autotog : 1; // RW, auto DATAx toggle
  278. uint8_t data_no : 1; // RW, not expecting data
  279. uint8_t resv_7 : 1;
  280. };
  281. };
  282. #define RB_UH_RES_MASK 0x03
  283. #define RB_UH_RES_NO 0x04
  284. #define RB_UH_TOG_MASK 0x18
  285. #define RB_UH_AUTOTOG 0x20
  286. #define RB_UH_DATA_NO 0x40
  287. #define UH_RES_ACK 0
  288. #define UH_RES_NYET 1
  289. #define UH_RES_NAK 2
  290. #define UH_RES_STALL 3
  291. #define UH_TOG_DATA0 0
  292. #define UH_TOG_DATA1 1
  293. #define UH_TOG_DATA2 2
  294. #define UH_TOG_MDATA 3
  295. #define RB_UH_RES_ACK (UH_RES_ACK << 0)
  296. #define RB_UH_RES_NYET (UH_RES_NYET << 0)
  297. #define RB_UH_RES_NAK (UH_RES_NAK << 0)
  298. #define RB_UH_RES_STALL (UH_RES_STALL << 0)
  299. #define RB_UH_TOG_DATA0 (UH_TOG_DATA0 << 3)
  300. #define RB_UH_TOG_DATA1 (UH_TOG_DATA1 << 3)
  301. #define RB_UH_TOG_DATA2 (UH_TOG_DATA2 << 3)
  302. #define RB_UH_TOG_MDATA (UH_TOG_MDATA << 3)
  303. union _uhost_ctrl
  304. {
  305. uint8_t reg;
  306. struct
  307. {
  308. uint8_t bus_reset : 1; // RW, USB host transmit bus reset signal
  309. uint8_t bus_suspend : 1; // RW, USB host transmit suspend signal
  310. uint8_t bus_resume : 1; // RW, wake up device when bus suspended
  311. uint8_t resv_3 : 4;
  312. uint8_t autosof_en : 1; // RW, Auto generate SOF packet enable (CH569)
  313. };
  314. };
  315. #define RB_UH_BUS_RESET 0x01
  316. #define RB_UH_BUS_SUSPEND 0x02
  317. #define RB_UH_BUS_RESUME 0x04
  318. #define RB_UH_AUTOSOF_EN 0x80
  319. union _uh_ep_mod
  320. {
  321. uint8_t reg;
  322. struct
  323. {
  324. uint8_t rbuf_mod : 1; // RW, CH567/CH568 only
  325. uint8_t resv_1 : 2;
  326. uint8_t rx_en : 1; // RW, enable HOST receiver (IN)
  327. uint8_t tbuf_mod : 1; // RW, CH567/CH568 only
  328. uint8_t resv_5 : 1;
  329. uint8_t tx_en : 1; // RW, enable HOST transmitter (SETUP/OUT)
  330. uint8_t resv_7 : 1;
  331. };
  332. };
  333. #define RB_UH_RBUF_MOD 0x01
  334. #define RB_UH_RX_EN 0x08
  335. #define RB_UH_TBUF_MOD 0x10
  336. #define RB_UH_TX_EN 0x40
  337. union _uh_ep_pid
  338. {
  339. uint16_t reg;
  340. struct
  341. {
  342. uint8_t epnum_mask : 4; // RW, Set endpoint number of the target device
  343. uint8_t token_mask : 4; // RW, Set the token PID packet identification
  344. uint8_t resv;
  345. };
  346. };
  347. #define RB_UH_EPNUM_MASK 0x0f
  348. #define RB_UH_TOKEN_MASK 0xf0
  349. #ifndef SOC_SERIES_CH569
  350. union _uh_setup
  351. {
  352. uint8_t reg;
  353. struct
  354. {
  355. uint8_t resv_0 : 6;
  356. uint8_t sof_en : 1; // WO, Auto generate SOF packet enable
  357. uint8_t resv_7 : 1;
  358. };
  359. };
  360. #define RB_UH_SOF_EN 0x40
  361. #endif
  362. /*
  363. * USBHS Global Registers :
  364. *
  365. * 0x00 R8_USB_CTRL: USB control register
  366. * 0x02 R8_USB_INT_EN: USB interrupt enable register
  367. * 0x03 R8_USB_DEV_AD: USB addresss register
  368. * 0x04 R16_USB_FRAME_NO: USBHS frame number register
  369. * 0x06 R8_USB_SUSPEND: USB suspend control register
  370. * 0x08 R8_USB_SPD_TYPE: USB current speed type register
  371. * 0x09 R8_USB_MIS_ST: USB miscellaneous status register
  372. * 0x0a R8_USB_INT_FG: USB interrupt flag register
  373. * 0x0b R8_USB_INT_ST: USB interrpt status register
  374. * 0x0c R16_USB_RX_LEN: USB reception length register
  375. */
  376. /*
  377. * CH565/CH569 USBHS DEVICE Related Registers :
  378. *
  379. * 0x10 R8_UEP4_1_MOD: Endpoint 1(9) / 4(8/12) mode control register
  380. * 0x11 R8_UEP2_3_MOD: Endpoint 2(10) / 3(11) mode control register
  381. * 0x12 R8_UEP5_6_MOD: Endpoint 5(13) / 6(14) mode control register
  382. * 0x13 R8_UEP7_MOD: Endpoint 7(15) mode control register
  383. * 0x14 R32_UEP0_RT_DMA: Start address of endpoint0 buffer
  384. * 0x18 R32_UEP1_RX_DMA: Start address of endpoint 1(9) receive buffer
  385. * 0x1c R32_UEP2_RX_DMA: Start address of endpoint 2(10) receive buffer
  386. * 0x20 R32_UEP3_RX_DMA: Start address of endpoint 3(11) receive buffer
  387. * 0x24 R32_UEP4_RX_DMA: Start address of endpoint 4(8/12) receive buffer
  388. * 0x28 R32_UEP5_RX_DMA: Start address of endpoint 5(13) receive buffer
  389. * 0x2c R32_UEP6_RX_DMA: Start address of endpoint 6(14) receive buffer
  390. * 0x30 R32_UEP7_RX_DMA: Start address of endpoint 7(15) receive buffer
  391. * 0x34 R32_UEP1_TX_DMA: Start address of endpoint 1(9) transmit buffer
  392. * 0x38 R32_UEP2_TX_DMA: Start address of endpoint 2(10) transmit buffer
  393. * 0x3c R32_UEP3_TX_DMA: Start address of endpoint 3(11) transmit buffer
  394. * 0x40 R32_UEP4_TX_DMA: Start address of endpoint 4(8/12) transmit buffer
  395. * 0x44 R32_UEP5_TX_DMA: Start address of endpoint 5(13) transmit buffer
  396. * 0x48 R32_UEP6_TX_DMA: Start address of endpoint 6(14) transmit buffer
  397. * 0x4c R32_UEP7_TX_DMA: Start address of endpoint 7(15) transmit buffer
  398. * 0x50 R16_UEP0_MAX_LEN: Endpoint 0 receive maximum length packet register
  399. * 0x54 R16_UEP1_MAX_LEN: Endpoint 1(9) receive maximum length packet register
  400. * 0x58 R16_UEP2_MAX_LEN: Endpoint 2(10) receive maximum length packet register
  401. * 0x5c R16_UEP3_MAX_LEN: Endpoint 3(11) receive maximum length packet register
  402. * 0x60 R16_UEP4_MAX_LEN: Endpoint 4(8/12) receive maximum length packet register
  403. * 0x64 R16_UEP5_MAX_LEN: Endpoint 5(13) receive maximum length packet register
  404. * 0x68 R16_UEP6_MAX_LEN: Endpoint 6(14) receive maximum length packet register
  405. * 0x6c R16_UEP7_MAX_LEN: Endpoint 7(15) receive maximum length packet register
  406. * 0x70 R16_UEP0_T_LEN: Endpoint 0 transmission length register
  407. * 0x72 R8_UEP0_TX_CTRL: Endpoint 0 transmit control register
  408. * 0x73 R8_UEP0_RX_CTRL: Endpoint 0 receive control register
  409. * 0x74 R16_UEP1_T_LEN: Endpoint 1(9) transmission length register
  410. * 0x76 R8_UEP1_TX_CTRL: Endpoint 1(9) transmit control register
  411. * 0x77 R8_UEP1_RX_CTRL: Endpoint 1(9) receive control register
  412. * 0x78 R16_UEP2_T_LEN: Endpoint 2(10) transmission length register
  413. * 0x7a R8_UEP2_TX_CTRL: Endpoint 2(10) transmit control register
  414. * 0x7b R8_UEP2_RX_CTRL: Endpoint 2(10) receive control register
  415. * 0x7c R16_UEP3_T_LEN: Endpoint 3(11) transmission length register
  416. * 0x7e R8_UEP3_TX_CTRL: Endpoint 3(11) transmit control register
  417. * 0x7f R8_UEP3_RX_CTRL: Endpoint 3(11) receive control register
  418. * 0x80 R16_UEP4_T_LEN: Endpoint 4(8/12) transmission length register
  419. * 0x82 R8_UEP4_TX_CTRL: Endpoint 4(8/12) transmit control register
  420. * 0x83 R8_UEP4_RX_CTRL: Endpoint 4(8/12) receive control register
  421. * 0x84 R16_UEP5_T_LEN: Endpoint 5(13) transmission length register
  422. * 0x86 R8_UEP5_TX_CTRL: Endpoint 5(13) transmit control register
  423. * 0x87 R8_UEP5_RX_CTRL: Endpoint 5(13) receive control register
  424. * 0x88 R16_UEP6_T_LEN: Endpoint 6(14) transmission length register
  425. * 0x8a R8_UEP6_TX_CTRL: Endpoint 6(14) transmit control register
  426. * 0x8b R8_UEP6_RX_CTRL: Endpoint 6(14) receive control register
  427. * 0x8c R16_UEP7_T_LEN: Endpoint 7(15) transmission length register
  428. * 0x8e R8_UEP7_TX_CTRL: Endpoint 7(15) transmit control register
  429. * 0x8f R8_UEP7_RX_CTRL: Endpoint 7(15) receive control register
  430. *
  431. * CH567/CH568 USBHS DEVICE Related Registers :
  432. *
  433. * 0x10 UEP4_1_MOD: Endpoint 1/4 mode control register
  434. * 0x11 UEP2_3_MOD: Endpoint 2/3 mode control register
  435. * 0x14 UEP0_DMA: Endpoint 0 DMA buffer start address
  436. * 0x18 UEP1_DMA: Endpoint 1 DMA buffer start address
  437. * 0x1c UEP2_DMA: Endpoint 2 DMA buffer start address
  438. * 0x20 UEP3_DMA: Endpoint 3 DMA buffer start address
  439. * 0x24 UEP0_MAX_LEN: Endpoint 0 receive maximum length packet register
  440. * 0x28 UEP1_MAX_LEN: Endpoint 1 receive maximum length packet register
  441. * 0x2c UEP2_MAX_LEN: Endpoint 2 receive maximum length packet register
  442. * 0x30 UEP3_MAX_LEN: Endpoint 3 receive maximum length packet register
  443. * 0x34 UEP4_MAX_LEN: Endpoint 4 receive maximum length packet register
  444. * 0x38 UEP0_T_LEN: Endpoint 0 transmission length register
  445. * 0x3a UEP0_TX_CTRL: Endpoint 0 transmit control register
  446. * 0x3b UEP0_RX_CTRL: Endpoint 0 receive control register
  447. * 0x3c UEP1_T_LEN: Endpoint 1 transmission length register
  448. * 0x3e UEP1_TX_CTRL: Endpoint 1 transmit control register
  449. * 0x3f UEP1_RX_CTRL: Endpoint 1 receive control register
  450. * 0x40 UEP2_T_LEN: Endpoint 2 transmission length register
  451. * 0x42 UEP2_TX_CTRL: Endpoint 2 transmit control register
  452. * 0x43 UEP2_RX_CTRL: Endpoint 2 receive control register
  453. * 0x44 UEP2_T_LEN: Endpoint 3 transmission length register
  454. * 0x46 UEP2_TX_CTRL: Endpoint 3 transmit control register
  455. * 0x47 UEP2_RX_CTRL: Endpoint 3 receive control register
  456. * 0x48 UEP4_T_LEN: Endpoint 4 transmission length register
  457. * 0x4a UEP4_TX_CTRL: Endpoint 4 transmit control register
  458. * 0x4b UEP4_RX_CTRL: Endpoint 4 receive control register
  459. */
  460. /*
  461. * CH565/CH569 USBHS HOST Related Registers :
  462. *
  463. * 0x01 R8_UHOST_CTRL: USB host control register
  464. * 0x11 R8_UH_EP_MOD: USB host endpoint mode register
  465. * 0x1c R32_UH_RX_DMA: USB host receive buffer start address
  466. * 0x3c R32_UH_TX_DMA: USB host transmit buffer start address
  467. * 0x58 R16_UH_MAX_LEN: USB host reception maximum length packet register
  468. * 0x78 R16_UH_EP_PID: USB host token setting register
  469. * 0x7b R8_UH_RX_CTRL: USB host reception endpoint control register
  470. * 0x7c R16_UH_TX_LEN: USB host transmission length register
  471. * 0x7e R8_UH_TX_CTRL: USB host transmission endpoint control register
  472. * 0x80 R16_UH_SPLIT_DATA: USB host transmit SPLIT packet data
  473. *
  474. * CH567/CH568 USBHS HOST Related Registers :
  475. *
  476. * 0x01 UHOST_CTRL: USB host control register
  477. * 0x11 UH_EP_MOD: USB host endpoint mode register
  478. * 0x1c UH_RX_DMA: USB host receive buffer start address
  479. * 0x20 UH_TX_DMA: USB host transmit buffer start address
  480. * 0x2c UH_RX_MAX_LEN: USB host reception maximum length packet register
  481. * 0x3e UH_SETUP: USB host aux config register
  482. * 0x40 UH_EP_PID: USB host token setting register
  483. * 0x43 UH_RX_CTRL: USB host reception endpoint control register
  484. * 0x44 UH_TX_LEN: USB host transmission length register
  485. * 0x46 UH_TX_CTRL: USB host transmission endpoint control register
  486. * 0x48 UH_SPLIT_DATA: USB host transmit SPLIT packet data
  487. */
  488. struct usbhs_registers
  489. {
  490. union
  491. {
  492. /* USB Global Registers */
  493. struct
  494. {
  495. union _usb_ctrl CTRL;
  496. uint8_t stuff_01;
  497. union _usb_int_en INT_EN;
  498. uint8_t DEV_AD;
  499. uint16_t FRAME_NO;
  500. union _usb_suspend SUSPEND;
  501. uint8_t resv_07;
  502. union _usb_spd_type SPD_TYPE;
  503. union _usb_mis_st MIS_ST;
  504. union _usb_int_fg INT_FG;
  505. union _usb_int_st INT_ST;
  506. uint16_t RX_LEN;
  507. };
  508. /* USB DEVICE Related Registers */
  509. struct
  510. {
  511. uint32_t stuff_gr[4];
  512. union
  513. {
  514. uint8_t UEP_MOD[4];
  515. uint32_t R32_UEP_MOD;
  516. };
  517. #ifdef SOC_SERIES_CH569
  518. union
  519. {
  520. struct
  521. {
  522. uint32_t UEP0_RT_DMA;
  523. uint32_t stuff_rt[14];
  524. };
  525. struct
  526. {
  527. uint32_t UEP_RX_DMA[8]; // UEP_RX_DMA[0] NOT exist
  528. uint32_t stuff_rx[7];
  529. };
  530. struct
  531. {
  532. uint32_t stuff_tx[7];
  533. uint32_t UEP_TX_DMA[8]; // UEP_TX_DMA[0] NOT exist
  534. };
  535. };
  536. #else
  537. struct
  538. {
  539. uint16_t reg;
  540. uint16_t resv;
  541. } UEP_DMA[4];
  542. #endif
  543. struct
  544. {
  545. uint16_t reg;
  546. uint16_t resv;
  547. } UEP_MAX_LEN[UEP_ADDRESS_MAX + 1];
  548. struct
  549. {
  550. uint16_t t_len; // MSB 5 bits are fixed to 0
  551. union _uep_rt_ctrl TX_CTRL;
  552. union _uep_rt_ctrl RX_CTRL;
  553. } UEP_CTRL[UEP_ADDRESS_MAX + 1];
  554. };
  555. /* USB HOST Related Registers */
  556. #ifdef SOC_SERIES_CH569
  557. struct
  558. {
  559. uint8_t stuff_00;
  560. union _uhost_ctrl UHOST_CTRL;
  561. uint8_t stuff_02[15];
  562. union _uh_ep_mod UH_EP_MOD;
  563. uint8_t stuff_12[10];
  564. uint32_t UH_RX_DMA;
  565. uint32_t stuff_20[7];
  566. uint32_t UH_TX_DMA;
  567. uint32_t stuff_40[6];
  568. uint16_t UH_MAX_LEN;
  569. uint16_t stuff_5a[15];
  570. union _uh_ep_pid UH_EP_PID;
  571. uint8_t stuff_7a;
  572. union _uh_rt_ctrl UH_RX_CTRL;
  573. uint16_t UH_TX_LEN;
  574. union _uh_rt_ctrl UH_TX_CTRL;
  575. uint8_t stuff_7f;
  576. uint16_t UH_SPLIT_DATA;
  577. uint16_t stuff_82[7];
  578. };
  579. #else
  580. struct
  581. {
  582. uint8_t stuff_00;
  583. union _uhost_ctrl UHOST_CTRL;
  584. uint8_t stuff_02[15];
  585. union _uh_ep_mod UH_EP_MOD;
  586. uint8_t stuff_12[10];
  587. uint32_t UH_RX_DMA;
  588. uint32_t UH_TX_DMA;
  589. uint32_t stuff_24[2];
  590. uint16_t UH_MAX_LEN;
  591. uint16_t stuff_2e[8];
  592. uint8_t UH_SETUP;
  593. uint8_t stuff_3f;
  594. union _uh_ep_pid UH_EP_PID;
  595. uint8_t stuff_42;
  596. union _uh_rt_ctrl UH_RX_CTRL;
  597. uint16_t UH_TX_LEN;
  598. union _uh_rt_ctrl UH_TX_CTRL;
  599. uint8_t stuff_47;
  600. uint16_t UH_SPLIT_DATA;
  601. uint16_t stuff_4a;
  602. };
  603. #endif
  604. };
  605. } __packed;
  606. #ifdef SOC_SERIES_CH569
  607. CHECK_STRUCT_SIZE(struct usbhs_registers, 0x90);
  608. #else
  609. CHECK_STRUCT_SIZE(struct usbhs_registers, 0x4c);
  610. #endif
  611. rt_inline void _uep_mod_set(volatile struct usbhs_registers *usbhs,
  612. int ep_idx, uint8_t mod)
  613. {
  614. int reg_n = uep_mod_offset(ep_idx);
  615. int shift = uep_mod_shift(ep_idx);
  616. int mask = 0x0f << shift;
  617. /* ep_idx must be 1 ~ UEP_ADDRESS_MAX */
  618. usbhs->UEP_MOD[reg_n] = (usbhs->UEP_MOD[reg_n] & ~mask) | (mod << shift);
  619. }
  620. rt_inline uint8_t _uep_mod_get(volatile struct usbhs_registers *usbhs, int ep_idx)
  621. {
  622. int reg_n = uep_mod_offset(ep_idx);
  623. int shift = uep_mod_shift(ep_idx);
  624. /* ep_idx should be 1 ~ UEP_ADDRESS_MAX */
  625. return (usbhs->UEP_MOD[reg_n] >> shift) & 0x0f;
  626. }
  627. #ifdef __cplusplus
  628. }
  629. #endif
  630. #endif