2022-08-18 21:41:19 +08:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2022, sakumisu
|
2022-02-08 11:44:46 +08:00
|
|
|
*
|
2022-08-18 21:41:19 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2022-02-08 11:44:46 +08:00
|
|
|
*/
|
2023-11-20 22:15:43 +08:00
|
|
|
#include "usbh_core.h"
|
2022-02-08 11:44:46 +08:00
|
|
|
#include "usbh_hub.h"
|
|
|
|
|
|
2023-11-15 22:08:26 +08:00
|
|
|
#define DEV_FORMAT "/dev/hub%d"
|
2022-02-08 11:44:46 +08:00
|
|
|
|
2022-12-31 14:06:53 +08:00
|
|
|
#define HUB_DEBOUNCE_TIMEOUT 1500
|
|
|
|
|
#define HUB_DEBOUNCE_STEP 25
|
|
|
|
|
#define HUB_DEBOUNCE_STABLE 100
|
2022-09-04 20:17:32 +08:00
|
|
|
#define DELAY_TIME_AFTER_RESET 200
|
|
|
|
|
|
2023-11-15 22:08:26 +08:00
|
|
|
#define EXTHUB_FIRST_INDEX 2
|
2022-09-11 23:03:23 +08:00
|
|
|
|
2022-09-04 20:17:32 +08:00
|
|
|
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_hub_buf[32];
|
2023-04-22 14:23:26 +08:00
|
|
|
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_hub_intbuf[CONFIG_USBHOST_MAX_EXTHUBS + 1][CONFIG_USB_ALIGN_SIZE];
|
2022-09-04 20:17:32 +08:00
|
|
|
|
2022-02-08 11:44:46 +08:00
|
|
|
usb_slist_t hub_class_head = USB_SLIST_OBJECT_INIT(hub_class_head);
|
|
|
|
|
|
2022-09-04 20:17:32 +08:00
|
|
|
usb_osal_thread_t hub_thread;
|
2022-12-11 18:50:33 +08:00
|
|
|
usb_osal_mq_t hub_mq;
|
2022-02-08 11:44:46 +08:00
|
|
|
|
2023-02-18 15:18:49 +08:00
|
|
|
struct usbh_hub roothub;
|
2022-02-08 11:44:46 +08:00
|
|
|
|
2023-11-15 22:08:26 +08:00
|
|
|
extern int usbh_free_devaddr(struct usbh_hubport *hport);
|
2022-09-04 20:17:32 +08:00
|
|
|
extern int usbh_enumerate(struct usbh_hubport *hport);
|
2022-02-08 11:44:46 +08:00
|
|
|
|
2022-09-23 21:58:36 +08:00
|
|
|
static const char *speed_table[] = { "error-speed", "low-speed", "full-speed", "high-speed", "wireless-speed", "super-speed", "superplus-speed" };
|
2022-02-08 11:44:46 +08:00
|
|
|
|
2023-04-21 23:43:59 +08:00
|
|
|
#ifdef CONFIG_USBHOST_XHCI
|
|
|
|
|
struct usbh_hubport *usbh_get_roothub_port(unsigned int port)
|
|
|
|
|
{
|
|
|
|
|
return &roothub.child[port - 1];
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2022-12-03 19:31:39 +08:00
|
|
|
#if CONFIG_USBHOST_MAX_EXTHUBS > 0
|
2023-07-12 22:34:01 +08:00
|
|
|
static struct usbh_hub g_hub_class[CONFIG_USBHOST_MAX_EXTHUBS];
|
|
|
|
|
static uint32_t g_devinuse = 0;
|
|
|
|
|
|
2023-08-05 11:08:24 +08:00
|
|
|
static struct usbh_hub *usbh_hub_class_alloc(void)
|
2022-02-08 11:44:46 +08:00
|
|
|
{
|
|
|
|
|
int devno;
|
|
|
|
|
|
2023-07-12 22:34:01 +08:00
|
|
|
for (devno = 0; devno < CONFIG_USBHOST_MAX_EXTHUBS; devno++) {
|
|
|
|
|
if ((g_devinuse & (1 << devno)) == 0) {
|
|
|
|
|
g_devinuse |= (1 << devno);
|
|
|
|
|
memset(&g_hub_class[devno], 0, sizeof(struct usbh_hub));
|
|
|
|
|
g_hub_class[devno].index = EXTHUB_FIRST_INDEX + devno;
|
|
|
|
|
return &g_hub_class[devno];
|
2022-02-08 11:44:46 +08:00
|
|
|
}
|
|
|
|
|
}
|
2023-07-12 22:34:01 +08:00
|
|
|
return NULL;
|
2022-02-08 11:44:46 +08:00
|
|
|
}
|
|
|
|
|
|
2023-08-05 11:08:24 +08:00
|
|
|
static void usbh_hub_class_free(struct usbh_hub *hub_class)
|
2022-02-08 11:44:46 +08:00
|
|
|
{
|
2023-07-12 22:34:01 +08:00
|
|
|
int devno = hub_class->index - EXTHUB_FIRST_INDEX;
|
|
|
|
|
|
|
|
|
|
if (devno >= 0 && devno < 32) {
|
2022-02-08 11:44:46 +08:00
|
|
|
g_devinuse &= ~(1 << devno);
|
|
|
|
|
}
|
2023-07-12 22:34:01 +08:00
|
|
|
memset(hub_class, 0, sizeof(struct usbh_hub));
|
2022-02-08 11:44:46 +08:00
|
|
|
}
|
2023-01-10 15:01:50 +08:00
|
|
|
#endif
|
2022-12-11 18:50:33 +08:00
|
|
|
|
|
|
|
|
static void usbh_hub_register(struct usbh_hub *hub)
|
|
|
|
|
{
|
|
|
|
|
usb_slist_add_tail(&hub_class_head, &hub->list);
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-17 10:23:18 +08:00
|
|
|
#if CONFIG_USBHOST_MAX_EXTHUBS > 0
|
2022-12-11 18:50:33 +08:00
|
|
|
static void usbh_hub_unregister(struct usbh_hub *hub)
|
|
|
|
|
{
|
|
|
|
|
usb_slist_remove(&hub_class_head, &hub->list);
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-04 20:17:32 +08:00
|
|
|
static int _usbh_hub_get_hub_descriptor(struct usbh_hub *hub, uint8_t *buffer)
|
2022-02-08 11:44:46 +08:00
|
|
|
{
|
|
|
|
|
struct usb_setup_packet *setup;
|
2022-09-04 20:17:32 +08:00
|
|
|
int ret;
|
2022-02-08 11:44:46 +08:00
|
|
|
|
2023-02-18 15:18:49 +08:00
|
|
|
setup = hub->parent->setup;
|
2022-02-08 11:44:46 +08:00
|
|
|
|
|
|
|
|
setup->bmRequestType = USB_REQUEST_DIR_IN | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_DEVICE;
|
|
|
|
|
setup->bRequest = USB_REQUEST_GET_DESCRIPTOR;
|
2023-04-21 23:43:59 +08:00
|
|
|
|
|
|
|
|
/* TODO: hub descriptor has some difference between USB 2.0 and USB 3.x,
|
|
|
|
|
and we havn't handle the difference here */
|
|
|
|
|
if ((hub->parent->speed == USB_SPEED_SUPER) ||
|
|
|
|
|
(hub->parent->speed == USB_SPEED_SUPER_PLUS)) {
|
|
|
|
|
setup->wValue = HUB_DESCRIPTOR_TYPE_HUB3 << 8;
|
|
|
|
|
} else {
|
|
|
|
|
setup->wValue = HUB_DESCRIPTOR_TYPE_HUB << 8;
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-08 11:44:46 +08:00
|
|
|
setup->wIndex = 0;
|
|
|
|
|
setup->wLength = USB_SIZEOF_HUB_DESC;
|
|
|
|
|
|
2023-11-15 22:08:26 +08:00
|
|
|
ret = usbh_control_transfer(hub->parent, setup, g_hub_buf);
|
2022-09-04 20:17:32 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
memcpy(buffer, g_hub_buf, USB_SIZEOF_HUB_DESC);
|
|
|
|
|
return ret;
|
2022-02-08 11:44:46 +08:00
|
|
|
}
|
2023-08-27 13:38:13 +08:00
|
|
|
#if 0
|
2022-09-04 20:17:32 +08:00
|
|
|
static int _usbh_hub_get_status(struct usbh_hub *hub, uint8_t *buffer)
|
2022-02-08 11:44:46 +08:00
|
|
|
{
|
|
|
|
|
struct usb_setup_packet *setup;
|
2022-09-04 20:17:32 +08:00
|
|
|
int ret;
|
2022-02-08 11:44:46 +08:00
|
|
|
|
2023-02-18 15:18:49 +08:00
|
|
|
setup = hub->parent->setup;
|
2022-02-08 11:44:46 +08:00
|
|
|
|
|
|
|
|
setup->bmRequestType = USB_REQUEST_DIR_IN | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_DEVICE;
|
|
|
|
|
setup->bRequest = HUB_REQUEST_GET_STATUS;
|
|
|
|
|
setup->wValue = 0;
|
|
|
|
|
setup->wIndex = 0;
|
|
|
|
|
setup->wLength = 2;
|
|
|
|
|
|
2023-11-15 22:08:26 +08:00
|
|
|
ret = usbh_control_transfer(hub->parent, setup, g_hub_buf);
|
2022-09-04 20:17:32 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
memcpy(buffer, g_hub_buf, 2);
|
|
|
|
|
return ret;
|
2022-02-08 11:44:46 +08:00
|
|
|
}
|
2023-03-17 10:23:18 +08:00
|
|
|
#endif
|
2023-08-27 13:38:13 +08:00
|
|
|
#endif
|
2022-02-08 11:44:46 +08:00
|
|
|
|
2022-09-04 20:17:32 +08:00
|
|
|
static int _usbh_hub_get_portstatus(struct usbh_hub *hub, uint8_t port, struct hub_port_status *port_status)
|
2022-02-08 11:44:46 +08:00
|
|
|
{
|
|
|
|
|
struct usb_setup_packet *setup;
|
2022-09-04 20:17:32 +08:00
|
|
|
int ret;
|
2022-02-08 11:44:46 +08:00
|
|
|
|
2023-02-18 15:18:49 +08:00
|
|
|
setup = hub->parent->setup;
|
2022-02-08 11:44:46 +08:00
|
|
|
|
|
|
|
|
setup->bmRequestType = USB_REQUEST_DIR_IN | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_OTHER;
|
|
|
|
|
setup->bRequest = HUB_REQUEST_GET_STATUS;
|
|
|
|
|
setup->wValue = 0;
|
|
|
|
|
setup->wIndex = port;
|
|
|
|
|
setup->wLength = 4;
|
|
|
|
|
|
2023-11-15 22:08:26 +08:00
|
|
|
ret = usbh_control_transfer(hub->parent, setup, g_hub_buf);
|
2022-09-04 20:17:32 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
memcpy(port_status, g_hub_buf, 4);
|
|
|
|
|
return ret;
|
2022-02-08 11:44:46 +08:00
|
|
|
}
|
|
|
|
|
|
2022-09-04 20:17:32 +08:00
|
|
|
static int _usbh_hub_set_feature(struct usbh_hub *hub, uint8_t port, uint8_t feature)
|
2022-02-08 11:44:46 +08:00
|
|
|
{
|
|
|
|
|
struct usb_setup_packet *setup;
|
|
|
|
|
|
2023-02-18 15:18:49 +08:00
|
|
|
setup = hub->parent->setup;
|
2022-02-08 11:44:46 +08:00
|
|
|
|
|
|
|
|
setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_OTHER;
|
|
|
|
|
setup->bRequest = HUB_REQUEST_SET_FEATURE;
|
|
|
|
|
setup->wValue = feature;
|
|
|
|
|
setup->wIndex = port;
|
|
|
|
|
setup->wLength = 0;
|
|
|
|
|
|
2023-11-15 22:08:26 +08:00
|
|
|
return usbh_control_transfer(hub->parent, setup, NULL);
|
2022-02-08 11:44:46 +08:00
|
|
|
}
|
|
|
|
|
|
2022-09-04 20:17:32 +08:00
|
|
|
static int _usbh_hub_clear_feature(struct usbh_hub *hub, uint8_t port, uint8_t feature)
|
2022-02-08 11:44:46 +08:00
|
|
|
{
|
|
|
|
|
struct usb_setup_packet *setup;
|
|
|
|
|
|
2023-02-18 15:18:49 +08:00
|
|
|
setup = hub->parent->setup;
|
2022-02-08 11:44:46 +08:00
|
|
|
|
|
|
|
|
setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_OTHER;
|
|
|
|
|
setup->bRequest = HUB_REQUEST_CLEAR_FEATURE;
|
|
|
|
|
setup->wValue = feature;
|
|
|
|
|
setup->wIndex = port;
|
|
|
|
|
setup->wLength = 0;
|
|
|
|
|
|
2023-11-15 22:08:26 +08:00
|
|
|
return usbh_control_transfer(hub->parent, setup, NULL);
|
2022-02-08 11:44:46 +08:00
|
|
|
}
|
|
|
|
|
|
2023-04-21 23:43:59 +08:00
|
|
|
static int _usbh_hub_set_depth(struct usbh_hub *hub, uint16_t depth)
|
|
|
|
|
{
|
|
|
|
|
struct usb_setup_packet *setup;
|
|
|
|
|
|
|
|
|
|
setup = hub->parent->setup;
|
|
|
|
|
|
|
|
|
|
setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_DEVICE;
|
|
|
|
|
setup->bRequest = HUB_REQUEST_SET_HUB_DEPTH;
|
|
|
|
|
setup->wValue = depth;
|
|
|
|
|
setup->wIndex = 0;
|
|
|
|
|
setup->wLength = 0;
|
|
|
|
|
|
2023-11-15 22:08:26 +08:00
|
|
|
return usbh_control_transfer(hub->parent, setup, NULL);
|
2023-04-21 23:43:59 +08:00
|
|
|
}
|
|
|
|
|
|
2023-03-17 10:23:18 +08:00
|
|
|
#if CONFIG_USBHOST_MAX_EXTHUBS > 0
|
2022-02-08 11:44:46 +08:00
|
|
|
static int parse_hub_descriptor(struct usb_hub_descriptor *desc, uint16_t length)
|
|
|
|
|
{
|
|
|
|
|
if (desc->bLength != USB_SIZEOF_HUB_DESC) {
|
|
|
|
|
USB_LOG_ERR("invalid device bLength 0x%02x\r\n", desc->bLength);
|
|
|
|
|
return -1;
|
|
|
|
|
} else if (desc->bDescriptorType != HUB_DESCRIPTOR_TYPE_HUB) {
|
|
|
|
|
USB_LOG_ERR("unexpected descriptor 0x%02x\r\n", desc->bDescriptorType);
|
|
|
|
|
return -2;
|
|
|
|
|
} else {
|
2022-09-11 23:03:23 +08:00
|
|
|
USB_LOG_RAW("Hub Descriptor:\r\n");
|
2022-09-04 20:17:32 +08:00
|
|
|
USB_LOG_RAW("bLength: 0x%02x \r\n", desc->bLength);
|
|
|
|
|
USB_LOG_RAW("bDescriptorType: 0x%02x \r\n", desc->bDescriptorType);
|
|
|
|
|
USB_LOG_RAW("bNbrPorts: 0x%02x \r\n", desc->bNbrPorts);
|
|
|
|
|
USB_LOG_RAW("wHubCharacteristics: 0x%04x \r\n", desc->wHubCharacteristics);
|
|
|
|
|
USB_LOG_RAW("bPwrOn2PwrGood: 0x%02x \r\n", desc->bPwrOn2PwrGood);
|
|
|
|
|
USB_LOG_RAW("bHubContrCurrent: 0x%02x \r\n", desc->bHubContrCurrent);
|
|
|
|
|
USB_LOG_RAW("DeviceRemovable: 0x%02x \r\n", desc->DeviceRemovable);
|
|
|
|
|
USB_LOG_RAW("PortPwrCtrlMask: 0x%02x \r\n", desc->PortPwrCtrlMask);
|
2022-02-08 11:44:46 +08:00
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2023-03-17 10:23:18 +08:00
|
|
|
#endif
|
2022-02-08 11:44:46 +08:00
|
|
|
|
2022-09-04 20:17:32 +08:00
|
|
|
static int usbh_hub_get_portstatus(struct usbh_hub *hub, uint8_t port, struct hub_port_status *port_status)
|
|
|
|
|
{
|
|
|
|
|
struct usb_setup_packet roothub_setup;
|
|
|
|
|
struct usb_setup_packet *setup;
|
|
|
|
|
|
|
|
|
|
if (hub->is_roothub) {
|
|
|
|
|
setup = &roothub_setup;
|
|
|
|
|
setup->bmRequestType = USB_REQUEST_DIR_IN | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_OTHER;
|
|
|
|
|
setup->bRequest = HUB_REQUEST_GET_STATUS;
|
|
|
|
|
setup->wValue = 0;
|
|
|
|
|
setup->wIndex = port;
|
|
|
|
|
setup->wLength = 4;
|
|
|
|
|
return usbh_roothub_control(&roothub_setup, (uint8_t *)port_status);
|
|
|
|
|
} else {
|
|
|
|
|
return _usbh_hub_get_portstatus(hub, port, port_status);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-20 22:15:43 +08:00
|
|
|
int usbh_hub_set_feature(struct usbh_hub *hub, uint8_t port, uint8_t feature)
|
2022-09-04 20:17:32 +08:00
|
|
|
{
|
|
|
|
|
struct usb_setup_packet roothub_setup;
|
|
|
|
|
struct usb_setup_packet *setup;
|
|
|
|
|
|
|
|
|
|
if (hub->is_roothub) {
|
|
|
|
|
setup = &roothub_setup;
|
|
|
|
|
setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_OTHER;
|
|
|
|
|
setup->bRequest = HUB_REQUEST_SET_FEATURE;
|
|
|
|
|
setup->wValue = feature;
|
|
|
|
|
setup->wIndex = port;
|
|
|
|
|
setup->wLength = 0;
|
|
|
|
|
return usbh_roothub_control(setup, NULL);
|
|
|
|
|
} else {
|
|
|
|
|
return _usbh_hub_set_feature(hub, port, feature);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-20 22:15:43 +08:00
|
|
|
int usbh_hub_clear_feature(struct usbh_hub *hub, uint8_t port, uint8_t feature)
|
2022-09-04 20:17:32 +08:00
|
|
|
{
|
|
|
|
|
struct usb_setup_packet roothub_setup;
|
|
|
|
|
struct usb_setup_packet *setup;
|
|
|
|
|
|
|
|
|
|
if (hub->is_roothub) {
|
|
|
|
|
setup = &roothub_setup;
|
|
|
|
|
setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_OTHER;
|
|
|
|
|
setup->bRequest = HUB_REQUEST_CLEAR_FEATURE;
|
|
|
|
|
setup->wValue = feature;
|
|
|
|
|
setup->wIndex = port;
|
|
|
|
|
setup->wLength = 0;
|
|
|
|
|
return usbh_roothub_control(setup, NULL);
|
|
|
|
|
} else {
|
|
|
|
|
return _usbh_hub_clear_feature(hub, port, feature);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-21 23:43:59 +08:00
|
|
|
static int usbh_hub_set_depth(struct usbh_hub *hub, uint16_t depth)
|
|
|
|
|
{
|
|
|
|
|
struct usb_setup_packet roothub_setup;
|
|
|
|
|
struct usb_setup_packet *setup;
|
|
|
|
|
|
|
|
|
|
if (hub->is_roothub) {
|
|
|
|
|
setup = &roothub_setup;
|
|
|
|
|
setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_DEVICE;
|
|
|
|
|
setup->bRequest = HUB_REQUEST_SET_HUB_DEPTH;
|
|
|
|
|
setup->wValue = depth;
|
|
|
|
|
setup->wIndex = 0;
|
|
|
|
|
setup->wLength = 0;
|
|
|
|
|
return usbh_roothub_control(setup, NULL);
|
|
|
|
|
} else {
|
|
|
|
|
return _usbh_hub_set_depth(hub, depth);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-15 22:08:26 +08:00
|
|
|
static void usbh_hub_thread_wakeup(struct usbh_hub *hub)
|
|
|
|
|
{
|
|
|
|
|
usb_osal_mq_send(hub_mq, (uintptr_t)hub);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void usbh_hubport_release(struct usbh_hubport *child)
|
|
|
|
|
{
|
|
|
|
|
if (child->connected) {
|
|
|
|
|
child->connected = false;
|
|
|
|
|
usbh_free_devaddr(child);
|
|
|
|
|
for (uint8_t i = 0; i < child->config.config_desc.bNumInterfaces; i++) {
|
|
|
|
|
if (child->config.intf[i].class_driver && child->config.intf[i].class_driver->disconnect) {
|
|
|
|
|
CLASS_DISCONNECT(child, i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
child->config.config_desc.bNumInterfaces = 0;
|
2023-11-17 21:05:07 +08:00
|
|
|
usbh_kill_urb(&child->ep0_urb);
|
2023-11-15 22:08:26 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-11 18:50:33 +08:00
|
|
|
#if CONFIG_USBHOST_MAX_EXTHUBS > 0
|
2022-09-09 22:18:02 +08:00
|
|
|
static void hub_int_complete_callback(void *arg, int nbytes)
|
|
|
|
|
{
|
|
|
|
|
struct usbh_hub *hub = (struct usbh_hub *)arg;
|
|
|
|
|
|
2023-11-15 22:08:26 +08:00
|
|
|
if (nbytes > 0) {
|
2022-09-09 22:18:02 +08:00
|
|
|
usbh_hub_thread_wakeup(hub);
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-12-11 18:50:33 +08:00
|
|
|
|
2022-04-04 15:37:14 +08:00
|
|
|
static int usbh_hub_connect(struct usbh_hubport *hport, uint8_t intf)
|
2022-02-08 11:44:46 +08:00
|
|
|
{
|
|
|
|
|
struct usb_endpoint_descriptor *ep_desc;
|
2022-09-04 20:17:32 +08:00
|
|
|
struct hub_port_status port_status;
|
2022-02-08 11:44:46 +08:00
|
|
|
int ret;
|
|
|
|
|
|
2023-08-05 11:08:24 +08:00
|
|
|
struct usbh_hub *hub = usbh_hub_class_alloc();
|
2023-07-12 22:34:01 +08:00
|
|
|
if (hub == NULL) {
|
2023-11-13 19:50:04 +08:00
|
|
|
USB_LOG_ERR("Fail to alloc hub_class\r\n");
|
2022-02-08 11:44:46 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-04 20:17:32 +08:00
|
|
|
hub->hub_addr = hport->dev_addr;
|
|
|
|
|
hub->parent = hport;
|
2022-02-24 12:29:06 +08:00
|
|
|
|
2022-09-04 20:17:32 +08:00
|
|
|
hport->config.intf[intf].priv = hub;
|
2022-02-08 11:44:46 +08:00
|
|
|
|
2022-09-04 20:17:32 +08:00
|
|
|
ret = _usbh_hub_get_hub_descriptor(hub, (uint8_t *)&hub->hub_desc);
|
|
|
|
|
if (ret < 0) {
|
2022-02-08 11:44:46 +08:00
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-04 20:17:32 +08:00
|
|
|
parse_hub_descriptor(&hub->hub_desc, USB_SIZEOF_HUB_DESC);
|
2022-02-08 11:44:46 +08:00
|
|
|
|
2022-09-04 20:17:32 +08:00
|
|
|
for (uint8_t port = 0; port < hub->hub_desc.bNbrPorts; port++) {
|
|
|
|
|
hub->child[port].port = port + 1;
|
|
|
|
|
hub->child[port].parent = hub;
|
2022-02-08 11:44:46 +08:00
|
|
|
}
|
|
|
|
|
|
2022-09-14 19:50:06 +08:00
|
|
|
ep_desc = &hport->config.intf[intf].altsetting[0].ep[0].ep_desc;
|
2022-02-08 11:44:46 +08:00
|
|
|
if (ep_desc->bEndpointAddress & 0x80) {
|
2023-11-15 22:08:26 +08:00
|
|
|
USBH_EP_INIT(hub->intin, ep_desc);
|
2022-02-08 11:44:46 +08:00
|
|
|
} else {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-21 23:43:59 +08:00
|
|
|
if (hport->speed == USB_SPEED_SUPER) {
|
|
|
|
|
uint16_t depth = 0;
|
|
|
|
|
struct usbh_hubport *parent = hport->parent->parent;
|
|
|
|
|
while (parent) {
|
|
|
|
|
depth++;
|
|
|
|
|
parent = parent->parent->parent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ret = usbh_hub_set_depth(hub, depth);
|
|
|
|
|
if (ret < 0) {
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-04 20:17:32 +08:00
|
|
|
for (uint8_t port = 0; port < hub->hub_desc.bNbrPorts; port++) {
|
2022-09-11 22:43:51 +08:00
|
|
|
ret = usbh_hub_set_feature(hub, port + 1, HUB_PORT_FEATURE_POWER);
|
2022-02-08 11:44:46 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-04 20:17:32 +08:00
|
|
|
for (uint8_t port = 0; port < hub->hub_desc.bNbrPorts; port++) {
|
|
|
|
|
ret = usbh_hub_get_portstatus(hub, port + 1, &port_status);
|
2022-09-11 23:03:23 +08:00
|
|
|
USB_LOG_INFO("port %u, status:0x%02x, change:0x%02x\r\n", port + 1, port_status.wPortStatus, port_status.wPortChange);
|
2022-02-08 11:44:46 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-09 22:18:02 +08:00
|
|
|
hub->connected = true;
|
2022-09-04 20:17:32 +08:00
|
|
|
snprintf(hport->config.intf[intf].devname, CONFIG_USBHOST_DEV_NAMELEN, DEV_FORMAT, hub->index);
|
|
|
|
|
usbh_hub_register(hub);
|
2022-02-24 12:29:06 +08:00
|
|
|
USB_LOG_INFO("Register HUB Class:%s\r\n", hport->config.intf[intf].devname);
|
2022-02-08 11:44:46 +08:00
|
|
|
|
2023-02-18 15:18:49 +08:00
|
|
|
hub->int_buffer = g_hub_intbuf[hub->index - 1];
|
2023-11-15 22:08:26 +08:00
|
|
|
usbh_int_urb_fill(&hub->intin_urb, hub->parent, hub->intin, hub->int_buffer, 1, 0, hub_int_complete_callback, hub);
|
2022-09-15 20:46:14 +08:00
|
|
|
usbh_submit_urb(&hub->intin_urb);
|
2022-02-08 11:44:46 +08:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-04 15:37:14 +08:00
|
|
|
static int usbh_hub_disconnect(struct usbh_hubport *hport, uint8_t intf)
|
2022-02-08 11:44:46 +08:00
|
|
|
{
|
|
|
|
|
struct usbh_hubport *child;
|
|
|
|
|
int ret = 0;
|
|
|
|
|
|
2022-09-04 20:17:32 +08:00
|
|
|
struct usbh_hub *hub = (struct usbh_hub *)hport->config.intf[intf].priv;
|
2022-02-08 11:44:46 +08:00
|
|
|
|
2022-09-04 20:17:32 +08:00
|
|
|
if (hub) {
|
|
|
|
|
if (hub->intin) {
|
2023-11-15 22:08:26 +08:00
|
|
|
usbh_kill_urb(&hub->intin_urb);
|
2022-02-08 11:44:46 +08:00
|
|
|
}
|
|
|
|
|
|
2022-09-04 20:17:32 +08:00
|
|
|
for (uint8_t port = 0; port < hub->hub_desc.bNbrPorts; port++) {
|
|
|
|
|
child = &hub->child[port];
|
2023-11-15 22:08:26 +08:00
|
|
|
usbh_hubport_release(child);
|
2022-02-08 11:44:46 +08:00
|
|
|
child->parent = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-12 22:34:01 +08:00
|
|
|
if (hport->config.intf[intf].devname[0] != '\0') {
|
2022-05-22 17:09:47 +08:00
|
|
|
USB_LOG_INFO("Unregister HUB Class:%s\r\n", hport->config.intf[intf].devname);
|
2023-07-12 22:34:01 +08:00
|
|
|
usbh_hub_unregister(hub);
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-05 11:08:24 +08:00
|
|
|
usbh_hub_class_free(hub);
|
2022-02-08 11:44:46 +08:00
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
2022-12-03 19:31:39 +08:00
|
|
|
#endif
|
2022-09-04 20:17:32 +08:00
|
|
|
|
2023-07-05 22:39:47 +08:00
|
|
|
static void usbh_hubport_enumerate_thread(void *argument)
|
|
|
|
|
{
|
|
|
|
|
struct usbh_hubport *child = (struct usbh_hubport *)argument;
|
|
|
|
|
|
|
|
|
|
if (usbh_enumerate(child) < 0) {
|
|
|
|
|
/** release child sources */
|
|
|
|
|
usbh_hubport_release(child);
|
|
|
|
|
USB_LOG_ERR("Port %u enumerate fail\r\n", child->port);
|
|
|
|
|
}
|
2023-07-12 21:48:18 +08:00
|
|
|
usb_osal_thread_delete(NULL);
|
2023-07-05 22:39:47 +08:00
|
|
|
}
|
|
|
|
|
|
2022-09-04 20:17:32 +08:00
|
|
|
static void usbh_hub_events(struct usbh_hub *hub)
|
|
|
|
|
{
|
|
|
|
|
struct usbh_hubport *child;
|
|
|
|
|
struct hub_port_status port_status;
|
|
|
|
|
uint8_t portchange_index;
|
|
|
|
|
uint16_t portstatus;
|
|
|
|
|
uint16_t portchange;
|
2022-02-08 11:44:46 +08:00
|
|
|
uint16_t mask;
|
|
|
|
|
uint16_t feat;
|
2022-09-04 20:17:32 +08:00
|
|
|
uint8_t speed;
|
2022-02-08 11:44:46 +08:00
|
|
|
int ret;
|
|
|
|
|
|
2022-09-04 20:17:32 +08:00
|
|
|
if (!hub->connected) {
|
2022-02-08 11:44:46 +08:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-11 17:44:36 +08:00
|
|
|
portchange_index = hub->int_buffer[0];
|
|
|
|
|
hub->int_buffer[0] = 0;
|
2022-09-04 20:17:32 +08:00
|
|
|
|
2023-08-11 17:44:36 +08:00
|
|
|
for (uint8_t port = 0; port < hub->hub_desc.bNbrPorts; port++) {
|
2022-09-04 20:17:32 +08:00
|
|
|
USB_LOG_DBG("Port change:0x%02x\r\n", portchange_index);
|
2022-02-08 11:44:46 +08:00
|
|
|
|
2022-09-04 20:17:32 +08:00
|
|
|
if (!(portchange_index & (1 << (port + 1)))) {
|
2022-02-08 11:44:46 +08:00
|
|
|
continue;
|
|
|
|
|
}
|
2022-09-04 20:17:32 +08:00
|
|
|
portchange_index &= ~(1 << (port + 1));
|
|
|
|
|
USB_LOG_DBG("Port %d change\r\n", port + 1);
|
2022-02-08 11:44:46 +08:00
|
|
|
|
|
|
|
|
/* Read hub port status */
|
2022-09-04 20:17:32 +08:00
|
|
|
ret = usbh_hub_get_portstatus(hub, port + 1, &port_status);
|
2022-02-08 11:44:46 +08:00
|
|
|
if (ret < 0) {
|
2022-09-04 20:17:32 +08:00
|
|
|
USB_LOG_ERR("Failed to read port %u status, errorcode: %d\r\n", port + 1, ret);
|
2022-02-08 11:44:46 +08:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-04 20:17:32 +08:00
|
|
|
portstatus = port_status.wPortStatus;
|
|
|
|
|
portchange = port_status.wPortChange;
|
|
|
|
|
|
|
|
|
|
USB_LOG_DBG("port %u, status:0x%02x, change:0x%02x\r\n", port + 1, portstatus, portchange);
|
2022-02-08 11:44:46 +08:00
|
|
|
|
|
|
|
|
/* First, clear all change bits */
|
|
|
|
|
mask = 1;
|
|
|
|
|
feat = HUB_PORT_FEATURE_C_CONNECTION;
|
2022-09-04 20:17:32 +08:00
|
|
|
while (portchange) {
|
|
|
|
|
if (portchange & mask) {
|
|
|
|
|
ret = usbh_hub_clear_feature(hub, port + 1, feat);
|
2022-02-08 11:44:46 +08:00
|
|
|
if (ret < 0) {
|
2022-09-04 20:17:32 +08:00
|
|
|
USB_LOG_ERR("Failed to clear port %u, change mask:%04x, errorcode:%d\r\n", port + 1, mask, ret);
|
|
|
|
|
continue;
|
2022-02-08 11:44:46 +08:00
|
|
|
}
|
2022-09-04 20:17:32 +08:00
|
|
|
portchange &= (~mask);
|
2022-02-08 11:44:46 +08:00
|
|
|
}
|
|
|
|
|
mask <<= 1;
|
|
|
|
|
feat++;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-04 20:17:32 +08:00
|
|
|
portchange = port_status.wPortChange;
|
2022-02-08 11:44:46 +08:00
|
|
|
|
2022-09-04 20:17:32 +08:00
|
|
|
/* Second, if port changes, debounces first */
|
|
|
|
|
if (portchange & HUB_PORT_STATUS_C_CONNECTION) {
|
|
|
|
|
uint16_t connection = 0;
|
2022-02-18 17:53:46 +08:00
|
|
|
uint16_t debouncestable = 0;
|
2022-12-31 14:06:53 +08:00
|
|
|
for (uint32_t debouncetime = 0; debouncetime < HUB_DEBOUNCE_TIMEOUT; debouncetime += HUB_DEBOUNCE_STEP) {
|
2022-09-04 20:17:32 +08:00
|
|
|
/* Read hub port status */
|
|
|
|
|
ret = usbh_hub_get_portstatus(hub, port + 1, &port_status);
|
2022-02-18 17:53:46 +08:00
|
|
|
if (ret < 0) {
|
2022-09-04 20:17:32 +08:00
|
|
|
USB_LOG_ERR("Failed to read port %u status, errorcode: %d\r\n", port + 1, ret);
|
|
|
|
|
continue;
|
2022-02-18 17:53:46 +08:00
|
|
|
}
|
2022-09-04 20:17:32 +08:00
|
|
|
|
|
|
|
|
portstatus = port_status.wPortStatus;
|
|
|
|
|
portchange = port_status.wPortChange;
|
|
|
|
|
|
|
|
|
|
USB_LOG_DBG("Port %u, status:0x%02x, change:0x%02x\r\n", port + 1, portstatus, portchange);
|
2022-12-31 14:06:53 +08:00
|
|
|
|
|
|
|
|
if (!(portchange & HUB_PORT_STATUS_C_CONNECTION) &&
|
|
|
|
|
((portstatus & HUB_PORT_STATUS_CONNECTION) == connection)) {
|
|
|
|
|
debouncestable += HUB_DEBOUNCE_STEP;
|
|
|
|
|
if (debouncestable >= HUB_DEBOUNCE_STABLE) {
|
|
|
|
|
break;
|
2022-02-18 17:53:46 +08:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
debouncestable = 0;
|
2022-12-31 14:06:53 +08:00
|
|
|
connection = portstatus & HUB_PORT_STATUS_CONNECTION;
|
2022-02-18 17:53:46 +08:00
|
|
|
}
|
|
|
|
|
|
2022-09-04 20:17:32 +08:00
|
|
|
if (portchange & HUB_PORT_STATUS_C_CONNECTION) {
|
|
|
|
|
usbh_hub_clear_feature(hub, port + 1, HUB_PORT_FEATURE_C_CONNECTION);
|
|
|
|
|
}
|
2022-12-31 14:06:53 +08:00
|
|
|
|
|
|
|
|
usb_osal_msleep(HUB_DEBOUNCE_STEP);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** check if debounce ok */
|
|
|
|
|
if (debouncestable < HUB_DEBOUNCE_STABLE) {
|
|
|
|
|
USB_LOG_ERR("Failed to debounce port %u\r\n", port + 1);
|
|
|
|
|
break;
|
2022-02-08 11:44:46 +08:00
|
|
|
}
|
|
|
|
|
|
2022-09-04 20:17:32 +08:00
|
|
|
/* Last, check connect status */
|
|
|
|
|
if (portstatus & HUB_PORT_STATUS_CONNECTION) {
|
|
|
|
|
ret = usbh_hub_set_feature(hub, port + 1, HUB_PORT_FEATURE_RESET);
|
2022-02-08 11:44:46 +08:00
|
|
|
if (ret < 0) {
|
2022-09-04 20:17:32 +08:00
|
|
|
USB_LOG_ERR("Failed to reset port %u,errorcode:%d\r\n", port, ret);
|
2022-02-08 11:44:46 +08:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-04 20:17:32 +08:00
|
|
|
usb_osal_msleep(DELAY_TIME_AFTER_RESET);
|
|
|
|
|
/* Read hub port status */
|
|
|
|
|
ret = usbh_hub_get_portstatus(hub, port + 1, &port_status);
|
2022-02-08 11:44:46 +08:00
|
|
|
if (ret < 0) {
|
2022-09-04 20:17:32 +08:00
|
|
|
USB_LOG_ERR("Failed to read port %u status, errorcode: %d\r\n", port + 1, ret);
|
2022-02-08 11:44:46 +08:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-04 20:17:32 +08:00
|
|
|
portstatus = port_status.wPortStatus;
|
|
|
|
|
portchange = port_status.wPortChange;
|
|
|
|
|
if (!(portstatus & HUB_PORT_STATUS_RESET) && (portstatus & HUB_PORT_STATUS_ENABLE)) {
|
|
|
|
|
if (portchange & HUB_PORT_STATUS_C_RESET) {
|
|
|
|
|
ret = usbh_hub_clear_feature(hub, port + 1, HUB_PORT_FEATURE_C_RESET);
|
2022-02-08 11:44:46 +08:00
|
|
|
if (ret < 0) {
|
2022-09-04 20:17:32 +08:00
|
|
|
USB_LOG_ERR("Failed to clear port %u reset change, errorcode: %d\r\n", port, ret);
|
2022-02-08 11:44:46 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-04 20:17:32 +08:00
|
|
|
if (portstatus & HUB_PORT_STATUS_HIGH_SPEED) {
|
|
|
|
|
speed = USB_SPEED_HIGH;
|
|
|
|
|
} else if (portstatus & HUB_PORT_STATUS_LOW_SPEED) {
|
|
|
|
|
speed = USB_SPEED_LOW;
|
2023-04-21 23:43:59 +08:00
|
|
|
}
|
|
|
|
|
#ifdef CONFIG_USBHOST_XHCI
|
2023-04-29 15:17:59 +08:00
|
|
|
else {
|
|
|
|
|
extern uint8_t usbh_get_port_speed(struct usbh_hub * hub, const uint8_t port);
|
2023-04-21 23:43:59 +08:00
|
|
|
|
2023-04-29 15:17:59 +08:00
|
|
|
/* USB3.0 speed cannot get from portstatus, checkout port speed instead */
|
2023-04-21 23:43:59 +08:00
|
|
|
uint8_t super_speed = usbh_get_port_speed(hub, port + 1);
|
|
|
|
|
if (super_speed > USB_SPEED_HIGH) {
|
|
|
|
|
/* assert that when using USB 3.0 ports, attached device must also be USB 3.0 speed */
|
|
|
|
|
speed = super_speed;
|
|
|
|
|
} else {
|
|
|
|
|
speed = USB_SPEED_FULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
else {
|
2022-09-04 20:17:32 +08:00
|
|
|
speed = USB_SPEED_FULL;
|
2022-02-08 11:44:46 +08:00
|
|
|
}
|
2023-04-21 23:43:59 +08:00
|
|
|
#endif
|
2022-02-08 11:44:46 +08:00
|
|
|
|
2022-09-04 20:17:32 +08:00
|
|
|
child = &hub->child[port];
|
2022-12-31 14:06:53 +08:00
|
|
|
/** release child sources first */
|
|
|
|
|
usbh_hubport_release(child);
|
2022-12-03 19:39:27 +08:00
|
|
|
|
2022-09-04 20:17:32 +08:00
|
|
|
memset(child, 0, sizeof(struct usbh_hubport));
|
|
|
|
|
child->parent = hub;
|
|
|
|
|
child->connected = true;
|
|
|
|
|
child->port = port + 1;
|
|
|
|
|
child->speed = speed;
|
2023-04-21 23:24:13 +08:00
|
|
|
|
2022-09-04 20:17:32 +08:00
|
|
|
USB_LOG_INFO("New %s device on Hub %u, Port %u connected\r\n", speed_table[speed], hub->index, port + 1);
|
|
|
|
|
|
2023-07-05 22:39:47 +08:00
|
|
|
/* create disposable thread to enumerate device on current hport, do not block hub thread */
|
2023-11-17 21:05:07 +08:00
|
|
|
usb_osal_thread_create("usbh_enum", CONFIG_USBHOST_PSC_STACKSIZE, CONFIG_USBHOST_PSC_PRIO + 1, usbh_hubport_enumerate_thread, (void *)child);
|
2022-02-08 11:44:46 +08:00
|
|
|
} else {
|
2022-12-30 20:57:54 +08:00
|
|
|
child = &hub->child[port];
|
2022-12-31 14:06:53 +08:00
|
|
|
/** release child sources */
|
|
|
|
|
usbh_hubport_release(child);
|
2023-04-21 23:43:59 +08:00
|
|
|
|
|
|
|
|
/** some USB 3.0 ip may failed to enable USB 2.0 port for USB 3.0 device */
|
|
|
|
|
USB_LOG_WRN("Failed to enable port %u\r\n", port + 1);
|
2022-12-31 14:06:53 +08:00
|
|
|
|
2022-02-08 11:44:46 +08:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2022-09-04 20:17:32 +08:00
|
|
|
child = &hub->child[port];
|
2022-12-31 14:06:53 +08:00
|
|
|
/** release child sources */
|
|
|
|
|
usbh_hubport_release(child);
|
2023-02-23 17:53:42 +08:00
|
|
|
USB_LOG_INFO("Device on Hub %u, Port %u disconnected\r\n", hub->index, port + 1);
|
2022-02-08 11:44:46 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-10-05 12:22:23 +08:00
|
|
|
|
|
|
|
|
/* Start next hub int transfer */
|
|
|
|
|
if (!hub->is_roothub && hub->connected) {
|
|
|
|
|
usbh_submit_urb(&hub->intin_urb);
|
|
|
|
|
}
|
2022-09-04 20:17:32 +08:00
|
|
|
}
|
2022-02-08 11:44:46 +08:00
|
|
|
|
2022-09-04 20:17:32 +08:00
|
|
|
static void usbh_hub_thread(void *argument)
|
|
|
|
|
{
|
2022-12-11 18:50:33 +08:00
|
|
|
struct usbh_hub *hub;
|
2022-09-04 20:17:32 +08:00
|
|
|
int ret = 0;
|
2022-02-08 11:44:46 +08:00
|
|
|
|
2022-09-04 20:17:32 +08:00
|
|
|
usb_hc_init();
|
|
|
|
|
while (1) {
|
2023-10-12 10:23:51 +08:00
|
|
|
ret = usb_osal_mq_recv(hub_mq, (uintptr_t *)&hub, USB_OSAL_WAITING_FOREVER);
|
2022-09-04 20:17:32 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2022-12-11 18:50:33 +08:00
|
|
|
usbh_hub_events(hub);
|
2022-02-08 11:44:46 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-11 18:50:33 +08:00
|
|
|
static void usbh_roothub_register(void)
|
2022-02-08 11:44:46 +08:00
|
|
|
{
|
2022-12-11 18:50:33 +08:00
|
|
|
memset(&roothub, 0, sizeof(struct usbh_hub));
|
|
|
|
|
|
|
|
|
|
roothub.connected = true;
|
|
|
|
|
roothub.index = 1;
|
|
|
|
|
roothub.is_roothub = true;
|
|
|
|
|
roothub.parent = NULL;
|
|
|
|
|
roothub.hub_addr = 1;
|
|
|
|
|
roothub.hub_desc.bNbrPorts = CONFIG_USBHOST_MAX_RHPORTS;
|
|
|
|
|
usbh_hub_register(&roothub);
|
2022-09-04 20:17:32 +08:00
|
|
|
}
|
|
|
|
|
|
2022-12-11 18:50:33 +08:00
|
|
|
void usbh_roothub_thread_wakeup(uint8_t port)
|
2022-09-04 20:17:32 +08:00
|
|
|
{
|
2023-02-18 15:18:49 +08:00
|
|
|
roothub.int_buffer = g_hub_intbuf[roothub.index - 1];
|
2022-12-11 18:50:33 +08:00
|
|
|
roothub.int_buffer[0] |= (1 << port);
|
|
|
|
|
usbh_hub_thread_wakeup(&roothub);
|
2022-09-04 20:17:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int usbh_hub_initialize(void)
|
|
|
|
|
{
|
2022-09-14 19:50:06 +08:00
|
|
|
usbh_roothub_register();
|
|
|
|
|
|
2022-12-11 18:50:33 +08:00
|
|
|
hub_mq = usb_osal_mq_create(7);
|
|
|
|
|
if (hub_mq == NULL) {
|
2022-09-04 20:17:32 +08:00
|
|
|
return -1;
|
2022-02-08 11:44:46 +08:00
|
|
|
}
|
2022-09-04 20:17:32 +08:00
|
|
|
|
|
|
|
|
hub_thread = usb_osal_thread_create("usbh_hub", CONFIG_USBHOST_PSC_STACKSIZE, CONFIG_USBHOST_PSC_PRIO, usbh_hub_thread, NULL);
|
|
|
|
|
if (hub_thread == NULL) {
|
|
|
|
|
return -1;
|
2022-02-08 11:44:46 +08:00
|
|
|
}
|
2022-09-04 20:17:32 +08:00
|
|
|
return 0;
|
2022-02-08 11:44:46 +08:00
|
|
|
}
|
2022-12-03 19:31:39 +08:00
|
|
|
#if CONFIG_USBHOST_MAX_EXTHUBS > 0
|
2022-12-31 15:55:07 +08:00
|
|
|
const struct usbh_class_driver hub_class_driver = {
|
2022-02-08 11:44:46 +08:00
|
|
|
.driver_name = "hub",
|
|
|
|
|
.connect = usbh_hub_connect,
|
|
|
|
|
.disconnect = usbh_hub_disconnect
|
2022-03-23 17:15:57 +08:00
|
|
|
};
|
|
|
|
|
|
2022-12-31 15:55:07 +08:00
|
|
|
CLASS_INFO_DEFINE const struct usbh_class_info hub_class_info = {
|
2022-03-23 17:15:57 +08:00
|
|
|
.match_flags = USB_CLASS_MATCH_INTF_CLASS,
|
|
|
|
|
.class = USB_DEVICE_CLASS_HUB,
|
|
|
|
|
.subclass = 0,
|
|
|
|
|
.protocol = 0,
|
|
|
|
|
.vid = 0x00,
|
|
|
|
|
.pid = 0x00,
|
2022-12-31 15:55:07 +08:00
|
|
|
.class_driver = &hub_class_driver
|
2022-03-27 14:38:47 +08:00
|
|
|
};
|
2022-12-30 20:57:54 +08:00
|
|
|
#endif
|