usb_glue_mcx.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  1. /*
  2. * Copyright (c) 2024 ~ 2025, sakumisu
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include "usbd_core.h"
  7. #include "usbh_core.h"
  8. #include "fsl_common.h"
  9. #include "fsl_cache.h"
  10. #include "usb_chipidea_reg.h"
  11. __WEAK void USBD_IRQHandler(uint8_t busid)
  12. {
  13. }
  14. __WEAK void USBH_IRQHandler(uint8_t busid)
  15. {
  16. }
  17. #if !defined(CONFIG_USB_EHCI_NXP)
  18. #error "mcx ehci must config CONFIG_USB_EHCI_NXP"
  19. #endif
  20. #if !defined(CONFIG_USB_EHCI_HCCR_OFFSET) || CONFIG_USB_EHCI_HCCR_OFFSET != 0x100
  21. #error "mcx ehci must config CONFIG_USB_EHCI_HCCR_OFFSET to 0x100"
  22. #endif
  23. #define USB_DEVICE_CONFIG_EHCI 1
  24. /*! @brief USB controller ID */
  25. typedef enum _usb_controller_index {
  26. kUSB_ControllerKhci0 = 0U, /*!< KHCI 0U */
  27. kUSB_ControllerKhci1 = 1U, /*!< KHCI 1U, Currently, there are no platforms which have two KHCI IPs, this is reserved
  28. to be used in the future. */
  29. kUSB_ControllerEhci0 = 2U, /*!< EHCI 0U */
  30. kUSB_ControllerEhci1 = 3U, /*!< EHCI 1U, Currently, there are no platforms which have two EHCI IPs, this is reserved
  31. to be used in the future. */
  32. kUSB_ControllerLpcIp3511Fs0 = 4U, /*!< LPC USB IP3511 FS controller 0 */
  33. kUSB_ControllerLpcIp3511Fs1 = 5U, /*!< LPC USB IP3511 FS controller 1, there are no platforms which have two IP3511
  34. IPs, this is reserved to be used in the future. */
  35. kUSB_ControllerLpcIp3511Hs0 = 6U, /*!< LPC USB IP3511 HS controller 0 */
  36. kUSB_ControllerLpcIp3511Hs1 = 7U, /*!< LPC USB IP3511 HS controller 1, there are no platforms which have two IP3511
  37. IPs, this is reserved to be used in the future. */
  38. kUSB_ControllerOhci0 = 8U, /*!< OHCI 0U */
  39. kUSB_ControllerOhci1 = 9U, /*!< OHCI 1U, Currently, there are no platforms which have two OHCI IPs, this is reserved
  40. to be used in the future. */
  41. kUSB_ControllerIp3516Hs0 = 10U, /*!< IP3516HS 0U */
  42. kUSB_ControllerIp3516Hs1 = 11U, /*!< IP3516HS 1U, Currently, there are no platforms which have two IP3516HS IPs,
  43. this is reserved to be used in the future. */
  44. kUSB_ControllerDwc30 = 12U, /*!< DWC3 0U */
  45. kUSB_ControllerDwc31 = 13U, /*!< DWC3 1U Currently, there are no platforms which have two Dwc IPs, this is reserved
  46. to be used in the future.*/
  47. } usb_controller_index_t;
  48. /* USB PHY condfiguration */
  49. #define BOARD_USB_PHY_D_CAL (0x04U)
  50. #define BOARD_USB_PHY_TXCAL45DP (0x07U)
  51. #define BOARD_USB_PHY_TXCAL45DM (0x07U)
  52. #define BOARD_XTAL0_CLK_HZ 24000000U /*!< Board xtal0 frequency in Hz */
  53. typedef struct _usb_phy_config_struct {
  54. uint8_t D_CAL; /* Decode to trim the nominal 17.78mA current source */
  55. uint8_t TXCAL45DP; /* Decode to trim the nominal 45-Ohm series termination resistance to the USB_DP output pin */
  56. uint8_t TXCAL45DM; /* Decode to trim the nominal 45-Ohm series termination resistance to the USB_DM output pin */
  57. } usb_phy_config_struct_t;
  58. void *USB_EhciPhyGetBase(uint8_t controllerId)
  59. {
  60. void *usbPhyBase = NULL;
  61. #if ((defined FSL_FEATURE_SOC_USBPHY_COUNT) && (FSL_FEATURE_SOC_USBPHY_COUNT > 0U))
  62. #if defined(USBPHY_STACK_BASE_ADDRS)
  63. uint32_t usbphy_base[] = USBPHY_STACK_BASE_ADDRS;
  64. #else
  65. uint32_t usbphy_base[] = USBPHY_BASE_ADDRS;
  66. #endif
  67. uint32_t *temp;
  68. if (controllerId < (uint8_t)kUSB_ControllerEhci0) {
  69. return NULL;
  70. }
  71. if ((controllerId == (uint8_t)kUSB_ControllerEhci0) || (controllerId == (uint8_t)kUSB_ControllerEhci1)) {
  72. controllerId = controllerId - (uint8_t)kUSB_ControllerEhci0;
  73. } else if ((controllerId == (uint8_t)kUSB_ControllerLpcIp3511Hs0) ||
  74. (controllerId == (uint8_t)kUSB_ControllerLpcIp3511Hs1)) {
  75. controllerId = controllerId - (uint8_t)kUSB_ControllerLpcIp3511Hs0;
  76. } else if ((controllerId == (uint8_t)kUSB_ControllerIp3516Hs0) || (controllerId == (uint8_t)kUSB_ControllerIp3516Hs1)) {
  77. controllerId = controllerId - (uint8_t)kUSB_ControllerIp3516Hs0;
  78. } else {
  79. return NULL;
  80. }
  81. if (controllerId < (sizeof(usbphy_base) / sizeof(usbphy_base[0]))) {
  82. temp = (uint32_t *)usbphy_base[controllerId];
  83. usbPhyBase = (void *)temp;
  84. } else {
  85. return NULL;
  86. }
  87. #endif
  88. return usbPhyBase;
  89. }
  90. /*!
  91. * @brief ehci phy initialization.
  92. *
  93. * This function initialize ehci phy IP.
  94. *
  95. * @param[in] controllerId ehci controller id, please reference to #usb_controller_index_t.
  96. * @param[in] freq the external input clock.
  97. * for example: if the external input clock is 16M, the parameter freq should be 16000000.
  98. *
  99. * @retval 0 cancel successfully.
  100. * @retval -1 the freq value is incorrect.
  101. */
  102. uint32_t USB_EhciPhyInit(uint8_t controllerId, uint32_t freq, usb_phy_config_struct_t *phyConfig)
  103. {
  104. #if ((defined FSL_FEATURE_SOC_USBPHY_COUNT) && (FSL_FEATURE_SOC_USBPHY_COUNT > 0U))
  105. USBPHY_Type *usbPhyBase;
  106. usbPhyBase = (USBPHY_Type *)USB_EhciPhyGetBase(controllerId);
  107. if (NULL == usbPhyBase) {
  108. return (uint8_t)-1;
  109. }
  110. #if ((defined FSL_FEATURE_SOC_ANATOP_COUNT) && (FSL_FEATURE_SOC_ANATOP_COUNT > 0U))
  111. ANATOP->HW_ANADIG_REG_3P0.RW =
  112. (ANATOP->HW_ANADIG_REG_3P0.RW &
  113. (~(ANATOP_HW_ANADIG_REG_3P0_OUTPUT_TRG(0x1F) | ANATOP_HW_ANADIG_REG_3P0_ENABLE_ILIMIT_MASK))) |
  114. ANATOP_HW_ANADIG_REG_3P0_OUTPUT_TRG(0x17) | ANATOP_HW_ANADIG_REG_3P0_ENABLE_LINREG_MASK;
  115. ANATOP->HW_ANADIG_USB2_CHRG_DETECT.SET =
  116. ANATOP_HW_ANADIG_USB2_CHRG_DETECT_CHK_CHRG_B_MASK | ANATOP_HW_ANADIG_USB2_CHRG_DETECT_EN_B_MASK;
  117. #endif
  118. #if (defined USB_ANALOG)
  119. USB_ANALOG->INSTANCE[controllerId - (uint8_t)kUSB_ControllerEhci0].CHRG_DETECT_SET =
  120. USB_ANALOG_CHRG_DETECT_CHK_CHRG_B(1) | USB_ANALOG_CHRG_DETECT_EN_B(1);
  121. #endif
  122. #if ((!(defined FSL_FEATURE_SOC_CCM_ANALOG_COUNT)) && (!(defined FSL_FEATURE_SOC_ANATOP_COUNT)))
  123. usbPhyBase->TRIM_OVERRIDE_EN = 0x001fU; /* override IFR value */
  124. #endif
  125. usbPhyBase->CTRL |= USBPHY_CTRL_SET_ENUTMILEVEL2_MASK; /* support LS device. */
  126. usbPhyBase->CTRL |= USBPHY_CTRL_SET_ENUTMILEVEL3_MASK; /* support external FS Hub with LS device connected. */
  127. /* PWD register provides overall control of the PHY power state */
  128. usbPhyBase->PWD = 0U;
  129. if (((uint8_t)kUSB_ControllerIp3516Hs0 == controllerId) || ((uint8_t)kUSB_ControllerIp3516Hs1 == controllerId) ||
  130. ((uint8_t)kUSB_ControllerLpcIp3511Hs0 == controllerId) ||
  131. ((uint8_t)kUSB_ControllerLpcIp3511Hs1 == controllerId)) {
  132. usbPhyBase->CTRL_SET = USBPHY_CTRL_SET_ENAUTOCLR_CLKGATE_MASK;
  133. usbPhyBase->CTRL_SET = USBPHY_CTRL_SET_ENAUTOCLR_PHY_PWD_MASK;
  134. }
  135. if (NULL != phyConfig) {
  136. /* Decode to trim the nominal 17.78mA current source for the High Speed TX drivers on USB_DP and USB_DM. */
  137. usbPhyBase->TX =
  138. ((usbPhyBase->TX & (~(USBPHY_TX_D_CAL_MASK | USBPHY_TX_TXCAL45DM_MASK | USBPHY_TX_TXCAL45DP_MASK))) |
  139. (USBPHY_TX_D_CAL(phyConfig->D_CAL) | USBPHY_TX_TXCAL45DP(phyConfig->TXCAL45DP) |
  140. USBPHY_TX_TXCAL45DM(phyConfig->TXCAL45DM)));
  141. }
  142. #endif
  143. return (uint8_t)0;
  144. }
  145. /*!
  146. * @brief ehci phy initialization for suspend and resume.
  147. *
  148. * This function initialize ehci phy IP for suspend and resume.
  149. *
  150. * @param[in] controllerId ehci controller id, please reference to #usb_controller_index_t.
  151. * @param[in] freq the external input clock.
  152. * for example: if the external input clock is 16M, the parameter freq should be 16000000.
  153. *
  154. * @retval 0 cancel successfully.
  155. * @retval -1 the freq value is incorrect.
  156. */
  157. uint32_t USB_EhciLowPowerPhyInit(uint8_t controllerId, uint32_t freq, usb_phy_config_struct_t *phyConfig)
  158. {
  159. #if ((defined FSL_FEATURE_SOC_USBPHY_COUNT) && (FSL_FEATURE_SOC_USBPHY_COUNT > 0U))
  160. USBPHY_Type *usbPhyBase;
  161. usbPhyBase = (USBPHY_Type *)USB_EhciPhyGetBase(controllerId);
  162. if (NULL == usbPhyBase) {
  163. return (uint8_t)-1;
  164. }
  165. #if ((!(defined FSL_FEATURE_SOC_CCM_ANALOG_COUNT)) && (!(defined FSL_FEATURE_SOC_ANATOP_COUNT)))
  166. usbPhyBase->TRIM_OVERRIDE_EN = 0x001fU; /* override IFR value */
  167. #endif
  168. #if ((defined USBPHY_CTRL_AUTORESUME_EN_MASK) && (USBPHY_CTRL_AUTORESUME_EN_MASK > 0U))
  169. usbPhyBase->CTRL_CLR |= USBPHY_CTRL_AUTORESUME_EN_MASK;
  170. #else
  171. usbPhyBase->CTRL |= USBPHY_CTRL_ENAUTO_PWRON_PLL_MASK;
  172. #endif
  173. usbPhyBase->CTRL |= USBPHY_CTRL_ENAUTOCLR_CLKGATE_MASK | USBPHY_CTRL_ENAUTOCLR_PHY_PWD_MASK;
  174. usbPhyBase->CTRL |= USBPHY_CTRL_SET_ENUTMILEVEL2_MASK; /* support LS device. */
  175. usbPhyBase->CTRL |= USBPHY_CTRL_SET_ENUTMILEVEL3_MASK; /* support external FS Hub with LS device connected. */
  176. /* PWD register provides overall control of the PHY power state */
  177. usbPhyBase->PWD = 0U;
  178. #if (defined USBPHY_ANACTRL_PFD_CLKGATE_MASK)
  179. /* now the 480MHz USB clock is up, then configure fractional divider after PLL with PFD
  180. * pfd clock = 480MHz*18/N, where N=18~35
  181. * Please note that USB1PFDCLK has to be less than 180MHz for RUN or HSRUN mode
  182. */
  183. usbPhyBase->ANACTRL |= USBPHY_ANACTRL_PFD_FRAC(24); /* N=24 */
  184. usbPhyBase->ANACTRL |= USBPHY_ANACTRL_PFD_CLK_SEL(1); /* div by 4 */
  185. usbPhyBase->ANACTRL &= ~USBPHY_ANACTRL_DEV_PULLDOWN_MASK;
  186. usbPhyBase->ANACTRL &= ~USBPHY_ANACTRL_PFD_CLKGATE_MASK;
  187. while (0U == (usbPhyBase->ANACTRL & USBPHY_ANACTRL_PFD_STABLE_MASK)) {
  188. }
  189. #endif
  190. if (NULL != phyConfig) {
  191. /* Decode to trim the nominal 17.78mA current source for the High Speed TX drivers on USB_DP and USB_DM. */
  192. usbPhyBase->TX =
  193. ((usbPhyBase->TX & (~(USBPHY_TX_D_CAL_MASK | USBPHY_TX_TXCAL45DM_MASK | USBPHY_TX_TXCAL45DP_MASK))) |
  194. (USBPHY_TX_D_CAL(phyConfig->D_CAL) | USBPHY_TX_TXCAL45DP(phyConfig->TXCAL45DP) |
  195. USBPHY_TX_TXCAL45DM(phyConfig->TXCAL45DM)));
  196. }
  197. #endif
  198. return (uint8_t)0;
  199. }
  200. /*!
  201. * @brief ehci phy de-initialization.
  202. *
  203. * This function de-initialize ehci phy IP.
  204. *
  205. * @param[in] controllerId ehci controller id, please reference to #usb_controller_index_t.
  206. */
  207. void USB_EhciPhyDeinit(uint8_t controllerId)
  208. {
  209. #if ((defined FSL_FEATURE_SOC_USBPHY_COUNT) && (FSL_FEATURE_SOC_USBPHY_COUNT > 0U))
  210. USBPHY_Type *usbPhyBase;
  211. usbPhyBase = (USBPHY_Type *)USB_EhciPhyGetBase(controllerId);
  212. if (NULL == usbPhyBase) {
  213. return;
  214. }
  215. #if ((!(defined FSL_FEATURE_SOC_CCM_ANALOG_COUNT)) && (!(defined FSL_FEATURE_SOC_ANATOP_COUNT)))
  216. usbPhyBase->PLL_SIC &= ~USBPHY_PLL_SIC_PLL_POWER_MASK; /* power down PLL */
  217. usbPhyBase->PLL_SIC &= ~USBPHY_PLL_SIC_PLL_EN_USB_CLKS_MASK; /* disable USB clock output from USB PHY PLL */
  218. #endif
  219. usbPhyBase->CTRL |= USBPHY_CTRL_CLKGATE_MASK; /* set to 1U to gate clocks */
  220. #endif
  221. }
  222. /*!
  223. * @brief ehci phy disconnect detection enable or disable.
  224. *
  225. * This function enable/disable host ehci disconnect detection.
  226. *
  227. * @param[in] controllerId ehci controller id, please reference to #usb_controller_index_t.
  228. * @param[in] enable
  229. * 1U - enable;
  230. * 0U - disable;
  231. */
  232. void USB_EhcihostPhyDisconnectDetectCmd(uint8_t controllerId, uint8_t enable)
  233. {
  234. #if ((defined FSL_FEATURE_SOC_USBPHY_COUNT) && (FSL_FEATURE_SOC_USBPHY_COUNT > 0U))
  235. USBPHY_Type *usbPhyBase;
  236. usbPhyBase = (USBPHY_Type *)USB_EhciPhyGetBase(controllerId);
  237. if (NULL == usbPhyBase) {
  238. return;
  239. }
  240. if (0U != enable) {
  241. usbPhyBase->CTRL |= USBPHY_CTRL_ENHOSTDISCONDETECT_MASK;
  242. } else {
  243. usbPhyBase->CTRL &= (~USBPHY_CTRL_ENHOSTDISCONDETECT_MASK);
  244. }
  245. #endif
  246. }
  247. #if ((defined FSL_FEATURE_SOC_USBPHY_COUNT) && (FSL_FEATURE_SOC_USBPHY_COUNT > 0U))
  248. #if ((defined FSL_FEATURE_USBHSD_HAS_EXIT_HS_ISSUE) && (FSL_FEATURE_USBHSD_HAS_EXIT_HS_ISSUE > 0U))
  249. void USB_PhyDeviceForceEnterFSMode(uint8_t controllerId, uint8_t enable)
  250. {
  251. USBPHY_Type *usbPhyBase;
  252. usbPhyBase = (USBPHY_Type *)USB_EhciPhyGetBase(controllerId);
  253. if (NULL == usbPhyBase) {
  254. return;
  255. }
  256. if (0U != enable) {
  257. uint32_t delay = 1000000;
  258. usbPhyBase->DEBUG0_CLR = USBPHY_DEBUG0_CLKGATE_MASK;
  259. while ((0U != (usbPhyBase->USB1_VBUS_DET_STAT & USBPHY_USB1_VBUS_DET_STAT_VBUS_VALID_3V_MASK)) && (0U != delay)) {
  260. delay--;
  261. }
  262. usbPhyBase->USB1_LOOPBACK_SET = USBPHY_USB1_LOOPBACK_UTMI_TESTSTART_MASK;
  263. } else {
  264. usbPhyBase->DEBUG0_CLR = USBPHY_DEBUG0_CLKGATE_MASK;
  265. usbPhyBase->USB1_LOOPBACK_CLR = USBPHY_USB1_LOOPBACK_UTMI_TESTSTART_MASK;
  266. }
  267. }
  268. #endif
  269. #endif
  270. void USB_ClockInit(void)
  271. {
  272. usb_phy_config_struct_t phyConfig = {
  273. BOARD_USB_PHY_D_CAL,
  274. BOARD_USB_PHY_TXCAL45DP,
  275. BOARD_USB_PHY_TXCAL45DM,
  276. };
  277. SPC0->ACTIVE_VDELAY = 0x0500;
  278. /* Change the power DCDC to 1.8v (By deafult, DCDC is 1.8V), CORELDO to 1.1v (By deafult, CORELDO is 1.0V) */
  279. SPC0->ACTIVE_CFG &= ~SPC_ACTIVE_CFG_CORELDO_VDD_DS_MASK;
  280. SPC0->ACTIVE_CFG |= SPC_ACTIVE_CFG_DCDC_VDD_LVL(0x3) | SPC_ACTIVE_CFG_CORELDO_VDD_LVL(0x3) |
  281. SPC_ACTIVE_CFG_SYSLDO_VDD_DS_MASK | SPC_ACTIVE_CFG_DCDC_VDD_DS(0x2u);
  282. /* Wait until it is done */
  283. while (SPC0->SC & SPC_SC_BUSY_MASK)
  284. ;
  285. if (0u == (SCG0->LDOCSR & SCG_LDOCSR_LDOEN_MASK)) {
  286. SCG0->TRIM_LOCK = 0x5a5a0001U;
  287. SCG0->LDOCSR |= SCG_LDOCSR_LDOEN_MASK;
  288. /* wait LDO ready */
  289. while (0U == (SCG0->LDOCSR & SCG_LDOCSR_VOUT_OK_MASK))
  290. ;
  291. }
  292. SYSCON->AHBCLKCTRLSET[2] |= SYSCON_AHBCLKCTRL2_USB_HS_MASK | SYSCON_AHBCLKCTRL2_USB_HS_PHY_MASK;
  293. SCG0->SOSCCFG &= ~(SCG_SOSCCFG_RANGE_MASK | SCG_SOSCCFG_EREFS_MASK);
  294. /* xtal = 20 ~ 30MHz */
  295. SCG0->SOSCCFG = (1U << SCG_SOSCCFG_RANGE_SHIFT) | (1U << SCG_SOSCCFG_EREFS_SHIFT);
  296. SCG0->SOSCCSR |= SCG_SOSCCSR_SOSCEN_MASK;
  297. while (1) {
  298. if (SCG0->SOSCCSR & SCG_SOSCCSR_SOSCVLD_MASK) {
  299. break;
  300. }
  301. }
  302. SYSCON->CLOCK_CTRL |= SYSCON_CLOCK_CTRL_CLKIN_ENA_MASK | SYSCON_CLOCK_CTRL_CLKIN_ENA_FM_USBH_LPT_MASK;
  303. CLOCK_EnableClock(kCLOCK_UsbHs);
  304. CLOCK_EnableClock(kCLOCK_UsbHsPhy);
  305. CLOCK_EnableUsbhsPhyPllClock(kCLOCK_Usbphy480M, 24000000U);
  306. CLOCK_EnableUsbhsClock();
  307. USB_EhciPhyInit(kUSB_ControllerEhci0, BOARD_XTAL0_CLK_HZ, &phyConfig);
  308. }
  309. void (*g_usb_nxp_irq)(uint8_t busid);
  310. void usb_dc_low_level_init(uint8_t busid)
  311. {
  312. USB_ClockInit();
  313. g_usb_nxp_irq = USBD_IRQHandler;
  314. /* Install isr, set priority, and enable IRQ. */
  315. NVIC_SetPriority((IRQn_Type)USB1_HS_IRQn, 3);
  316. EnableIRQ((IRQn_Type)USB1_HS_IRQn);
  317. }
  318. void usb_dc_low_level_deinit(uint8_t busid)
  319. {
  320. DisableIRQ((IRQn_Type)USB1_HS_IRQn);
  321. }
  322. static void usb_host_mode_init(CHIPIDEA_TypeDef *ptr)
  323. {
  324. /* Set mode to host, must be set immediately after reset */
  325. ptr->USBMODE &= ~USB_USBMODE_CM_MASK;
  326. ptr->USBMODE |= USB_USBMODE_CM_SET(3);
  327. /* Set the endian */
  328. ptr->USBMODE &= ~USB_USBMODE_ES_MASK;
  329. /* Set parallel interface signal */
  330. ptr->PORTSC1 &= ~USB_PORTSC1_STS_MASK;
  331. /* Set parallel transceiver width */
  332. ptr->PORTSC1 &= ~USB_PORTSC1_PTW_MASK;
  333. /* Not use interrupt threshold. */
  334. ptr->USBCMD &= ~USB_USBCMD_ITC_MASK;
  335. }
  336. void usb_hc_low_level_init(struct usbh_bus *bus)
  337. {
  338. USB_ClockInit();
  339. g_usb_nxp_irq = USBH_IRQHandler;
  340. /* Install isr, set priority, and enable IRQ. */
  341. NVIC_SetPriority((IRQn_Type)USB1_HS_IRQn, 3);
  342. EnableIRQ((IRQn_Type)USB1_HS_IRQn);
  343. }
  344. void usb_hc_low_level2_init(struct usbh_bus *bus)
  345. {
  346. usb_host_mode_init((CHIPIDEA_TypeDef *)(bus->hcd.reg_base));
  347. }
  348. void usb_hc_low_level_deinit(struct usbh_bus *bus)
  349. {
  350. DisableIRQ((IRQn_Type)USB1_HS_IRQn);
  351. }
  352. uint8_t usbh_get_port_speed(struct usbh_bus *bus, const uint8_t port)
  353. {
  354. (void)port;
  355. uint8_t speed;
  356. CHIPIDEA_TypeDef *ptr = (CHIPIDEA_TypeDef *)bus->hcd.reg_base;
  357. speed = USB_PORTSC1_PSPD_GET(ptr->PORTSC1);
  358. if (speed == 0x00) {
  359. return USB_SPEED_FULL;
  360. }
  361. if (speed == 0x01) {
  362. return USB_SPEED_LOW;
  363. }
  364. if (speed == 0x02) {
  365. USB_EhcihostPhyDisconnectDetectCmd(kUSB_ControllerEhci0, 1);
  366. return USB_SPEED_HIGH;
  367. }
  368. return 0;
  369. }
  370. void USB1_HS_IRQHandler(void)
  371. {
  372. g_usb_nxp_irq(0);
  373. }
  374. #ifdef CONFIG_USB_DCACHE_ENABLE
  375. void usb_dcache_clean(uintptr_t addr, size_t size)
  376. {
  377. DCACHE_CleanByRange(addr, size);
  378. }
  379. void usb_dcache_invalidate(uintptr_t addr, size_t size)
  380. {
  381. DCACHE_InvalidateByRange(addr, size);
  382. }
  383. void usb_dcache_flush(uintptr_t addr, size_t size)
  384. {
  385. DCACHE_CleanInvalidateByRange(addr, size);
  386. }
  387. #endif