From aa67c98a4aa3f870258f7c1e4f8a52890ba39296 Mon Sep 17 00:00:00 2001 From: Koen Zandberg Date: Fri, 31 Mar 2023 14:27:32 +0200 Subject: [PATCH] synopsys_dwc2: implement USBOPT_ENUMERATED_SPEED --- .../usbdev_synopsys_dwc2.c | 35 +++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/drivers/usbdev_synopsys_dwc2/usbdev_synopsys_dwc2.c b/drivers/usbdev_synopsys_dwc2/usbdev_synopsys_dwc2.c index 92a08d22db..8bfc4338e3 100644 --- a/drivers/usbdev_synopsys_dwc2/usbdev_synopsys_dwc2.c +++ b/drivers/usbdev_synopsys_dwc2/usbdev_synopsys_dwc2.c @@ -1021,10 +1021,36 @@ static void _usbdev_init(usbdev_t *dev) #endif } +static usb_speed_t _get_max_speed(const usbdev_t *dev) +{ + dwc2_usb_otg_fshs_t *usbdev = (dwc2_usb_otg_fshs_t *)dev; + const dwc2_usb_otg_fshs_config_t *conf = usbdev->config; + if (IS_USED(DWC2_USB_OTG_HS_ENABLED) && (conf->type == DWC2_USB_OTG_HS)) { + return USB_SPEED_HIGH; + } + return USB_SPEED_FULL; +} + +static usb_speed_t _get_enumeration_speed(const usbdev_t *dev) +{ + dwc2_usb_otg_fshs_t *usbdev = (dwc2_usb_otg_fshs_t *)dev; + const dwc2_usb_otg_fshs_config_t *conf = usbdev->config; + unsigned speed = (_device_regs(conf)->DSTS & USB_OTG_DSTS_ENUMSPD_Msk) >> + USB_OTG_DSTS_ENUMSPD_Pos; + switch (speed) { + case 0x00: + return USB_SPEED_HIGH; + case 0x03: + return USB_SPEED_FULL; + default: + assert(false); /* reserved values by peripheral */ + } + return USB_SPEED_FULL; /* Should not be reached */ +} + static int _usbdev_get(usbdev_t *dev, usbopt_t opt, void *value, size_t max_len) { - (void)dev; (void)max_len; int res = -ENOTSUP; switch (opt) { @@ -1035,7 +1061,12 @@ static int _usbdev_get(usbdev_t *dev, usbopt_t opt, break; case USBOPT_MAX_SPEED: assert(max_len == sizeof(usb_speed_t)); - *(usb_speed_t *)value = USB_SPEED_FULL; + *(usb_speed_t *)value = _get_max_speed(dev); + res = sizeof(usb_speed_t); + break; + case USBOPT_ENUMERATED_SPEED: + assert(max_len == sizeof(usb_speed_t)); + *(usb_speed_t *)value = _get_enumeration_speed(dev); res = sizeof(usb_speed_t); break; default: