@@ -40,32 +40,22 @@ 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 ,
53- /* The host port has encountered an overcurrent condition */
54- UHC_DWC2_CORE_EVENT_OVRCUR ,
46+ UHC_DWC2_EVENT_DISABLED ,
47+ /* Overcurrent detected. Port is now UHC_PORT_STATE_RECOVERY */
48+ UHC_DWC2_EVENT_OVERCURRENT ,
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_OVERCURRENT_CLEAR ,
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 ,
67- /* Overcurrent detected. Port is now UHC_PORT_STATE_RECOVERY */
68- UHC_PORT_EVENT_OVERCURRENT ,
56+ UHC_DWC2_EVENT_ERROR ,
57+ /* Event on a channel 0. Use +N for channel N */
58+ UHC_DWC2_EVENT_CHAN0 ,
6959};
7060
7161enum uhc_dwc2_speed {
@@ -649,21 +639,13 @@ static enum uhc_dwc2_event uhc_dwc2_decode_hprt(const struct device *dev,
649639 enum uhc_dwc2_event port_event = UHC_DWC2_EVENT_NONE ;
650640
651641 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 :
642+ case UHC_DWC2_EVENT_ENABLED :
661643 /* Initialize remaining host port registers */
662644 dwc2_port_enable (dev );
663- port_event = UHC_PORT_EVENT_ENABLED ;
645+ port_event = UHC_DWC2_EVENT_ENABLED ;
664646 priv -> conn_dev_ena = 1 ;
665647 break ;
666- case UHC_DWC2_CORE_EVENT_DISABLED :
648+ case UHC_DWC2_EVENT_DISABLED :
667649 priv -> conn_dev_ena = 0 ;
668650 /* Could be due to a disable request or reset request, or due to a port error */
669651 /* Ignore the disable event if it's due to a reset request */
@@ -681,24 +663,24 @@ static enum uhc_dwc2_event uhc_dwc2_decode_hprt(const struct device *dev,
681663 LOG_ERR ("Port disabled due to an error, changing state to "
682664 "recovery" );
683665 priv -> port_state = UHC_PORT_STATE_RECOVERY ;
684- port_event = UHC_PORT_EVENT_ERROR ;
666+ port_event = UHC_DWC2_EVENT_ERROR ;
685667 }
686668 }
687669 break ;
688- case UHC_DWC2_CORE_EVENT_OVRCUR :
689- case UHC_DWC2_CORE_EVENT_OVRCUR_CLR :
670+ case UHC_DWC2_EVENT_OVERCURRENT :
671+ case UHC_DWC2_EVENT_OVERCURRENT_CLEAR :
690672 /* TODO: Handle overcurrent event */
691673
692674 /* If port state powered, we need to power it off to protect it
693675 * change port state to recovery
694- * generate port event UHC_PORT_EVENT_OVERCURRENT
676+ * generate port event UHC_DWC2_EVENT_OVERCURRENT
695677 * disable the flag conn_dev_ena
696678 */
697679
698680 LOG_ERR ("Overcurrent detected on port, not implemented yet" );
699681 break ;
700682 default :
701- __ASSERT (false, "Unexpected core event %d" , core_event ) ;
683+ port_event = core_event ;
702684 break ;
703685 }
704686 return port_event ;
@@ -735,7 +717,7 @@ static inline enum uhc_dwc2_event uhc_dwc2_decode_intr(const struct device *dev)
735717 if ((core_intrs & CORE_EVENTS_INTRS_MSK ) || (port_intrs & PORT_EVENTS_INTRS_MSK )) {
736718 if (core_intrs & USB_DWC2_GINTSTS_DISCONNINT ) {
737719 /* Disconnect event */
738- core_event = UHC_DWC2_CORE_EVENT_DISCONN ;
720+ core_event = UHC_DWC2_EVENT_DISCONNECTION ;
739721 /* Debounce lock */
740722 uhc_dwc2_lock_enable (dev );
741723 } else {
@@ -744,20 +726,20 @@ static inline enum uhc_dwc2_event uhc_dwc2_decode_intr(const struct device *dev)
744726 /* Check if this is an overcurrent or an overcurrent cleared */
745727 if (port_intrs & USB_DWC2_HPRT_PRTOVRCURRACT ) {
746728 /* TODO: Verify handling logic during overcurrent */
747- core_event = UHC_DWC2_CORE_EVENT_OVRCUR ;
729+ core_event = UHC_DWC2_EVENT_OVERCURRENT ;
748730 } else {
749- core_event = UHC_DWC2_CORE_EVENT_OVRCUR_CLR ;
731+ core_event = UHC_DWC2_EVENT_OVERCURRENT_CLEAR ;
750732 }
751733 } else if (port_intrs & USB_DWC2_HPRT_PRTENCHNG ) {
752734 if (port_intrs & USB_DWC2_HPRT_PRTENA ) {
753735 /* Host port was enabled */
754- core_event = UHC_DWC2_CORE_EVENT_ENABLED ;
736+ core_event = UHC_DWC2_EVENT_ENABLED ;
755737 } else {
756738 /* Host port has been disabled */
757- core_event = UHC_DWC2_CORE_EVENT_DISABLED ;
739+ core_event = UHC_DWC2_EVENT_DISABLED ;
758740 }
759741 } else if (port_intrs & USB_DWC2_HPRT_PRTCONNDET && !priv -> lock_enabled ) {
760- core_event = UHC_DWC2_CORE_EVENT_CONN ;
742+ core_event = UHC_DWC2_EVENT_CONNECTION ;
761743 /* Debounce lock */
762744 uhc_dwc2_lock_enable (dev );
763745 } else {
@@ -767,11 +749,12 @@ static inline enum uhc_dwc2_event uhc_dwc2_decode_intr(const struct device *dev)
767749 }
768750 }
769751 }
752+
770753 /* Port events always take precedence over channel events */
771754 if (core_event == UHC_DWC2_EVENT_NONE && (core_intrs & USB_DWC2_GINTSTS_HCHINT )) {
772755 /* One or more channels have pending interrupts. Store the mask of those channels */
773756 priv -> pending_channel_intrs_msk = sys_read32 ((mem_addr_t )& dwc2 -> haint );
774- core_event = UHC_DWC2_CORE_EVENT_CHAN ;
757+ core_event = UHC_DWC2_EVENT_CHAN0 ;
775758 }
776759
777760 return core_event ;
@@ -1085,7 +1068,7 @@ static void uhc_dwc2_isr_handler(const struct device *dev)
10851068 key = irq_lock ();
10861069
10871070 core_event = uhc_dwc2_decode_intr (dev );
1088- if (core_event == UHC_DWC2_CORE_EVENT_CHAN ) {
1071+ if (core_event == UHC_DWC2_EVENT_CHAN0 ) {
10891072 /* Channel event. Cycle through each pending channel */
10901073 struct uhc_dwc2_chan * chan ;
10911074
@@ -1147,19 +1130,19 @@ static inline enum uhc_dwc2_event uhc_dwc2_get_port_event(const struct device *d
11471130 port_event = priv -> last_event ;
11481131
11491132 switch (port_event ) {
1150- case UHC_PORT_EVENT_CONNECTION :
1133+ case UHC_DWC2_EVENT_CONNECTION :
11511134 /* Don't update state immediately, we still need to debounce. */
11521135 if (uhc_dwc2_port_debounce (dev )) {
1153- port_event = UHC_PORT_EVENT_CONNECTION ;
1136+ port_event = UHC_DWC2_EVENT_CONNECTION ;
11541137 } else {
11551138 LOG_ERR ("Port is not connected after debounce" );
11561139 /* TODO: Simulate and/or verify */
11571140 LOG_WRN ("Port debounce error handling is not implemented yet" );
11581141 }
11591142 break ;
1160- case UHC_PORT_EVENT_DISCONNECTION :
1161- case UHC_PORT_EVENT_ERROR :
1162- case UHC_PORT_EVENT_OVERCURRENT :
1143+ case UHC_DWC2_EVENT_DISCONNECTION :
1144+ case UHC_DWC2_EVENT_ERROR :
1145+ case UHC_DWC2_EVENT_OVERCURRENT :
11631146 break ;
11641147 default :
11651148 break ;
@@ -1453,11 +1436,11 @@ static inline void uhc_dwc2_handle_port_events(const struct device *dev)
14531436 /* No event, nothing to do */
14541437 break ;
14551438
1456- case UHC_PORT_EVENT_CONNECTION :
1439+ case UHC_DWC2_EVENT_CONNECTION :
14571440 uhc_dwc2_port_reset (dev );
14581441 break ;
14591442
1460- case UHC_PORT_EVENT_ENABLED :
1443+ case UHC_DWC2_EVENT_ENABLED :
14611444 /* TODO: enter critical section */
14621445 priv -> port_state = UHC_PORT_STATE_ENABLED ;
14631446 /* TODO: exit critical section */
@@ -1479,9 +1462,9 @@ static inline void uhc_dwc2_handle_port_events(const struct device *dev)
14791462 uhc_dwc2_submit_new_device (dev , port_speed );
14801463 break ;
14811464
1482- case UHC_PORT_EVENT_DISCONNECTION :
1483- case UHC_PORT_EVENT_ERROR :
1484- case UHC_PORT_EVENT_OVERCURRENT :
1465+ case UHC_DWC2_EVENT_DISCONNECTION :
1466+ case UHC_DWC2_EVENT_ERROR :
1467+ case UHC_DWC2_EVENT_OVERCURRENT :
14851468 port_has_device = false;
14861469
14871470 /* TODO: enter critical section */
0 commit comments