Skip to content

Commit cee68df

Browse files
committed
f
1 parent 846abca commit cee68df

File tree

1 file changed

+51
-64
lines changed

1 file changed

+51
-64
lines changed

drivers/usb/uhc/uhc_dwc2.c

Lines changed: 51 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -858,13 +858,13 @@ static inline int uhc_dwc2_config_phy(const struct device *dev)
858858
gusbcfg &= ~(USB_DWC2_GUSBCFG_ULPIFSLS | USB_DWC2_GUSBCFG_ULPICLK_SUSM);
859859
} else {
860860
LOG_WRN("Highspeed UTMI+ PHY init");
861-
// Select UTMI+ PHY (internal)
861+
/* Select UTMI+ PHY (internal) */
862862
gusbcfg &= ~USB_DWC2_GUSBCFG_ULPI_UTMI_SEL_ULPI;
863-
// Set 16-bit interface if supported
863+
/* Set 16-bit interface if supported */
864864
if (priv->const_cfg.phydatawidth) {
865-
gusbcfg |= USB_DWC2_GUSBCFG_PHYIF_16_BIT; // 16 bit
865+
gusbcfg |= USB_DWC2_GUSBCFG_PHYIF_16_BIT;
866866
} else {
867-
gusbcfg &= ~USB_DWC2_GUSBCFG_PHYIF_16_BIT; // 8 bit
867+
gusbcfg &= ~USB_DWC2_GUSBCFG_PHYIF_16_BIT;
868868
}
869869
}
870870
sys_write32(gusbcfg, (mem_addr_t)&dwc2->gusbcfg);
@@ -1303,12 +1303,14 @@ static void IRAM_ATTR _buffer_fill(pipe_t *pipe)
13031303
/* TODO: sync CACHE */
13041304
}
13051305

1306-
static inline ctrl_stage_t cal_next_pid(ctrl_stage_t pid, uint8_t pkt_count) {
1307-
if (pkt_count & 0x01) {
1308-
return pid ^ 0x02; // toggle DATA0 and DATA1
1309-
} else {
1310-
return pid;
1311-
}
1306+
static inline ctrl_stage_t cal_next_pid(ctrl_stage_t pid, uint8_t pkt_count)
1307+
{
1308+
if (pkt_count & 0x01) {
1309+
/* Toggle DATA0 and DATA1 */
1310+
return pid ^ 0x02;
1311+
} else {
1312+
return pid;
1313+
}
13121314
}
13131315

13141316
static void IRAM_ATTR _buffer_exec_proceed(pipe_t *pipe)
@@ -1361,7 +1363,7 @@ static void IRAM_ATTR _buffer_exec_proceed(pipe_t *pipe)
13611363
net_buf_add(xfer->buf, size);
13621364
}
13631365
}
1364-
} else { /* cur_stg == 1. // Just finished data stage. Go to status stage */
1366+
} else { /* cur_stg == 1. Just finished data stage. Go to status stage */
13651367
/* Status stage is always the opposite direction of data stage */
13661368
next_dir_is_in = !buffer_exec->flags.ctrl.data_stg_in;
13671369
next_pid = CTRL_STAGE_DATA1; /* Status stage always has a PID of DATA1 */
@@ -1472,9 +1474,7 @@ static pipe_event_t uhc_dwc2_decode_chan(pipe_t* pipe, uhc_dwc2_channel_t *chan_
14721474
break;
14731475
}
14741476
default:
1475-
__ASSERT(false,
1476-
"uhc_dwc2_decode_chan: Unknown channel event: %s",
1477-
dwc2_chan_event_str[chan_event]);
1477+
__ASSERT(false, "uhc_dwc2_decode_chan: Unknown channel event");
14781478
break;
14791479
}
14801480

@@ -1730,14 +1730,8 @@ static inline int uhc_dwc2_port_recovery(const struct device *dev)
17301730
int ret;
17311731

17321732
/* TODO: Implement port checks */
1733-
/*
1734-
* Hint:
1735-
* struct uhc_dwc2_data_s *priv = uhc_get_private(dev);
1736-
* priv->dynamic.state == UHC_PORT_STATE_RECOVERY;
1737-
* priv->num_channels_idle == 0;
1738-
* priv->num_channels_queued == 0
1739-
* priv->dynamic.flags.val == 0
1740-
*/
1733+
/* Port should be in recovery state and no ongoing transfers */
1734+
/* Port flags should be 0 */
17411735

