Skip to content

Commit 1059c13

Browse files
author
Josuah Demangeon
committed
merge core and port events together
Signed-off-by: Josuah Demangeon <[email protected]>
1 parent 666fe7e commit 1059c13

File tree

1 file changed

+42
-50
lines changed

1 file changed

+42
-50
lines changed

drivers/usb/uhc/uhc_dwc2.c

Lines changed: 42 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,36 @@ 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,
3941
/* Root port event */
4042
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,
49+
/* The host port has been enabled (i.e., connected device has been reset. Send SOFs) */
50+
UHC_DWC2_CORE_EVENT_ENABLED,
51+
/* 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,
55+
/* The host port has been cleared of the overcurrent condition */
56+
UHC_DWC2_CORE_EVENT_OVRCUR_CLR,
4157
/* Root chan event */
4258
UHC_DWC2_EVENT_CHAN0,
59+
/* 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,
63+
/* A device disconnection has been detected */
64+
UHC_PORT_EVENT_DISCONNECTION,
65+
/* 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,
4369
};
4470

4571
enum uhc_dwc2_speed {
@@ -55,21 +81,6 @@ enum uhc_dwc2_xfer_type {
5581
UHC_DWC2_XFER_TYPE_INTR = 3,
5682
};
5783

58-
enum uhc_port_event {
59-
/* No event has occurred or the event is no longer valid */
60-
UHC_PORT_EVENT_NONE,
61-
/* A device has been connected to the port */
62-
UHC_PORT_EVENT_CONNECTION,
63-
/* Device has completed reset and enabled on the port */
64-
UHC_PORT_EVENT_ENABLED,
65-
/* A device disconnection has been detected */
66-
UHC_PORT_EVENT_DISCONNECTION,
67-
/* Port error detected. Port is now UHC_PORT_STATE_RECOVERY */
68-
UHC_PORT_EVENT_ERROR,
69-
/* Overcurrent detected. Port is now UHC_PORT_STATE_RECOVERY */
70-
UHC_PORT_EVENT_OVERCURRENT,
71-
};
72-
7384
enum uhc_port_state {
7485
/* The port is not powered */
7586
UHC_PORT_STATE_NOT_POWERED,
@@ -90,25 +101,6 @@ enum uhc_port_state {
90101
UHC_PORT_STATE_RECOVERY,
91102
};
92103

93-
enum uhc_dwc2_core_event {
94-
/* No event occurred, or could not decode interrupt */
95-
UHC_DWC2_CORE_EVENT_NONE,
96-
/* A channel event has occurred. Call the channel event handler instead */
97-
UHC_DWC2_CORE_EVENT_CHAN,
98-
/* The host port has detected a connection */
99-
UHC_DWC2_CORE_EVENT_CONN,
100-
/* The host port has detected a disconnection */
101-
UHC_DWC2_CORE_EVENT_DISCONN,
102-
/* The host port has been enabled (i.e., connected device has been reset. Send SOFs) */
103-
UHC_DWC2_CORE_EVENT_ENABLED,
104-
/* The host port has been disabled (no more SOFs) */
105-
UHC_DWC2_CORE_EVENT_DISABLED,
106-
/* The host port has encountered an overcurrent condition */
107-
UHC_DWC2_CORE_EVENT_OVRCUR,
108-
/* The host port has been cleared of the overcurrent condition */
109-
UHC_DWC2_CORE_EVENT_OVRCUR_CLR,
110-
};
111-
112104
enum uhc_dwc2_chan_event {
113105
/* The channel has completed execution of a transfer. Channel is now halted */
114106
DWC2_CHAN_EVENT_CPLT,
@@ -177,7 +169,7 @@ struct uhc_dwc2_data {
177169
/* Bit mask of channels with pending interrupts */
178170
uint32_t pending_channel_intrs_msk;
179171
/* Data, that is used in multiple threads */
180-
enum uhc_port_event last_event;
172+
enum uhc_dwc2_event last_event;
181173
enum uhc_port_state port_state;
182174
/* FIFO */
183175
uint16_t fifo_top;
@@ -650,11 +642,11 @@ static inline void uhc_dwc2_init_gahbcfg(const struct device *dev)
650642
sys_set_bits((mem_addr_t)&dwc2->gahbcfg, USB_DWC2_GAHBCFG_GLBINTRMASK);
651643
}
652644

653-
static enum uhc_port_event uhc_dwc2_decode_hprt(const struct device *dev,
654-
enum uhc_dwc2_core_event core_event)
645+
static enum uhc_dwc2_event uhc_dwc2_decode_hprt(const struct device *dev,
646+
enum uhc_dwc2_event core_event)
655647
{
656648
struct uhc_dwc2_data *priv = uhc_get_private(dev);
657-
enum uhc_port_event port_event = UHC_PORT_EVENT_NONE;
649+
enum uhc_dwc2_event port_event = UHC_DWC2_EVENT_NONE;
658650

659651
switch (core_event) {
660652
case UHC_DWC2_CORE_EVENT_CONN:
@@ -712,12 +704,12 @@ static enum uhc_port_event uhc_dwc2_decode_hprt(const struct device *dev,
712704
return port_event;
713705
}
714706

715-
static inline enum uhc_dwc2_core_event uhc_dwc2_decode_intr(const struct device *dev)
707+
static inline enum uhc_dwc2_event uhc_dwc2_decode_intr(const struct device *dev)
716708
{
717709
const struct uhc_dwc2_config *const config = dev->config;
718710
struct uhc_dwc2_data *priv = uhc_get_private(dev);
719711
struct usb_dwc2_reg *const dwc2 = config->base;
720-
enum uhc_dwc2_core_event core_event = UHC_DWC2_CORE_EVENT_NONE;
712+
enum uhc_dwc2_event core_event = UHC_DWC2_EVENT_NONE;
721713
uint32_t core_intrs;
722714
uint32_t port_intrs = 0;
723715

@@ -776,7 +768,7 @@ static inline enum uhc_dwc2_core_event uhc_dwc2_decode_intr(const struct device
776768
}
777769
}
778770
/* Port events always take precedence over channel events */
779-
if (core_event == UHC_DWC2_CORE_EVENT_NONE && (core_intrs & USB_DWC2_GINTSTS_HCHINT)) {
771+
if (core_event == UHC_DWC2_EVENT_NONE && (core_intrs & USB_DWC2_GINTSTS_HCHINT)) {
780772
/* One or more channels have pending interrupts. Store the mask of those channels */
781773
priv->pending_channel_intrs_msk = sys_read32((mem_addr_t)&dwc2->haint);
782774
core_event = UHC_DWC2_CORE_EVENT_CHAN;
@@ -1088,7 +1080,7 @@ static void uhc_dwc2_isr_handler(const struct device *dev)
10881080
{
10891081
struct uhc_dwc2_data *priv = uhc_get_private(dev);
10901082
unsigned int key;
1091-
enum uhc_dwc2_core_event core_event;
1083+
enum uhc_dwc2_event core_event;
10921084

10931085
key = irq_lock();
10941086

@@ -1103,12 +1095,12 @@ static void uhc_dwc2_isr_handler(const struct device *dev)
11031095
chan = uhc_dwc2_get_chan_pending_intr(dev);
11041096
}
11051097
} else {
1106-
if (core_event != UHC_DWC2_CORE_EVENT_NONE) {
1098+
if (core_event != UHC_DWC2_EVENT_NONE) {
11071099
/* Port event */
1108-
enum uhc_port_event port_event;
1100+
enum uhc_dwc2_event port_event;
11091101

11101102
port_event = uhc_dwc2_decode_hprt(dev, core_event);
1111-
if (port_event != UHC_PORT_EVENT_NONE) {
1103+
if (port_event != UHC_DWC2_EVENT_NONE) {
11121104
priv->last_event = port_event;
11131105
k_event_set(&priv->event, BIT(UHC_DWC2_EVENT_PORT));
11141106
}
@@ -1147,10 +1139,10 @@ static inline bool uhc_dwc2_port_debounce(const struct device *dev)
11471139
return is_connected;
11481140
}
11491141

1150-
static inline enum uhc_port_event uhc_dwc2_get_port_event(const struct device *dev)
1142+
static inline enum uhc_dwc2_event uhc_dwc2_get_port_event(const struct device *dev)
11511143
{
11521144
struct uhc_dwc2_data *priv = uhc_get_private(dev);
1153-
enum uhc_port_event port_event = UHC_PORT_EVENT_NONE;
1145+
enum uhc_dwc2_event port_event = UHC_DWC2_EVENT_NONE;
11541146

11551147
port_event = priv->last_event;
11561148

@@ -1449,15 +1441,15 @@ static void uhc_dwc2_chan_deinit(const struct device *dev, struct uhc_dwc2_chan
14491441
static inline void uhc_dwc2_handle_port_events(const struct device *dev)
14501442
{
14511443
struct uhc_dwc2_data *priv = uhc_get_private(dev);
1452-
enum uhc_port_event port_event = uhc_dwc2_get_port_event(dev);
1444+
enum uhc_dwc2_event port_event = uhc_dwc2_get_port_event(dev);
14531445
enum uhc_dwc2_speed port_speed;
14541446
bool port_has_device;
14551447
int ret;
14561448

14571449
LOG_DBG("Port event: %d", port_event);
14581450

14591451
switch (port_event) {
1460-
case UHC_PORT_EVENT_NONE:
1452+
case UHC_DWC2_EVENT_NONE:
14611453
/* No event, nothing to do */
14621454
break;
14631455

@@ -1799,7 +1791,7 @@ static int uhc_dwc2_init(const struct device *dev)
17991791

18001792
/* Update the port state and flags */
18011793
priv->port_state = UHC_PORT_STATE_NOT_POWERED;
1802-
priv->last_event = UHC_PORT_EVENT_NONE;
1794+
priv->last_event = UHC_DWC2_EVENT_NONE;
18031795

18041796
/* TODO: Clear all the flags and channels */
18051797
priv->pending_channel_intrs_msk = 0;

0 commit comments

Comments
 (0)