From 88c0d13f0bc0e632874449de487310194618628b Mon Sep 17 00:00:00 2001 From: CTCaer Date: Sun, 22 Jun 2025 13:10:47 +0300 Subject: [PATCH] bdk: usb: remove unused endpoint from hid --- bdk/usb/usb_descriptor_types.h | 4 ++-- bdk/usb/usb_descriptors.c | 30 +++++++--------------------- bdk/usb/usbd.c | 36 ++++++++++++++++++---------------- bdk/usb/xusbd.c | 36 ++++++++++++++++++---------------- 4 files changed, 47 insertions(+), 59 deletions(-) diff --git a/bdk/usb/usb_descriptor_types.h b/bdk/usb/usb_descriptor_types.h index cb58abc2..90dadb8b 100644 --- a/bdk/usb/usb_descriptor_types.h +++ b/bdk/usb/usb_descriptor_types.h @@ -1,7 +1,7 @@ /* * USB driver for Tegra X1 * - * Copyright (c) 2019-2020 CTCaer + * Copyright (c) 2019-2025 CTCaer * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -151,7 +151,7 @@ typedef struct _usb_cfg_hid_descr_t usb_cfg_descr_t config; usb_inter_descr_t interface; usb_hid_descr_t hid; - usb_ep_descr_t endpoint[2]; + usb_ep_descr_t endpoint[1]; } __attribute__((packed)) usb_cfg_hid_descr_t; typedef struct _usb_dev_bot_t diff --git a/bdk/usb/usb_descriptors.c b/bdk/usb/usb_descriptors.c index 389a70d5..04346d9a 100644 --- a/bdk/usb/usb_descriptors.c +++ b/bdk/usb/usb_descriptors.c @@ -1,7 +1,7 @@ /* * USB driver for Tegra X1 * - * Copyright (c) 2019-2020 CTCaer + * Copyright (c) 2019-2025 CTCaer * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -409,10 +409,10 @@ static usb_cfg_hid_descr_t usb_configuration_descriptor_hid_jc = .interface.bDescriptorType = USB_DESCRIPTOR_INTERFACE, .interface.bInterfaceNumber = 0, .interface.bAlternateSetting = 0, - .interface.bNumEndpoints = 2, + .interface.bNumEndpoints = 1, .interface.bInterfaceClass = 0x03, // Human Interface Device Class. - .interface.bInterfaceSubClass = 0x00, // SCSI Transparent Command Set. - .interface.bInterfaceProtocol = 0x00, // Bulk-Only Transport. + .interface.bInterfaceSubClass = 0x00, // No Subclass. + .interface.bInterfaceProtocol = 0x00, // None. .interface.iInterface = 0x00, .hid.bLength = 9, @@ -430,14 +430,6 @@ static usb_cfg_hid_descr_t usb_configuration_descriptor_hid_jc = .endpoint[0].bmAttributes = USB_EP_TYPE_INTR, .endpoint[0].wMaxPacketSize = 0x200, .endpoint[0].bInterval = 4, // 8ms on HS. - - /* Endpoint descriptor structure EP1 OUT */ - .endpoint[1].bLength = 7, - .endpoint[1].bDescriptorType = USB_DESCRIPTOR_ENDPOINT, - .endpoint[1].bEndpointAddress = 0x01, // USB_EP_ADDR_BULK_OUT. - .endpoint[1].bmAttributes = USB_EP_TYPE_INTR, - .endpoint[1].wMaxPacketSize = 0x200, - .endpoint[1].bInterval = 4 // 8ms on HS. }; static u8 usb_vendor_string_descriptor_hid[22] = @@ -478,10 +470,10 @@ static usb_cfg_hid_descr_t usb_configuration_descriptor_hid_touch = .interface.bDescriptorType = USB_DESCRIPTOR_INTERFACE, .interface.bInterfaceNumber = 0, .interface.bAlternateSetting = 0, - .interface.bNumEndpoints = 2, + .interface.bNumEndpoints = 1, .interface.bInterfaceClass = 0x03, // Human Interface Device Class. - .interface.bInterfaceSubClass = 0x00, // SCSI Transparent Command Set. - .interface.bInterfaceProtocol = 0x00, // Bulk-Only Transport. + .interface.bInterfaceSubClass = 0x00, // No Subclass. + .interface.bInterfaceProtocol = 0x00, // None. .interface.iInterface = 0x00, .hid.bLength = 9, @@ -499,14 +491,6 @@ static usb_cfg_hid_descr_t usb_configuration_descriptor_hid_touch = .endpoint[0].bmAttributes = USB_EP_TYPE_INTR, .endpoint[0].wMaxPacketSize = 0x200, .endpoint[0].bInterval = 3, // 4ms on HS. - - /* Endpoint descriptor structure EP1 OUT */ - .endpoint[1].bLength = 7, - .endpoint[1].bDescriptorType = USB_DESCRIPTOR_ENDPOINT, - .endpoint[1].bEndpointAddress = 0x01, // USB_EP_ADDR_BULK_OUT. - .endpoint[1].bmAttributes = USB_EP_TYPE_INTR, - .endpoint[1].wMaxPacketSize = 0x200, - .endpoint[1].bInterval = 3 // 4ms on HS. }; usb_desc_t usb_gadget_ums_descriptors = diff --git a/bdk/usb/usbd.c b/bdk/usb/usbd.c index 2a7fe97d..f422587e 100644 --- a/bdk/usb/usbd.c +++ b/bdk/usb/usbd.c @@ -1,7 +1,7 @@ /* * Enhanced USB Device (EDCI) driver for Tegra X1 * - * Copyright (c) 2019-2024 CTCaer + * Copyright (c) 2019-2025 CTCaer * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -941,13 +941,13 @@ static void _usbd_handle_get_descriptor(bool *transmit_data, void **descriptor, { if (usbd_otg->port_speed == USB_HIGH_SPEED) // High speed. 512 bytes. { - usbd_otg->desc->cfg->endpoint[0].wMaxPacketSize = 0x200; - usbd_otg->desc->cfg->endpoint[1].wMaxPacketSize = 0x200; + for (u32 i = 0; i < usbd_otg->desc->cfg->interface.bNumEndpoints; i++) + usbd_otg->desc->cfg->endpoint[i].wMaxPacketSize = 0x200; // No burst. } else // Full speed. 64 bytes. { - usbd_otg->desc->cfg->endpoint[0].wMaxPacketSize = 0x40; - usbd_otg->desc->cfg->endpoint[1].wMaxPacketSize = 0x40; + for (u32 i = 0; i < usbd_otg->desc->cfg->interface.bNumEndpoints; i++) + usbd_otg->desc->cfg->endpoint[i].wMaxPacketSize = 0x40; } } else @@ -955,17 +955,19 @@ static void _usbd_handle_get_descriptor(bool *transmit_data, void **descriptor, usb_cfg_hid_descr_t *tmp = (usb_cfg_hid_descr_t *)usbd_otg->desc->cfg; if (usbd_otg->port_speed == USB_HIGH_SPEED) // High speed. 512 bytes. { - tmp->endpoint[0].wMaxPacketSize = 0x200; - tmp->endpoint[1].wMaxPacketSize = 0x200; - tmp->endpoint[0].bInterval = usbd_otg->gadget == USB_GADGET_HID_GAMEPAD ? 4 : 3; // 8ms : 4ms. - tmp->endpoint[1].bInterval = usbd_otg->gadget == USB_GADGET_HID_GAMEPAD ? 4 : 3; // 8ms : 4ms. + for (u32 i = 0; i < tmp->interface.bNumEndpoints; i++) + { + tmp->endpoint[i].wMaxPacketSize = 0x200; + tmp->endpoint[i].bInterval = usbd_otg->gadget == USB_GADGET_HID_GAMEPAD ? 4 : 3; // 8ms : 4ms. + } } else // Full speed. 64 bytes. { - tmp->endpoint[0].wMaxPacketSize = 0x40; - tmp->endpoint[1].wMaxPacketSize = 0x40; - tmp->endpoint[0].bInterval = usbd_otg->gadget == USB_GADGET_HID_GAMEPAD ? 8 : 4; // 8ms : 4ms. - tmp->endpoint[1].bInterval = usbd_otg->gadget == USB_GADGET_HID_GAMEPAD ? 8 : 4; // 8ms : 4ms. + for (u32 i = 0; i < tmp->interface.bNumEndpoints; i++) + { + tmp->endpoint[i].wMaxPacketSize = 0x40; + tmp->endpoint[i].bInterval = usbd_otg->gadget == USB_GADGET_HID_GAMEPAD ? 8 : 4; // 8ms : 4ms. + } } } *descriptor = usbd_otg->desc->cfg; @@ -1011,13 +1013,13 @@ static void _usbd_handle_get_descriptor(bool *transmit_data, void **descriptor, goto exit; if (usbd_otg->port_speed == USB_HIGH_SPEED) { - usbd_otg->desc->cfg_other->endpoint[0].wMaxPacketSize = 0x40; - usbd_otg->desc->cfg_other->endpoint[1].wMaxPacketSize = 0x40; + for (u32 i = 0; i < usbd_otg->desc->cfg_other->interface.bNumEndpoints; i++) + usbd_otg->desc->cfg_other->endpoint[i].wMaxPacketSize = 0x40; } else { - usbd_otg->desc->cfg_other->endpoint[0].wMaxPacketSize = 0x200; - usbd_otg->desc->cfg_other->endpoint[1].wMaxPacketSize = 0x200; + for (u32 i = 0; i < usbd_otg->desc->cfg_other->interface.bNumEndpoints; i++) + usbd_otg->desc->cfg_other->endpoint[i].wMaxPacketSize = 0x200; } if ((usbd_otg->charger_detect & 1) && (usbd_otg->charger_detect & 2)) usbd_otg->desc->cfg_other->config.bMaxPower = 500 / 2; diff --git a/bdk/usb/xusbd.c b/bdk/usb/xusbd.c index 87df551f..385bc0d0 100644 --- a/bdk/usb/xusbd.c +++ b/bdk/usb/xusbd.c @@ -1,7 +1,7 @@ /* * eXtensible USB Device driver (XDCI) for Tegra X1 * - * Copyright (c) 2020-2024 CTCaer + * Copyright (c) 2020-2025 CTCaer * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -1522,13 +1522,13 @@ static int _xusb_handle_get_descriptor(const usb_ctrl_setup_t *ctrl_setup) { if (usbd_xotg->port_speed == XUSB_HIGH_SPEED) // High speed. 512 bytes. { - usbd_xotg->desc->cfg->endpoint[0].wMaxPacketSize = 0x200; // No burst. - usbd_xotg->desc->cfg->endpoint[1].wMaxPacketSize = 0x200; // No burst. + for (u32 i = 0; i < usbd_xotg->desc->cfg->interface.bNumEndpoints; i++) + usbd_xotg->desc->cfg->endpoint[i].wMaxPacketSize = 0x200; // No burst. } else // Full speed. 64 bytes. { - usbd_xotg->desc->cfg->endpoint[0].wMaxPacketSize = 0x40; - usbd_xotg->desc->cfg->endpoint[1].wMaxPacketSize = 0x40; + for (u32 i = 0; i < usbd_xotg->desc->cfg->interface.bNumEndpoints; i++) + usbd_xotg->desc->cfg->endpoint[i].wMaxPacketSize = 0x40; } } else @@ -1536,17 +1536,19 @@ static int _xusb_handle_get_descriptor(const usb_ctrl_setup_t *ctrl_setup) usb_cfg_hid_descr_t *tmp = (usb_cfg_hid_descr_t *)usbd_xotg->desc->cfg; if (usbd_xotg->port_speed == XUSB_HIGH_SPEED) // High speed. 512 bytes. { - tmp->endpoint[0].wMaxPacketSize = 0x200; - tmp->endpoint[1].wMaxPacketSize = 0x200; - tmp->endpoint[0].bInterval = usbd_xotg->gadget == USB_GADGET_HID_GAMEPAD ? 4 : 3; // 8ms : 4ms. - tmp->endpoint[1].bInterval = usbd_xotg->gadget == USB_GADGET_HID_GAMEPAD ? 4 : 3; // 8ms : 4ms. + for (u32 i = 0; i < tmp->interface.bNumEndpoints; i++) + { + tmp->endpoint[i].wMaxPacketSize = 0x200; + tmp->endpoint[i].bInterval = usbd_xotg->gadget == USB_GADGET_HID_GAMEPAD ? 4 : 3; // 8ms : 4ms. + } } else // Full speed. 64 bytes. { - tmp->endpoint[0].wMaxPacketSize = 0x40; - tmp->endpoint[1].wMaxPacketSize = 0x40; - tmp->endpoint[0].bInterval = usbd_xotg->gadget == USB_GADGET_HID_GAMEPAD ? 8 : 4; // 8ms : 4ms. - tmp->endpoint[1].bInterval = usbd_xotg->gadget == USB_GADGET_HID_GAMEPAD ? 8 : 4; // 8ms : 4ms. + for (u32 i = 0; i < tmp->interface.bNumEndpoints; i++) + { + tmp->endpoint[i].wMaxPacketSize = 0x40; + tmp->endpoint[i].bInterval = usbd_xotg->gadget == USB_GADGET_HID_GAMEPAD ? 8 : 4; // 8ms : 4ms. + } } } descriptor = usbd_xotg->desc->cfg; @@ -1595,13 +1597,13 @@ static int _xusb_handle_get_descriptor(const usb_ctrl_setup_t *ctrl_setup) } if (usbd_xotg->port_speed == XUSB_HIGH_SPEED) { - usbd_xotg->desc->cfg_other->endpoint[0].wMaxPacketSize = 0x40; - usbd_xotg->desc->cfg_other->endpoint[1].wMaxPacketSize = 0x40; + for (u32 i = 0; i < usbd_xotg->desc->cfg_other->interface.bNumEndpoints; i++) + usbd_xotg->desc->cfg_other->endpoint[i].wMaxPacketSize = 0x40; } else { - usbd_xotg->desc->cfg_other->endpoint[0].wMaxPacketSize = 0x200; - usbd_xotg->desc->cfg_other->endpoint[1].wMaxPacketSize = 0x200; + for (u32 i = 0; i < usbd_xotg->desc->cfg_other->interface.bNumEndpoints; i++) + usbd_xotg->desc->cfg_other->endpoint[i].wMaxPacketSize = 0x200; } descriptor = usbd_xotg->desc->cfg_other; size = usbd_xotg->desc->cfg_other->config.wTotalLength;