17421736
/* TODO: enter critical section */
17431737
ret = uhc_dwc2_quirk_irq_disable_func(dev);
@@ -1827,11 +1821,10 @@ static void uhc_dwc2_pipe_set_ep_char(const uhc_pipe_config_t *pipe_config,
18271821
uhc_dwc2_ep_char_t *ep_char)
18281822
{
18291823
uhc_dwc2_xfer_type_t dw2_ll_xfer_type;
1830-
switch (type) {
1831-
case USB_TRANSFER_TYPE_CTRL:
1824+
1825+
if (type == USB_TRANSFER_TYPE_CTRL) {
18321826
dw2_ll_xfer_type = UHC_DWC2_XFER_TYPE_CTRL;
1833-
break;
1834-
default:
1827+
} else {
18351828
LOG_ERR("Unsupported transfer type %d", type);
18361829
return;
18371830
}
@@ -2203,41 +2196,35 @@ static inline void uhc_dwc2_handle_pipe_events(const struct device *dev)
22032196

22042197
LOG_DBG("Pipe event: %s", uhc_pipe_event_str[pipe->last_event]);
22052198

2206-
switch (pipe->last_event) {
2207-
case PIPE_EVENT_XFER_DONE: {
2208-
/* XFER transfer is done, process the transfer and release the pipe buffer */
2209-
struct uhc_transfer *const xfer = (struct uhc_transfer *)pipe->buffer->xfer;
2199+
if (pipe->last_event == PIPE_EVENT_XFER_DONE) {
2200+
/* XFER transfer is done, process the transfer and release the pipe buffer */
2201+
struct uhc_transfer *const xfer = (struct uhc_transfer *)pipe->buffer->xfer;
22102202

2211-
if (xfer->buf != NULL && xfer->buf->len) {
2212-
LOG_HEXDUMP_WRN(xfer->buf->data, xfer->buf->len, "data");
2213-
}
2203+
if (xfer->buf != NULL && xfer->buf->len) {
2204+
LOG_HEXDUMP_WRN(xfer->buf->data, xfer->buf->len, "data");
2205+
}
22142206

2215-
/* TODO: Refactor the address setting logic. */
2216-
/* To configure the channel, we need to get the dev addr from higher logic */
2217-
if (pipe->buffer->flags.ctrl.set_addr) {
2218-
pipe->buffer->flags.ctrl.set_addr = 0;
2219-
pipe->ep_char.dev_addr = pipe->buffer->flags.ctrl.new_addr;
2220-
/* Set the new device address in the channel */
2221-
sys_set_bits((mem_addr_t)&pipe->chan_obj->regs->hcchar,
2222-
(pipe->ep_char.dev_addr << USB_DWC2_HCCHAR0_DEVADDR_POS));
2223-
k_msleep(SET_ADDR_DELAY_MS);
2224-
}
2207+
/* TODO: Refactor the address setting logic. */
2208+
/* To configure the channel, we need to get the dev addr from higher logic */
2209+
if (pipe->buffer->flags.ctrl.set_addr) {
2210+
pipe->buffer->flags.ctrl.set_addr = 0;
2211+
pipe->ep_char.dev_addr = pipe->buffer->flags.ctrl.new_addr;
2212+
/* Set the new device address in the channel */
2213+
sys_set_bits((mem_addr_t)&pipe->chan_obj->regs->hcchar,
2214+
(pipe->ep_char.dev_addr << USB_DWC2_HCCHAR0_DEVADDR_POS));
2215+
k_msleep(SET_ADDR_DELAY_MS);
2216+
}
22252217

2226-
/* TODO: Refactor pipe resources release */
2227-
pipe->flags.has_xfer = 0;
2228-
priv->num_pipes_idle++;
2229-
priv->num_pipes_queued--;
2218+
/* TODO: Refactor pipe resources release */
2219+
pipe->flags.has_xfer = 0;
2220+
priv->num_pipes_idle++;
2221+
priv->num_pipes_queued--;
22302222

2231-
uhc_xfer_return(dev, xfer, 0);
2232-
break;
2233-
}
2234-
case PIPE_EVENT_ERROR:
2235-
case PIPE_EVENT_HALTED:
2236-
case PIPE_EVENT_NONE:
2237-
default: {
2238-
LOG_ERR("Unhandled pipe event %s", uhc_pipe_event_str[pipe->last_event]);
2239-
break;
2240-
}
2223+
uhc_xfer_return(dev, xfer, 0);
2224+
2225+
} else {
2226+
/* TODO: Handle the rest pipe events */
2227+
LOG_ERR("Unhandled pipe event %s", uhc_pipe_event_str[pipe->last_event]);
22412228
}
22422229
}
22432230

@@ -2283,15 +2270,15 @@ static inline int uhc_dwc2_submit_ctrl_xfer(const struct device *dev,
22832270

22842271
/* TODO: Check that XFER has not already been enqueued? */
22852272

2286-
/* TODO: dma addr must be aligned 4 bytes */
2287-
/*
2288-
* Hint: if (((uintptr_t)xfer->setup_pkt % 4)) { ... }
2289-
*/
2273+
/* TODO: setup packet must be aligned 4 bytes? */
2274+
if (((uintptr_t)xfer->setup_pkt % 4)) {
2275+
LOG_WRN("Setup packet address %p is not 4-byte aligned", xfer->setup_pkt);
2276+
}
22902277

22912278
/* TODO: Buffer addr that will used as dma addr also should be aligned */
2292-
/*
2293-
* Hint: if(((uintptr_t)net_buf_tail(xfer->buf) % 4)) { ... }
2294-
*/
2279+
if((xfer->buf != NULL) && ((uintptr_t)net_buf_tail(xfer->buf) % 4)) {
2280+
LOG_WRN("XFER buffer address %08lXh is not 4-byte aligned", (uintptr_t)net_buf_tail(xfer->buf));
2281+
}
22952282

22962283
sys_dlist_append(&pipe->xfer_pending_list, &xfer->node);
22972284
pipe->num_xfer_pending++;

0 commit comments

Comments
 (0)