Skip to content

Commit c10544e

Browse files
author
Josuah Demangeon
committed
switch to atomic_or for setting all events at once
Signed-off-by: Josuah Demangeon <[email protected]>
1 parent 6940ba4 commit c10544e

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

drivers/usb/uhc/uhc_dwc2.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,7 @@ static void uhc_dwc2_isr_chan_handler(const struct device *dev, struct uhc_dwc2_
796796
struct usb_dwc2_reg *const dwc2 = config->base;
797797
struct uhc_dwc2_data *priv = uhc_get_private(dev);
798798
const struct usb_dwc2_host_chan *chan_regs = UHC_DWC2_CHAN_REG(dwc2, chan->chan_idx);
799+
uint32_t chan_event = 0;
799800
uint32_t hcint;
800801

801802
/* Clear the interrupt bits by writing them back */
@@ -812,14 +813,14 @@ static void uhc_dwc2_isr_chan_handler(const struct device *dev, struct uhc_dwc2_
812813

813814
LOG_ERR("Channel %d error: 0x%08x", chan->chan_idx, hcint);
814815
/* TODO: Store the error in hal context */
815-
atomic_set_bit(&chan->event, DWC2_CHAN_EVENT_ERROR);
816+
chan_event |= BIT(DWC2_CHAN_EVENT_ERROR);
816817

817818
} else if (hcint & USB_DWC2_HCINT_CHHLTD) {
818819
if (chan->halt_requested) {
819820
chan->halt_requested = 0;
820-
atomic_set_bit(&chan->event, DWC2_CHAN_EVENT_HALT_REQ);
821+
chan_event |= BIT(DWC2_CHAN_EVENT_HALT_REQ);
821822
} else {
822-
atomic_set_bit(&chan->event, DWC2_CHAN_EVENT_CPLT);
823+
chan_event |= BIT(DWC2_CHAN_EVENT_CPLT);
823824
}
824825

825826
} else if (hcint & USB_DWC2_HCINT_XFERCOMPL) {
@@ -839,11 +840,14 @@ static void uhc_dwc2_isr_chan_handler(const struct device *dev, struct uhc_dwc2_
839840
__ASSERT(false, "Unknown channel interrupt, HCINT=%08Xh", hcint);
840841
}
841842

842-
if (atomic_test_bit(&chan->event, DWC2_CHAN_EVENT_CPLT) && !uhc_dwc2_buffer_is_done(chan)) {
843+
if ((chan_event & BIT(DWC2_CHAN_EVENT_CPLT)) && !uhc_dwc2_buffer_is_done(chan)) {
843844
/* No completion event until the buffer is complete software-side too */
844-
atomic_clear_bit(&chan->event, DWC2_CHAN_EVENT_CPLT);
845+
chan_event &= ~BIT(DWC2_CHAN_EVENT_CPLT);
845846
uhc_dwc2_buffer_exec_proceed(dev, chan);
846-
} else {
847+
}
848+
849+
if (chan_event != 0) {
850+
atomic_or(&chan->event, chan_event);
847851
k_event_set(&priv->event, BIT(UHC_DWC2_EVENT_CHAN0 + chan->chan_idx));
848852
}
849853
}
@@ -871,8 +875,8 @@ static void uhc_dwc2_isr_handler(const struct device *dev)
871875

872876
if (core_intrs & USB_DWC2_GINTSTS_DISCONNINT) {
873877
/* Disconnect event */
874-
k_event_set(&priv->event, BIT(UHC_DWC2_EVENT_DISCONNECTION));
875878
uhc_dwc2_debounce_enable(dev);
879+
k_event_set(&priv->event, BIT(UHC_DWC2_EVENT_DISCONNECTION));
876880
/* Port still connected, check port event */
877881
}
878882

@@ -906,8 +910,8 @@ static void uhc_dwc2_isr_handler(const struct device *dev)
906910
}
907911

908912
if (port_intrs & USB_DWC2_HPRT_PRTCONNDET && !priv->debouncing) {
909-
k_event_set(&priv->event, BIT(UHC_DWC2_EVENT_CONNECTION));
910913
uhc_dwc2_debounce_enable(dev);
914+
k_event_set(&priv->event, BIT(UHC_DWC2_EVENT_CONNECTION));
911915
}
912916

913917
(void)uhc_dwc2_quirk_irq_clear(dev);

0 commit comments

Comments
 (0)