@@ -40,32 +40,24 @@ enum uhc_dwc2_event {
4040 UHC_DWC2_EVENT_NONE ,
4141 /* Root port event */
4242 UHC_DWC2_EVENT_PORT ,
43- /* A channel event has occurred. Call the channel event handler instead */
44- UHC_DWC2_CORE_EVENT_CHAN ,
45- /* The host port has detected a connection */
46- UHC_DWC2_CORE_EVENT_CONN ,
47- /* The host port has detected a disconnection */
48- UHC_DWC2_CORE_EVENT_DISCONN ,
4943 /* The host port has been enabled (i.e., connected device has been reset. Send SOFs) */
50- UHC_DWC2_CORE_EVENT_ENABLED ,
44+ UHC_DWC2_EVENT_ENABLED ,
5145 /* The host port has been disabled (no more SOFs) */
52- UHC_DWC2_CORE_EVENT_DISABLED ,
46+ UHC_DWC2_EVENT_DISABLED ,
5347 /* The host port has encountered an overcurrent condition */
54- UHC_DWC2_CORE_EVENT_OVRCUR ,
48+ UHC_DWC2_EVENT_OVRCUR ,
5549 /* The host port has been cleared of the overcurrent condition */
56- UHC_DWC2_CORE_EVENT_OVRCUR_CLR ,
57- /* Root chan event */
58- UHC_DWC2_EVENT_CHAN0 ,
50+ UHC_DWC2_EVENT_OVRCUR_CLR ,
5951 /* A device has been connected to the port */
60- UHC_PORT_EVENT_CONNECTION ,
61- /* Device has completed reset and enabled on the port */
62- UHC_PORT_EVENT_ENABLED ,
52+ UHC_DWC2_EVENT_CONNECTION ,
6353 /* A device disconnection has been detected */
64- UHC_PORT_EVENT_DISCONNECTION ,
54+ UHC_DWC2_EVENT_DISCONNECTION ,
6555 /* Port error detected. Port is now UHC_PORT_STATE_RECOVERY */
66- UHC_PORT_EVENT_ERROR ,
56+ UHC_DWC2_EVENT_ERROR ,
6757 /* Overcurrent detected. Port is now UHC_PORT_STATE_RECOVERY */
68- UHC_PORT_EVENT_OVERCURRENT ,
58+ UHC_DWC2_EVENT_OVERCURRENT ,
59+ /* Event on a channel 0. Use +N for channel N */
60+ UHC_DWC2_EVENT_CHAN0 ,
6961};
7062
7163enum uhc_dwc2_speed {
@@ -649,21 +641,13 @@ static enum uhc_dwc2_event uhc_dwc2_decode_hprt(const struct device *dev,
649641 enum uhc_dwc2_event port_event = UHC_DWC2_EVENT_NONE ;
650642
651643 switch (core_event ) {
652- case UHC_DWC2_CORE_EVENT_CONN :
653- port_event = UHC_PORT_EVENT_CONNECTION ;
654- break ;
655- case UHC_DWC2_CORE_EVENT_DISCONN :
656- /* TODO: priv->port_state = UHC_PORT_STATE_RECOVERY */
657- port_event = UHC_PORT_EVENT_DISCONNECTION ;
658- priv -> conn_dev_ena = 0 ;
659- break ;
660- case UHC_DWC2_CORE_EVENT_ENABLED :
644+ case UHC_DWC2_EVENT_ENABLED :
661645 /* Initialize remaining host port registers */
662646 dwc2_port_enable (dev );
663- port_event = UHC_PORT_EVENT_ENABLED ;
647+ port_event = UHC_DWC2_EVENT_ENABLED ;
664648 priv -> conn_dev_ena = 1 ;
665649 break ;
666- case UHC_DWC2_CORE_EVENT_DISABLED :
650+ case UHC_DWC2_EVENT_DISABLED :
667651 priv -> conn_dev_ena = 0 ;
668652 /* Could be due to a disable request or reset request, or due to a port error */
669653 /* Ignore the disable event if it's due to a reset request */
@@ -681,24 +665,24 @@ static enum uhc_dwc2_event uhc_dwc2_decode_hprt(const struct device *dev,
681665 LOG_ERR ("Port disabled due to an error, changing state to "
682666 "recovery" );
683667 priv -> port_state = UHC_PORT_STATE_RECOVERY ;
684- port_event = UHC_PORT_EVENT_ERROR ;
668+ port_event = UHC_DWC2_EVENT_ERROR ;
685669 }
686670 }
687671 break ;
688- case UHC_DWC2_CORE_EVENT_OVRCUR :
689- case UHC_DWC2_CORE_EVENT_OVRCUR_CLR :
672+ case UHC_DWC2_EVENT_OVRCUR :
673+ case UHC_DWC2_EVENT_OVRCUR_CLR :
690674 /* TODO: Handle overcurrent event */
691675
692676 /* If port state powered, we need to power it off to protect it
693677 * change port state to recovery
694- * generate port event UHC_PORT_EVENT_OVERCURRENT
678+ * generate port event UHC_DWC2_EVENT_OVERCURRENT
695679 * disable the flag conn_dev_ena
696680 */
697681
698682 LOG_ERR ("Overcurrent detected on port, not implemented yet" );
699683 break ;
700684 default :
701- __ASSERT (false, "Unexpected core event %d" , core_event ) ;
685+ port_event = core_event ;
702686 break ;
703687 }
704688 return port_event ;
@@ -735,7 +719,7 @@ static inline enum uhc_dwc2_event uhc_dwc2_decode_intr(const struct device *dev)
735719 if ((core_intrs & CORE_EVENTS_INTRS_MSK ) || (port_intrs & PORT_EVENTS_INTRS_MSK )) {
736720 if (core_intrs & USB_DWC2_GINTSTS_DISCONNINT ) {
737721 /* Disconnect event */
738- core_event = UHC_DWC2_CORE_EVENT_DISCONN ;
722+ core_event = UHC_DWC2_EVENT_DISCONNECTION ;
739723 /* Debounce lock */
740724 uhc_dwc2_lock_enable (dev );
741725 } else {
@@ -744,20 +728,20 @@ static inline enum uhc_dwc2_event uhc_dwc2_decode_intr(const struct device *dev)
744728 /* Check if this is an overcurrent or an overcurrent cleared */
745729 if (port_intrs & USB_DWC2_HPRT_PRTOVRCURRACT ) {
746730 /* TODO: Verify handling logic during overcurrent */
747- core_event = UHC_DWC2_CORE_EVENT_OVRCUR ;
731+ core_event = UHC_DWC2_EVENT_OVRCUR ;
748732 } else {
749- core_event = UHC_DWC2_CORE_EVENT_OVRCUR_CLR ;
733+ core_event = UHC_DWC2_EVENT_OVRCUR_CLR ;
750734 }
751735 } else if (port_intrs & USB_DWC2_HPRT_PRTENCHNG ) {
752736 if (port_intrs & USB_DWC2_HPRT_PRTENA ) {
753737 /* Host port was enabled */
754- core_event = UHC_DWC2_CORE_EVENT_ENABLED ;
738+ core_event = UHC_DWC2_EVENT_ENABLED ;
755739 } else {
756740 /* Host port has been disabled */
757- core_event = UHC_DWC2_CORE_EVENT_DISABLED ;
741+ core_event = UHC_DWC2_EVENT_DISABLED ;
758742 }
759743 } else if (port_intrs & USB_DWC2_HPRT_PRTCONNDET && !priv -> lock_enabled ) {
760- core_event = UHC_DWC2_CORE_EVENT_CONN ;
744+ core_event = UHC_DWC2_EVENT_CONNECTION ;
761745 /* Debounce lock */
762746 uhc_dwc2_lock_enable (dev );
763747 } else {
@@ -771,7 +755,7 @@ static inline enum uhc_dwc2_event uhc_dwc2_decode_intr(const struct device *dev)
771755 if (core_event == UHC_DWC2_EVENT_NONE && (core_intrs & USB_DWC2_GINTSTS_HCHINT )) {
772756 /* One or more channels have pending interrupts. Store the mask of those channels */
773757 priv -> pending_channel_intrs_msk = sys_read32 ((mem_addr_t )& dwc2 -> haint );
774- core_event = UHC_DWC2_CORE_EVENT_CHAN ;
758+ core_event = UHC_DWC2_EVENT_CHAN0 ;
775759 }
776760
777761 return core_event ;
@@ -1085,7 +1069,7 @@ static void uhc_dwc2_isr_handler(const struct device *dev)
10851069 key = irq_lock ();
10861070
10871071 core_event = uhc_dwc2_decode_intr (dev );
1088- if (core_event == UHC_DWC2_CORE_EVENT_CHAN ) {
1072+ if (core_event == UHC_DWC2_EVENT_CHAN0 ) {
10891073 /* Channel event. Cycle through each pending channel */
10901074 struct uhc_dwc2_chan * chan ;
10911075
@@ -1147,19 +1131,19 @@ static inline enum uhc_dwc2_event uhc_dwc2_get_port_event(const struct device *d
11471131 port_event = priv -> last_event ;
11481132
11491133 switch (port_event ) {
1150- case UHC_PORT_EVENT_CONNECTION :
1134+ case UHC_DWC2_EVENT_CONNECTION :
11511135 /* Don't update state immediately, we still need to debounce. */
11521136 if (uhc_dwc2_port_debounce (dev )) {
1153- port_event = UHC_PORT_EVENT_CONNECTION ;
1137+ port_event = UHC_DWC2_EVENT_CONNECTION ;
11541138 } else {
11551139 LOG_ERR ("Port is not connected after debounce" );
11561140 /* TODO: Simulate and/or verify */
11571141 LOG_WRN ("Port debounce error handling is not implemented yet" );
11581142 }
11591143 break ;
1160- case UHC_PORT_EVENT_DISCONNECTION :
1161- case UHC_PORT_EVENT_ERROR :
1162- case UHC_PORT_EVENT_OVERCURRENT :
1144+ case UHC_DWC2_EVENT_DISCONNECTION :
1145+ case UHC_DWC2_EVENT_ERROR :
1146+ case UHC_DWC2_EVENT_OVERCURRENT :
11631147 break ;
11641148 default :
11651149 break ;
@@ -1453,11 +1437,11 @@ static inline void uhc_dwc2_handle_port_events(const struct device *dev)
14531437 /* No event, nothing to do */
14541438 break ;
14551439
1456- case UHC_PORT_EVENT_CONNECTION :
1440+ case UHC_DWC2_EVENT_CONNECTION :
14571441 uhc_dwc2_port_reset (dev );
14581442 break ;
14591443
1460- case UHC_PORT_EVENT_ENABLED :
1444+ case UHC_DWC2_EVENT_ENABLED :
14611445 /* TODO: enter critical section */
14621446 priv -> port_state = UHC_PORT_STATE_ENABLED ;
14631447 /* TODO: exit critical section */
@@ -1479,9 +1463,9 @@ static inline void uhc_dwc2_handle_port_events(const struct device *dev)
14791463 uhc_dwc2_submit_new_device (dev , port_speed );
14801464 break ;
14811465
1482- case UHC_PORT_EVENT_DISCONNECTION :
1483- case UHC_PORT_EVENT_ERROR :
1484- case UHC_PORT_EVENT_OVERCURRENT :
1466+ case UHC_DWC2_EVENT_DISCONNECTION :
1467+ case UHC_DWC2_EVENT_ERROR :
1468+ case UHC_DWC2_EVENT_OVERCURRENT :
14851469 port_has_device = false;
14861470
14871471 /* TODO: enter critical section */
0 commit comments