Skip to content

Commit 7b122b0

Browse files
author
Josuah Demangeon
committed
simplify channel interrupt handling
1 parent f74360f commit 7b122b0

File tree

1 file changed

+7
-33
lines changed

1 file changed

+7
-33
lines changed

drivers/usb/uhc/uhc_dwc2.c

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,6 @@ struct uhc_dwc2_chan {
145145
unsigned int interval;
146146
/* Offset in the periodic scheduler */
147147
uint32_t offset;
148-
/* The chan event type */
149-
enum uhc_dwc2_chan_event chan_event;
150148
/* Type of endpoint */
151149
enum uhc_dwc2_xfer_type type;
152150
/* Pipe status/state/events related */
@@ -170,10 +168,6 @@ struct uhc_dwc2_chan {
170168
uint8_t data_stg_in: 1;
171169
/* Has no data stage */
172170
uint8_t data_stg_skip: 1;
173-
/* This DMA buffer is currently being executed */
174-
uint8_t executing: 1;
175-
/* THis DMA buffer was canceled before completion */
176-
uint8_t was_canceled: 1;
177171
/* High-speed flag */
178172
uint8_t is_hs: 1;
179173
/* Support for Low-Speed is via a Full-Speed HUB */
@@ -875,6 +869,7 @@ enum uhc_dwc2_chan_event uhc_dwc2_hal_chan_decode_intr(const struct device *dev,
875869
__ASSERT(false, "Unknown channel interrupt, HCINT=%08Xh", hcint);
876870
chan_event = DWC2_CHAN_EVENT_NONE;
877871
}
872+
878873
return chan_event;
879874
}
880875

@@ -1058,14 +1053,6 @@ static void IRAM_ATTR _buffer_exec_proceed(const struct device *dev, struct uhc_
10581053
sys_write32(hcchar, (mem_addr_t)&chan_regs->hcchar);
10591054
}
10601055

1061-
static inline void _buffer_done(const struct device *dev, struct uhc_dwc2_chan *chan,
1062-
enum uhc_dwc2_chan_event chan_event, bool canceled)
1063-
{
1064-
chan->executing = 0;
1065-
chan->was_canceled = canceled;
1066-
chan->chan_event = chan_event;
1067-
}
1068-
10691056
static inline bool _buffer_can_fill(struct uhc_dwc2_chan *chan)
10701057
{
10711058
/* TODO: Double buffering scheme? */
@@ -1084,11 +1071,10 @@ static inline bool _buffer_can_exec(struct uhc_dwc2_chan *chan)
10841071
* Decode a channel interrupt and take appropriate action.
10851072
* Interrupt context.
10861073
*/
1087-
static enum uhc_dwc2_chan_event uhc_dwc2_decode_chan(const struct device *dev,
1088-
struct uhc_dwc2_chan *chan)
1074+
static void uhc_dwc2_handle_chan_intr(const struct device *dev, struct uhc_dwc2_chan *chan)
10891075
{
1076+
struct uhc_dwc2_data *priv = uhc_get_private(dev);
10901077
enum uhc_dwc2_chan_event chan_event = uhc_dwc2_hal_chan_decode_intr(dev, chan);
1091-
enum uhc_dwc2_chan_event ret = DWC2_CHAN_EVENT_NONE;
10921078

10931079
LOG_DBG("Channel event: %d", chan_event);
10941080

@@ -1101,9 +1087,9 @@ static enum uhc_dwc2_chan_event uhc_dwc2_decode_chan(const struct device *dev,
11011087
_buffer_exec_proceed(dev, chan);
11021088
break;
11031089
}
1104-
chan->last_event = DWC2_CHAN_EVENT_CPLT;
1105-
ret = chan->last_event;
1106-
_buffer_done(dev, chan, chan->last_event, false);
1090+
chan->last_event = chan_event;
1091+
chan->event_pending = 1;
1092+
k_event_post(&priv->drv_evt, BIT(UHC_DWC2_EVENT_CHAN));
11071093
break;
11081094
case DWC2_CHAN_EVENT_ERROR:
11091095
LOG_ERR("Channel error handling not implemented yet");
@@ -1132,8 +1118,6 @@ static enum uhc_dwc2_chan_event uhc_dwc2_decode_chan(const struct device *dev,
11321118
LOG_WRN("Unknown channel event %d", chan_event);
11331119
break;
11341120
}
1135-
1136-
return ret;
11371121
}
11381122

11391123
static IRAM_ATTR void _buffer_exec(const struct device *dev, struct uhc_dwc2_chan *chan)
@@ -1181,8 +1165,6 @@ static IRAM_ATTR void _buffer_exec(const struct device *dev, struct uhc_dwc2_cha
11811165
hcchar |= USB_DWC2_HCCHAR0_CHENA;
11821166
hcchar &= ~USB_DWC2_HCCHAR0_CHDIS;
11831167
sys_write32(hcchar, (mem_addr_t)&chan_regs->hcchar);
1184-
1185-
chan->executing = 1;
11861168
}
11871169

11881170
static void uhc_dwc2_isr_handler(const struct device *dev)
@@ -1200,15 +1182,7 @@ static void uhc_dwc2_isr_handler(const struct device *dev)
12001182

12011183
chan = uhc_dwc2_get_chan_pending_intr(dev);
12021184
while (chan != NULL) {
1203-
enum uhc_dwc2_chan_event chan_event = uhc_dwc2_decode_chan(dev, chan);
1204-
if (chan_event != DWC2_CHAN_EVENT_NONE) {
1205-
chan->last_event = chan_event;
1206-
chan->event_pending = 1;
1207-
k_event_post(&priv->drv_evt, BIT(UHC_DWC2_EVENT_CHAN));
1208-
}
1209-
/* Check for more channels with pending interrupts. Returns NULL if there
1210-
* are no more
1211-
*/
1185+
uhc_dwc2_handle_chan_intr(dev, chan);
12121186
chan = uhc_dwc2_get_chan_pending_intr(dev);
12131187
}
12141188
} else {

0 commit comments

Comments
 (0)