|
|
@@ -1,79 +1,27 @@
|
|
|
/*
|
|
|
- * Copyright (c) 2022, sakumisu
|
|
|
+ * Copyright (c) 2025, sakumisu
|
|
|
*
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
*/
|
|
|
#include "usbh_core.h"
|
|
|
#include "usbh_hub.h"
|
|
|
-#include "usb_xxx_reg.h"
|
|
|
|
|
|
-struct dwc2_pipe {
|
|
|
- bool inuse;
|
|
|
- uint32_t xfrd;
|
|
|
- volatile bool waiter;
|
|
|
- usb_osal_sem_t waitsem;
|
|
|
- struct usbh_hubport *hport;
|
|
|
- struct usbh_urb *urb;
|
|
|
-};
|
|
|
-
|
|
|
-struct dwc2_hcd {
|
|
|
- struct dwc2_pipe pipe_pool[CONFIG_USBHOST_PIPE_NUM];
|
|
|
-} g_dwc2_hcd;
|
|
|
-
|
|
|
-static int dwc2_chan_alloc(void)
|
|
|
-{
|
|
|
- int chidx;
|
|
|
-
|
|
|
- for (chidx = 0; chidx < CONFIG_USBHOST_PIPE_NUM; chidx++) {
|
|
|
- if (!g_dwc2_hcd.pipe_pool[chidx].inuse) {
|
|
|
- g_dwc2_hcd.pipe_pool[chidx].inuse = true;
|
|
|
- return chidx;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return -1;
|
|
|
-}
|
|
|
-
|
|
|
-static void dwc2_chan_free(struct dwc2_pipe *pipe)
|
|
|
-{
|
|
|
- pipe->inuse = false;
|
|
|
-}
|
|
|
-
|
|
|
-static int usbh_reset_port(const uint8_t port)
|
|
|
+int usb_hc_init(struct usbh_bus *bus)
|
|
|
{
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-static uint8_t usbh_get_port_speed(const uint8_t port)
|
|
|
-{
|
|
|
- return USB_SPEED_UNKNOWN;
|
|
|
-}
|
|
|
-
|
|
|
-__WEAK void usb_hc_low_level_init(void)
|
|
|
+int usb_hc_deinit(struct usbh_bus *bus)
|
|
|
{
|
|
|
-}
|
|
|
-
|
|
|
-int usb_hc_init(void)
|
|
|
-{
|
|
|
- int ret;
|
|
|
-
|
|
|
- memset(&g_dwc2_hcd, 0, sizeof(struct dwc2_hcd));
|
|
|
-
|
|
|
- for (uint8_t chidx = 0; chidx < CONFIG_USBHOST_PIPE_NUM; chidx++) {
|
|
|
- g_dwc2_hcd.pipe_pool[chidx].waitsem = usb_osal_sem_create(0);
|
|
|
- }
|
|
|
-
|
|
|
- usb_hc_low_level_init();
|
|
|
-
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-uint16_t usbh_get_frame_number(void)
|
|
|
+uint16_t usbh_get_frame_number(struct usbh_bus *bus)
|
|
|
{
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-int usbh_roothub_control(struct usb_setup_packet *setup, uint8_t *buf)
|
|
|
+int usbh_roothub_control(struct usbh_bus *bus, struct usb_setup_packet *setup, uint8_t *buf)
|
|
|
{
|
|
|
uint8_t nports;
|
|
|
uint8_t port;
|
|
|
@@ -150,7 +98,6 @@ int usbh_roothub_control(struct usb_setup_packet *setup, uint8_t *buf)
|
|
|
case HUB_PORT_FEATURE_POWER:
|
|
|
break;
|
|
|
case HUB_PORT_FEATURE_RESET:
|
|
|
- usbh_reset_port(port);
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
@@ -173,123 +120,12 @@ int usbh_roothub_control(struct usb_setup_packet *setup, uint8_t *buf)
|
|
|
|
|
|
int usbh_submit_urb(struct usbh_urb *urb)
|
|
|
{
|
|
|
- struct dwc2_chan *chan;
|
|
|
- size_t flags;
|
|
|
- int ret = 0;
|
|
|
- int chidx;
|
|
|
-
|
|
|
- if (!urb || !urb->hport || !urb->ep) {
|
|
|
- return -USB_ERR_INVAL;
|
|
|
- }
|
|
|
-
|
|
|
- if (!urb->hport->connected) {
|
|
|
- return -USB_ERR_NOTCONN;
|
|
|
- }
|
|
|
-
|
|
|
- if (urb->errorcode == -USB_ERR_BUSY) {
|
|
|
- return -USB_ERR_BUSY;
|
|
|
- }
|
|
|
-
|
|
|
- flags = usb_osal_enter_critical_section();
|
|
|
-
|
|
|
- chidx = dwc2_chan_alloc();
|
|
|
- if (chidx == -1) {
|
|
|
- usb_osal_leave_critical_section(flags);
|
|
|
- return -USB_ERR_NOMEM;
|
|
|
- }
|
|
|
-
|
|
|
- chan = &g_dwc2_hcd.chan_pool[chidx];
|
|
|
- chan->chidx = chidx;
|
|
|
- chan->urb = urb;
|
|
|
-
|
|
|
- urb->hcpriv = chan;
|
|
|
- urb->errorcode = -USB_ERR_BUSY;
|
|
|
- urb->actual_length = 0;
|
|
|
-
|
|
|
- usb_osal_leave_critical_section(flags);
|
|
|
-
|
|
|
- switch (USB_GET_ENDPOINT_TYPE(urb->ep->bmAttributes)) {
|
|
|
- case USB_ENDPOINT_TYPE_CONTROL:
|
|
|
- break;
|
|
|
- case USB_ENDPOINT_TYPE_BULK:
|
|
|
- break;
|
|
|
- case USB_ENDPOINT_TYPE_INTERRUPT:
|
|
|
- break;
|
|
|
- case USB_ENDPOINT_TYPE_ISOCHRONOUS:
|
|
|
- break;
|
|
|
- default:
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- if (urb->timeout > 0) {
|
|
|
- /* wait until timeout or sem give */
|
|
|
- ret = usb_osal_sem_take(chan->waitsem, urb->timeout);
|
|
|
- if (ret < 0) {
|
|
|
- goto errout_timeout;
|
|
|
- }
|
|
|
- urb->timeout = 0;
|
|
|
- ret = urb->errorcode;
|
|
|
- /* we can free chan when waitsem is done */
|
|
|
- dwc2_chan_free(chan);
|
|
|
- }
|
|
|
- return ret;
|
|
|
-errout_timeout:
|
|
|
- urb->timeout = 0;
|
|
|
- usbh_kill_urb(urb);
|
|
|
- return ret;
|
|
|
+ return -USB_ERR_NOTSUPP;
|
|
|
}
|
|
|
|
|
|
int usbh_kill_urb(struct usbh_urb *urb)
|
|
|
{
|
|
|
- struct dwc2_chan *chan;
|
|
|
- size_t flags;
|
|
|
-
|
|
|
- if (!urb || !urb->hcpriv) {
|
|
|
- return -USB_ERR_INVAL;
|
|
|
- }
|
|
|
-
|
|
|
- flags = usb_osal_enter_critical_section();
|
|
|
-
|
|
|
- chan = (struct dwc2_chan *)urb->hcpriv;
|
|
|
-
|
|
|
- chan->urb = NULL;
|
|
|
- urb->hcpriv = NULL;
|
|
|
-
|
|
|
- if (urb->timeout) {
|
|
|
- urb->timeout = 0;
|
|
|
- urb->errorcode = -USB_ERR_SHUTDOWN;
|
|
|
- usb_osal_sem_give(chan->waitsem);
|
|
|
- } else {
|
|
|
- dwc2_chan_free(chan);
|
|
|
- }
|
|
|
-
|
|
|
- usb_osal_leave_critical_section(flags);
|
|
|
-
|
|
|
- return 0;
|
|
|
-}
|
|
|
-
|
|
|
-static inline void dwc2_urb_waitup(struct usbh_urb *urb)
|
|
|
-{
|
|
|
- struct dwc2_chan *chan;
|
|
|
-
|
|
|
- chan = (struct dwc2_chan *)urb->hcpriv;
|
|
|
- chan->urb = NULL;
|
|
|
- urb->hcpriv = NULL;
|
|
|
-
|
|
|
- if (urb->timeout) {
|
|
|
- urb->timeout = 0;
|
|
|
- usb_osal_sem_give(chan->waitsem);
|
|
|
- } else {
|
|
|
- dwc2_chan_free(chan);
|
|
|
- }
|
|
|
-
|
|
|
- if (urb->complete) {
|
|
|
- if (urb->errorcode < 0) {
|
|
|
- urb->complete(urb->arg, urb->errorcode);
|
|
|
- } else {
|
|
|
- urb->complete(urb->arg, urb->actual_length);
|
|
|
- }
|
|
|
- }
|
|
|
+ return -USB_ERR_NOTSUPP;
|
|
|
}
|
|
|
|
|
|
void USBH_IRQHandler(uint8_t busid)
|