diff --git a/include/usb/usb_common.h b/include/usb/usb_common.h index 418b09cfa62..c3c0058e2ef 100644 --- a/include/usb/usb_common.h +++ b/include/usb/usb_common.h @@ -86,11 +86,6 @@ #define BCDDEVICE_RELNUM (BCD(KERNEL_VERSION_MAJOR) << 8 | \ BCD(KERNEL_VERSION_MINOR)) -/* 100mA max power, per 2mA units */ -/* USB 1.1 spec indicates 100mA(max) per unit load, up to 5 loads */ -#define MAX_LOW_POWER 0x32 -#define MAX_HIGH_POWER 0xFA - /* Highest value of Frame Number in SOF packets. */ #define USB_SOF_MAX 2047 @@ -100,10 +95,13 @@ * D5:Remote Wakeup -> 0, * D4...0:Reserved -> 0 */ -#define USB_CONFIGURATION_ATTRIBUTES_REMOTE_WAKEUP 0x20 -#define USB_CONFIGURATION_ATTRIBUTES 0xC0 \ - | (COND_CODE_1(CONFIG_USB_DEVICE_REMOTE_WAKEUP, \ - (USB_CONFIGURATION_ATTRIBUTES_REMOTE_WAKEUP), (0))) +#define USB_CONFIGURATION_ATTRIBUTES_REMOTE_WAKEUP BIT(5) +#define USB_CONFIGURATION_ATTRIBUTES_SELF_POWERED BIT(6) +#define USB_CONFIGURATION_ATTRIBUTES BIT(7) \ + | ((COND_CODE_1(CONFIG_USB_SELF_POWERED, \ + (USB_CONFIGURATION_ATTRIBUTES_SELF_POWERED), (0))) \ + | (COND_CODE_1(CONFIG_USB_DEVICE_REMOTE_WAKEUP, \ + (USB_CONFIGURATION_ATTRIBUTES_REMOTE_WAKEUP), (0)))) /* Classes */ #define COMMUNICATION_DEVICE_CLASS 0x02 diff --git a/subsys/usb/Kconfig b/subsys/usb/Kconfig index 6994d9f33d7..4583d64ffdd 100644 --- a/subsys/usb/Kconfig +++ b/subsys/usb/Kconfig @@ -90,6 +90,21 @@ config USB_DEVICE_BOS config USB_DEVICE_OS_DESC bool "Enable MS OS Descriptors support" +config USB_SELF_POWERED + bool "Set Self-powered characteristic" + default y + help + Set Self-powered characteristic in bmAttributes to indicate + self powered USB device. + +config USB_MAX_POWER + int "Set bMaxPower value" + default 50 + range 0 250 + help + Set bMaxPower value in the Standard Configuration Descriptor, + the result is 2mA times the value provided. + menuconfig USB_VBUS_GPIO bool "Control VBUS via GPIO pin" depends on GPIO diff --git a/subsys/usb/class/usb_dfu.c b/subsys/usb/class/usb_dfu.c index bc3169f0e0f..750c5c936f8 100644 --- a/subsys/usb/class/usb_dfu.c +++ b/subsys/usb/class/usb_dfu.c @@ -156,7 +156,7 @@ struct dev_dfu_mode_descriptor dfu_mode_desc = { .bConfigurationValue = 1, .iConfiguration = 0, .bmAttributes = USB_CONFIGURATION_ATTRIBUTES, - .bMaxPower = MAX_LOW_POWER, + .bMaxPower = CONFIG_USB_MAX_POWER, }, .sec_dfu_cfg = { /* Interface descriptor */ diff --git a/subsys/usb/usb_descriptor.c b/subsys/usb/usb_descriptor.c index 08b757fd737..6e25ba7fd45 100644 --- a/subsys/usb/usb_descriptor.c +++ b/subsys/usb/usb_descriptor.c @@ -89,7 +89,7 @@ USBD_DEVICE_DESCR_DEFINE(primary) struct common_descriptor common_desc = { .bConfigurationValue = 1, .iConfiguration = 0, .bmAttributes = USB_CONFIGURATION_ATTRIBUTES, - .bMaxPower = MAX_LOW_POWER, + .bMaxPower = CONFIG_USB_MAX_POWER, }, };