Skip to content

Commit cc5a2a9

Browse files
author
Josuah Demangeon
committed
flatten/simplify completion event logic
Signed-off-by: Josuah Demangeon <[email protected]>
1 parent c10544e commit cc5a2a9

File tree

1 file changed

+7
-26
lines changed

1 file changed

+7
-26
lines changed

drivers/usb/uhc/uhc_dwc2.c

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -819,8 +819,10 @@ static void uhc_dwc2_isr_chan_handler(const struct device *dev, struct uhc_dwc2_
819819
if (chan->halt_requested) {
820820
chan->halt_requested = 0;
821821
chan_event |= BIT(DWC2_CHAN_EVENT_HALT_REQ);
822-
} else {
822+
} else if (uhc_dwc2_buffer_is_done(chan)) {
823823
chan_event |= BIT(DWC2_CHAN_EVENT_CPLT);
824+
} else {
825+
uhc_dwc2_buffer_exec_proceed(dev, chan);
824826
}
825827

826828
} else if (hcint & USB_DWC2_HCINT_XFERCOMPL) {
@@ -840,12 +842,6 @@ static void uhc_dwc2_isr_chan_handler(const struct device *dev, struct uhc_dwc2_
840842
__ASSERT(false, "Unknown channel interrupt, HCINT=%08Xh", hcint);
841843
}
842844

843-
if ((chan_event & BIT(DWC2_CHAN_EVENT_CPLT)) && !uhc_dwc2_buffer_is_done(chan)) {
844-
/* No completion event until the buffer is complete software-side too */
845-
chan_event &= ~BIT(DWC2_CHAN_EVENT_CPLT);
846-
uhc_dwc2_buffer_exec_proceed(dev, chan);
847-
}
848-
849845
if (chan_event != 0) {
850846
atomic_or(&chan->event, chan_event);
851847
k_event_set(&priv->event, BIT(UHC_DWC2_EVENT_CHAN0 + chan->chan_idx));
@@ -873,11 +869,15 @@ static void uhc_dwc2_isr_handler(const struct device *dev)
873869
sys_write32(port_intrs & ~USB_DWC2_HPRT_PRTENA, (mem_addr_t)&dwc2->hprt);
874870
}
875871

872+
/* Disconnection takes precedense over connection */
876873
if (core_intrs & USB_DWC2_GINTSTS_DISCONNINT) {
877874
/* Disconnect event */
878875
uhc_dwc2_debounce_enable(dev);
879876
k_event_set(&priv->event, BIT(UHC_DWC2_EVENT_DISCONNECTION));
880877
/* Port still connected, check port event */
878+
} else if (port_intrs & USB_DWC2_HPRT_PRTCONNDET && !priv->debouncing) {
879+
uhc_dwc2_debounce_enable(dev);
880+
k_event_set(&priv->event, BIT(UHC_DWC2_EVENT_CONNECTION));
881881
}
882882

883883
if (core_intrs & USB_DWC2_GINTSTS_HCHINT) {
@@ -886,7 +886,6 @@ static void uhc_dwc2_isr_handler(const struct device *dev)
886886
for (uint8_t i; (i = __builtin_ffs(channels)) != 0; channels &= !BIT(i - 1)) {
887887
uhc_dwc2_isr_chan_handler(dev, &priv->chan[i - 1]);
888888
}
889-
LOG_DBG("Handling channel event");
890889
}
891890

892891
if (port_intrs & USB_DWC2_HPRT_PRTOVRCURRCHNG) {
@@ -909,11 +908,6 @@ static void uhc_dwc2_isr_handler(const struct device *dev)
909908
}
910909
}
911910

912-
if (port_intrs & USB_DWC2_HPRT_PRTCONNDET && !priv->debouncing) {
913-
uhc_dwc2_debounce_enable(dev);
914-
k_event_set(&priv->event, BIT(UHC_DWC2_EVENT_CONNECTION));
915-
}
916-
917911
(void)uhc_dwc2_quirk_irq_clear(dev);
918912
}
919913

@@ -1171,19 +1165,6 @@ static inline void uhc_dwc2_handle_port_events(const struct device *dev, uint32_
11711165

11721166
LOG_DBG("Port events: 0x08%x", events);
11731167

1174-
/* Note:
1175-
* Regressing events (e.g. enable -> disabled, connected -> disconnected) always
1176-
* take precedence.
1177-
*/
1178-
if ((events & BIT(UHC_DWC2_EVENT_ENABLED)) &&
1179-
(events & BIT(UHC_DWC2_EVENT_DISABLED))) {
1180-
events &= ~BIT(UHC_DWC2_EVENT_ENABLED);
1181-
}
1182-
if ((events & BIT(UHC_DWC2_EVENT_CONNECTION)) &&
1183-
(events & BIT(UHC_DWC2_EVENT_DISCONNECTION))) {
1184-
events &= ~BIT(UHC_DWC2_EVENT_CONNECTION);
1185-
}
1186-
11871168
if (events & BIT(UHC_DWC2_EVENT_ENABLED)) {
11881169
/* Initialize remaining host port registers */
11891170
dwc2_port_enable(dev);

0 commit comments

Comments
 (0)