Skip to content

Commit d11e766

Browse files
committed
drivers: usb: uhc: update usb host driver
1. Add interval for usb xfer. 2. Set right mps for during pipe init. 3. Set right direction for non-zero endpoint. 4. Check transferBuffer during init transfer. Signed-off-by: Aiden Hu <[email protected]>
1 parent cf883f6 commit d11e766

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

drivers/usb/uhc/uhc_common.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ 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+
uint8_t interval;
104105

105106
api->lock(dev);
106107

@@ -125,6 +126,7 @@ struct uhc_transfer *uhc_xfer_alloc(const struct device *dev,
125126
}
126127

127128
mps = ep_desc->wMaxPacketSize;
129+
interval = ep_desc->bInterval;
128130
}
129131

130132
LOG_DBG("Allocate xfer, ep 0x%02x mps %u cb %p", ep, mps, cb);
@@ -137,6 +139,7 @@ struct uhc_transfer *uhc_xfer_alloc(const struct device *dev,
137139
memset(xfer, 0, sizeof(struct uhc_transfer));
138140
xfer->ep = ep;
139141
xfer->mps = mps;
142+
xfer->interval = interval;
140143
xfer->udev = udev;
141144
xfer->cb = cb;
142145
xfer->priv = cb_priv;

drivers/usb/uhc/uhc_mcux_common.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,20 +280,21 @@ usb_host_pipe_t *uhc_mcux_init_hal_ep(const struct device *dev, struct uhc_trans
280280
/* USB_HostHelperGetPeripheralInformation uses this value as first parameter */
281281
pipe_init.devInstance = xfer->udev;
282282
pipe_init.nakCount = USB_HOST_CONFIG_MAX_NAK;
283-
pipe_init.maxPacketSize = xfer->mps;
283+
pipe_init.maxPacketSize = USB_MPS_EP_SIZE(xfer->mps);
284284
pipe_init.endpointAddress = USB_EP_GET_IDX(xfer->ep);
285285
pipe_init.direction = USB_EP_GET_IDX(xfer->ep) == 0 ? USB_OUT :
286286
USB_EP_GET_DIR(xfer->ep) ? USB_IN : USB_OUT;
287287
/* Current Zephyr Host stack is experimental, the endpoint's interval,
288288
* 'number per uframe' and the endpoint type cannot be got yet.
289289
*/
290290
pipe_init.numberPerUframe = 0; /* TODO: need right way to implement it. */
291+
pipe_init.numberPerUframe = USB_MPS_ADDITIONAL_TRANSACTIONS(xfer->mps);
291292
pipe_init.interval = xfer->interval;
292293
/* TODO: need right way to implement it. */
293294
if (pipe_init.endpointAddress == 0) {
294295
pipe_init.pipeType = USB_ENDPOINT_CONTROL;
295296
} else {
296-
pipe_init.pipeType = USB_ENDPOINT_BULK;
297+
pipe_init.pipeType = USB_ENDPOINT_ISOCHRONOUS;
297298
}
298299

299300
status = priv->mcux_if->controllerOpenPipe(priv->mcux_host.controllerHandle,
@@ -353,6 +354,10 @@ int uhc_mcux_hal_init_transfer_common(const struct device *dev, usb_host_transfe
353354
? USB_IN
354355
: USB_OUT;
355356
}
357+
else
358+
{
359+
mcux_xfer->direction = USB_EP_DIR_IS_IN(xfer->ep) ? USB_IN : USB_OUT;
360+
}
356361

357362
return 0;
358363
}

drivers/usb/uhc/uhc_mcux_ehci.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,10 @@ static usb_host_transfer_t *uhc_mcux_hal_init_transfer(const struct device *dev,
202202
memcpy(mcux_xfer->setupPacket, xfer->setup_pkt, 8u);
203203
if (xfer->buf != NULL) {
204204
mcux_xfer->transferBuffer = uhc_mcux_nocache_alloc(mcux_xfer->transferLength);
205+
if (mcux_xfer->transferBuffer == NULL)
206+
{
207+
LOG_ERR("Failed to allocate non-cached transfer buffer");
208+
}
205209
}
206210
#endif
207211

0 commit comments

Comments
 (0)