|
38 | 38 | #include "ehci_api.h" |
39 | 39 | #include "ehci.h" |
40 | 40 |
|
| 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 | + |
41 | 46 | //--------------------------------------------------------------------+ |
42 | 47 | // MACRO CONSTANT TYPEDEF |
43 | 48 | //--------------------------------------------------------------------+ |
@@ -179,6 +184,36 @@ static void ehci_enable_schedule(ehci_registers_t* regs, bool is_period) { |
179 | 184 | } |
180 | 185 | } |
181 | 186 |
|
| 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 | + |
182 | 217 | //--------------------------------------------------------------------+ |
183 | 218 | // HCD API |
184 | 219 | //--------------------------------------------------------------------+ |
@@ -213,16 +248,21 @@ void hcd_port_reset_end(uint8_t rhport) { |
213 | 248 | (void) rhport; |
214 | 249 | ehci_registers_t* regs = ehci_data.regs; |
215 | 250 |
|
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; |
220 | 256 |
|
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 | + } |
224 | 259 |
|
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 |
226 | 266 | } |
227 | 267 |
|
228 | 268 | bool hcd_port_connect_status(uint8_t rhport) { |
@@ -579,6 +619,10 @@ void port_connect_status_change_isr(uint8_t rhport) { |
579 | 619 | hcd_event_device_attach(rhport, true); |
580 | 620 | } else // device unplugged |
581 | 621 | { |
| 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 |
582 | 626 | hcd_event_device_remove(rhport, true); |
583 | 627 | } |
584 | 628 | } |
|
0 commit comments