Skip to content

Commit 4db2bda

Browse files
committed
echi: fix NXP USBPHY disconnection detection
Signed-off-by: HiFiPhile <[email protected]>
1 parent 3b4884f commit 4db2bda

File tree

1 file changed

+52
-8
lines changed

1 file changed

+52
-8
lines changed

src/portable/ehci/ehci.c

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@
3838
#include "ehci_api.h"
3939
#include "ehci.h"
4040

41+
// NXP specific fixes
42+
#if TU_CHECK_MCU(OPT_MCU_MIMXRT1XXX, OPT_MCU_LPC55, OPT_MCU_MCXN9)
43+
#include "fsl_device_registers.h"
44+
#endif
45+
4146
//--------------------------------------------------------------------+
4247
// MACRO CONSTANT TYPEDEF
4348
//--------------------------------------------------------------------+
@@ -179,6 +184,36 @@ static void ehci_enable_schedule(ehci_registers_t* regs, bool is_period) {
179184
}
180185
}
181186

187+
#if ((defined FSL_FEATURE_SOC_USBPHY_COUNT) && (FSL_FEATURE_SOC_USBPHY_COUNT > 0U))
188+
static void nxp_usbphy_disconn_detector_set(uint8_t port, bool enable) {
189+
// unify naming convention
190+
#if !defined(USBPHY1) && defined(USBPHY)
191+
#define USBPHY1 USBPHY
192+
#endif
193+
194+
if (port == 0) {
195+
if (enable) {
196+
USBPHY1->CTRL_SET = USBPHY_CTRL_ENHOSTDISCONDETECT_MASK;
197+
} else {
198+
USBPHY1->CTRL_CLR = USBPHY_CTRL_ENHOSTDISCONDETECT_MASK;
199+
}
200+
}
201+
#if FSL_FEATURE_SOC_USBPHY_COUNT > 1U
202+
else if (port == 1) {
203+
if (enable) {
204+
USBPHY2->CTRL_SET = USBPHY_CTRL_ENHOSTDISCONDETECT_MASK;
205+
} else {
206+
USBPHY2->CTRL_CLR = USBPHY_CTRL_ENHOSTDISCONDETECT_MASK;
207+
}
208+
}
209+
#endif
210+
211+
#if !defined(USBPHY1) && defined(USBPHY)
212+
#undef USBPHY1
213+
#endif
214+
}
215+
#endif
216+
182217
//--------------------------------------------------------------------+
183218
// HCD API
184219
//--------------------------------------------------------------------+
@@ -213,16 +248,21 @@ void hcd_port_reset_end(uint8_t rhport) {
213248
(void) rhport;
214249
ehci_registers_t* regs = ehci_data.regs;
215250

216-
// skip if reset is already complete
217-
if (!regs->portsc_bm.port_reset) {
218-
return;
219-
}
251+
// stop reset only if is not complete yet
252+
if (regs->portsc_bm.port_reset) {
253+
// mask out all change bits since they are Write 1 to clear
254+
uint32_t portsc = regs->portsc & ~EHCI_PORTSC_MASK_W1C;
255+
portsc &= ~EHCI_PORTSC_MASK_PORT_RESET;
220256

221-
// mask out all change bits since they are Write 1 to clear
222-
uint32_t portsc = regs->portsc & ~EHCI_PORTSC_MASK_W1C;
223-
portsc &= ~EHCI_PORTSC_MASK_PORT_RESET;
257+
regs->portsc = portsc;
258+
}
224259

225-
regs->portsc = portsc;
260+
#if ((defined FSL_FEATURE_SOC_USBPHY_COUNT) && (FSL_FEATURE_SOC_USBPHY_COUNT > 0U))
261+
// Enable disconnect detector for highspeed device only
262+
if (hcd_port_speed_get(rhport) == TUSB_SPEED_HIGH) {
263+
nxp_usbphy_disconn_detector_set(rhport, true);
264+
}
265+
#endif
226266
}
227267

228268
bool hcd_port_connect_status(uint8_t rhport) {
@@ -579,6 +619,10 @@ void port_connect_status_change_isr(uint8_t rhport) {
579619
hcd_event_device_attach(rhport, true);
580620
} else // device unplugged
581621
{
622+
#if ((defined FSL_FEATURE_SOC_USBPHY_COUNT) && (FSL_FEATURE_SOC_USBPHY_COUNT > 0U))
623+
// Disable disconnect detector
624+
nxp_usbphy_disconn_detector_set(rhport, false);
625+
#endif
582626
hcd_event_device_remove(rhport, true);
583627
}
584628
}

0 commit comments

Comments
 (0)