Skip to content

Commit 0b8a358

Browse files
committed
drivers: uhc: use correct endpoint type and interval
For usb xfer, set endpoint type and interval by the selected endpoint desc. Signed-off-by: Aiden Hu <[email protected]>
1 parent 61a8648 commit 0b8a358

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

drivers/usb/uhc/uhc_common.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ struct uhc_transfer *uhc_xfer_alloc(const struct device *dev,
101101
const struct uhc_api *api = dev->api;
102102
struct uhc_transfer *xfer = NULL;
103103
uint16_t mps;
104+
uint16_t interval;
105+
uint8_t type;
104106

105107
api->lock(dev);
106108

@@ -109,6 +111,8 @@ struct uhc_transfer *uhc_xfer_alloc(const struct device *dev,
109111
}
110112

111113
if (ep_idx == 0) {
114+
interval = 0;
115+
type = USB_EP_TYPE_CONTROL;
112116
mps = udev->dev_desc.bMaxPacketSize0;
113117
} else {
114118
struct usb_ep_descriptor *ep_desc;
@@ -125,6 +129,8 @@ struct uhc_transfer *uhc_xfer_alloc(const struct device *dev,
125129
}
126130

127131
mps = ep_desc->wMaxPacketSize;
132+
interval = ep_desc->bInterval;
133+
type = ep_desc->bmAttributes & USB_EP_TRANSFER_TYPE_MASK;
128134
}
129135

130136
LOG_DBG("Allocate xfer, ep 0x%02x mps %u cb %p", ep, mps, cb);
@@ -137,6 +143,8 @@ struct uhc_transfer *uhc_xfer_alloc(const struct device *dev,
137143
memset(xfer, 0, sizeof(struct uhc_transfer));
138144
xfer->ep = ep;
139145
xfer->mps = mps;
146+
xfer->interval = interval;
147+
xfer->type = type;
140148
xfer->udev = udev;
141149
xfer->cb = cb;
142150
xfer->priv = cb_priv;

drivers/usb/uhc/uhc_mcux_common.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -237,14 +237,14 @@ static usb_host_pipe_handle uhc_mcux_check_hal_ep(const struct device *dev,
237237
if (priv->mcux_eps[i] != NULL &&
238238
priv->mcux_eps[i]->endpointAddress == USB_EP_GET_IDX(xfer->ep) &&
239239
priv->mcux_eps[i]->direction == direction &&
240+
priv->mcux_eps[i]->pipeType == xfer->type &&
240241
priv->mcux_eps[i]->deviceHandle == xfer->udev) {
241242
mcux_ep = priv->mcux_eps[i];
242243
break;
243244
}
244245
}
245246

246-
/* TODO: need to check endpoint type too */
247-
if (mcux_ep != NULL &&
247+
if (mcux_ep != NULL && mcux_ep->pipeType == xfer->type &&
248248
(mcux_ep->maxPacketSize != xfer->mps ||
249249
mcux_ep->interval != xfer->interval)) {
250250
/* re-initialize the ep */
@@ -289,12 +289,7 @@ usb_host_pipe_t *uhc_mcux_init_hal_ep(const struct device *dev, struct uhc_trans
289289
*/
290290
pipe_init.numberPerUframe = 0; /* TODO: need right way to implement it. */
291291
pipe_init.interval = xfer->interval;
292-
/* TODO: need right way to implement it. */
293-
if (pipe_init.endpointAddress == 0) {
294-
pipe_init.pipeType = USB_ENDPOINT_CONTROL;
295-
} else {
296-
pipe_init.pipeType = USB_ENDPOINT_BULK;
297-
}
292+
pipe_init.pipeType = xfer->type;
298293

299294
status = priv->mcux_if->controllerOpenPipe(priv->mcux_host.controllerHandle,
300295
(usb_host_pipe_handle *)&mcux_ep, &pipe_init);

include/zephyr/drivers/usb/uhc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ struct uhc_transfer {
120120
struct net_buf *buf;
121121
/** Endpoint to which request is associated */
122122
uint8_t ep;
123+
/** Endpoint type */
124+
uint8_t type;
123125
/** Maximum packet size */
124126
uint16_t mps;
125127
/** Interval, used for periodic transfers only */

0 commit comments

Comments
 (0)