Skip to content

Commit 8983077

Browse files
author
Josuah Demangeon
committed
clean-up the channel event generation
Signed-off-by: Josuah Demangeon <[email protected]>
1 parent 2929b74 commit 8983077

File tree

1 file changed

+16
-26
lines changed

1 file changed

+16
-26
lines changed

drivers/usb/uhc/uhc_dwc2.c

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ LOG_MODULE_REGISTER(uhc_dwc2, CONFIG_UHC_DRIVER_LOG_LEVEL);
3636
#define UHC_DWC2_MAX_CHAN 16
3737

3838
enum uhc_dwc2_event {
39-
/* No event occurred, or could not decode interrupt */
40-
UHC_DWC2_EVENT_NONE,
4139
/* Root port event */
4240
UHC_DWC2_EVENT_PORT,
4341
/* The host port has been enabled (i.e., connected device has been reset. Send SOFs) */
@@ -58,6 +56,15 @@ enum uhc_dwc2_event {
5856
UHC_DWC2_EVENT_CHAN0,
5957
};
6058

59+
enum uhc_dwc2_chan_event {
60+
/* The channel has completed execution of a transfer. Channel is now halted */
61+
DWC2_CHAN_EVENT_CPLT,
62+
/* The channel has encountered an error. Channel is now halted */
63+
DWC2_CHAN_EVENT_ERROR,
64+
/* A halt has been requested on the channel */
65+
DWC2_CHAN_EVENT_HALT_REQ,
66+
};
67+
6168
enum uhc_dwc2_speed {
6269
UHC_DWC2_SPEED_HIGH = 0,
6370
UHC_DWC2_SPEED_FULL = 1,
@@ -91,17 +98,6 @@ enum uhc_port_state {
9198
UHC_PORT_STATE_RECOVERY,
9299
};
93100

94-
enum uhc_dwc2_chan_event {
95-
/* The channel has completed execution of a transfer. Channel is now halted */
96-
DWC2_CHAN_EVENT_CPLT,
97-
/* The channel has encountered an error. Channel is now halted */
98-
DWC2_CHAN_EVENT_ERROR,
99-
/* A halt has been requested on the channel */
100-
DWC2_CHAN_EVENT_HALT_REQ,
101-
/* No event (interrupt ran for internal processing) */
102-
DWC2_CHAN_EVENT_NONE,
103-
};
104-
105101
enum uhc_dwc2_ctrl_stage {
106102
CTRL_STAGE_DATA0 = 0,
107103
CTRL_STAGE_DATA2 = 1,
@@ -819,7 +815,6 @@ static void uhc_dwc2_isr_chan_handler(const struct device *dev, struct uhc_dwc2_
819815
struct usb_dwc2_reg *const dwc2 = config->base;
820816
struct uhc_dwc2_data *priv = uhc_get_private(dev);
821817
const struct usb_dwc2_host_chan *chan_regs = UHC_DWC2_CHAN_REG(dwc2, chan->chan_idx);
822-
enum uhc_dwc2_chan_event chan_event;
823818
uint32_t hcint;
824819

825820
/* Clear the interrupt bits by writing them back */
@@ -836,13 +831,13 @@ static void uhc_dwc2_isr_chan_handler(const struct device *dev, struct uhc_dwc2_
836831

837832
LOG_ERR("Channel %d error: 0x%08x", chan->chan_idx, hcint);
838833
/* TODO: Store the error in hal context */
839-
chan_event = DWC2_CHAN_EVENT_ERROR;
834+
atomic_set_bit(&chan->event, DWC2_CHAN_EVENT_ERROR);
840835
} else if (hcint & USB_DWC2_HCINT_CHHLTD) {
841836
if (chan->halt_requested) {
842837
chan->halt_requested = 0;
843-
chan_event = DWC2_CHAN_EVENT_HALT_REQ;
838+
atomic_set_bit(&chan->event, DWC2_CHAN_EVENT_HALT_REQ);
844839
} else {
845-
chan_event = DWC2_CHAN_EVENT_CPLT;
840+
atomic_set_bit(&chan->event, DWC2_CHAN_EVENT_CPLT);
846841
}
847842
} else if (hcint & USB_DWC2_HCINT_XFERCOMPL) {
848843
/* Note:
@@ -854,19 +849,18 @@ static void uhc_dwc2_isr_chan_handler(const struct device *dev, struct uhc_dwc2_
854849

855850
/*
856851
* After setting the halt bit, this will generate another channel halted interrupt.
857-
* We treat this interrupt as a NONE event, then cycle back with the channel halted
852+
* We treat this interrupt as no event, then cycle back with the channel halted
858853
* interrupt to handle the CPLT event.
859854
*/
860-
chan_event = DWC2_CHAN_EVENT_NONE;
861855
} else {
862856
__ASSERT(false, "Unknown channel interrupt, HCINT=%08Xh", hcint);
863-
chan_event = DWC2_CHAN_EVENT_NONE;
864857
}
865858

866-
if (chan_event == DWC2_CHAN_EVENT_CPLT && !uhc_dwc2_buffer_is_done(chan)) {
859+
if (atomic_test_bit(&chan->event, DWC2_CHAN_EVENT_CPLT) && !uhc_dwc2_buffer_is_done(chan)) {
860+
/* No completion event until the buffer is complete software-side too */
861+
atomic_clear_bit(&chan->event, DWC2_CHAN_EVENT_CPLT);
867862
uhc_dwc2_buffer_exec_proceed(dev, chan);
868863
} else {
869-
atomic_set_bit(&chan->event, chan_event);
870864
k_event_set(&priv->event, BIT(UHC_DWC2_EVENT_CHAN0 + chan->chan_idx));
871865
}
872866
}
@@ -1251,10 +1245,6 @@ static inline void uhc_dwc2_handle_port_events(const struct device *dev, uint32_
12511245
}
12521246
}
12531247

1254-
if (events & BIT(UHC_DWC2_EVENT_NONE)) {
1255-
/* No event, nothing to do */
1256-
}
1257-
12581248
if ((events & BIT(UHC_DWC2_EVENT_OVERCURRENT)) ||
12591249
(events & BIT(UHC_DWC2_EVENT_OVERCURRENT_CLEAR))) {
12601250
/* If port state powered, we need to power it off to protect it

0 commit comments

Comments
 (0)