Skip to content

Commit cca3854

Browse files
Thinh NguyenFelipe Balbi
authored andcommitted
usb: gadget: composite: Set recommended BESL values
Set the recommended BESL deep and baseline values based on the gadget's configuration parameters to the extended BOS descriptor. This feature helps to optimize power savings by maximizing the opportunity for longer L1 residency time. Signed-off-by: Thinh Nguyen <[email protected]> Signed-off-by: Felipe Balbi <[email protected]>
1 parent 54fb5ba commit cca3854

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

drivers/usb/gadget/composite.c

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -612,13 +612,37 @@ static int bos_desc(struct usb_composite_dev *cdev)
612612
struct usb_ext_cap_descriptor *usb_ext;
613613
struct usb_dcd_config_params dcd_config_params;
614614
struct usb_bos_descriptor *bos = cdev->req->buf;
615+
unsigned int besl = 0;
615616

616617
bos->bLength = USB_DT_BOS_SIZE;
617618
bos->bDescriptorType = USB_DT_BOS;
618619

619620
bos->wTotalLength = cpu_to_le16(USB_DT_BOS_SIZE);
620621
bos->bNumDeviceCaps = 0;
621622

623+
/* Get Controller configuration */
624+
if (cdev->gadget->ops->get_config_params) {
625+
cdev->gadget->ops->get_config_params(cdev->gadget,
626+
&dcd_config_params);
627+
} else {
628+
dcd_config_params.besl_baseline =
629+
USB_DEFAULT_BESL_UNSPECIFIED;
630+
dcd_config_params.besl_deep =
631+
USB_DEFAULT_BESL_UNSPECIFIED;
632+
dcd_config_params.bU1devExitLat =
633+
USB_DEFAULT_U1_DEV_EXIT_LAT;
634+
dcd_config_params.bU2DevExitLat =
635+
cpu_to_le16(USB_DEFAULT_U2_DEV_EXIT_LAT);
636+
}
637+
638+
if (dcd_config_params.besl_baseline != USB_DEFAULT_BESL_UNSPECIFIED)
639+
besl = USB_BESL_BASELINE_VALID |
640+
USB_SET_BESL_BASELINE(dcd_config_params.besl_baseline);
641+
642+
if (dcd_config_params.besl_deep != USB_DEFAULT_BESL_UNSPECIFIED)
643+
besl |= USB_BESL_DEEP_VALID |
644+
USB_SET_BESL_DEEP(dcd_config_params.besl_deep);
645+
622646
/*
623647
* A SuperSpeed device shall include the USB2.0 extension descriptor
624648
* and shall support LPM when operating in USB2.0 HS mode.
@@ -629,7 +653,8 @@ static int bos_desc(struct usb_composite_dev *cdev)
629653
usb_ext->bLength = USB_DT_USB_EXT_CAP_SIZE;
630654
usb_ext->bDescriptorType = USB_DT_DEVICE_CAPABILITY;
631655
usb_ext->bDevCapabilityType = USB_CAP_TYPE_EXT;
632-
usb_ext->bmAttributes = cpu_to_le32(USB_LPM_SUPPORT | USB_BESL_SUPPORT);
656+
usb_ext->bmAttributes = cpu_to_le32(USB_LPM_SUPPORT |
657+
USB_BESL_SUPPORT | besl);
633658

634659
/*
635660
* The Superspeed USB Capability descriptor shall be implemented by all
@@ -650,17 +675,6 @@ static int bos_desc(struct usb_composite_dev *cdev)
650675
USB_HIGH_SPEED_OPERATION |
651676
USB_5GBPS_OPERATION);
652677
ss_cap->bFunctionalitySupport = USB_LOW_SPEED_OPERATION;
653-
654-
/* Get Controller configuration */
655-
if (cdev->gadget->ops->get_config_params) {
656-
cdev->gadget->ops->get_config_params(cdev->gadget,
657-
&dcd_config_params);
658-
} else {
659-
dcd_config_params.bU1devExitLat =
660-
USB_DEFAULT_U1_DEV_EXIT_LAT;
661-
dcd_config_params.bU2DevExitLat =
662-
cpu_to_le16(USB_DEFAULT_U2_DEV_EXIT_LAT);
663-
}
664678
ss_cap->bU1devExitLat = dcd_config_params.bU1devExitLat;
665679
ss_cap->bU2DevExitLat = dcd_config_params.bU2DevExitLat;
666680
}

include/uapi/linux/usb/ch9.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -894,6 +894,8 @@ struct usb_ext_cap_descriptor { /* Link Power Management */
894894
#define USB_BESL_SUPPORT (1 << 2) /* supports BESL */
895895
#define USB_BESL_BASELINE_VALID (1 << 3) /* Baseline BESL valid*/
896896
#define USB_BESL_DEEP_VALID (1 << 4) /* Deep BESL valid */
897+
#define USB_SET_BESL_BASELINE(p) (((p) & 0xf) << 8)
898+
#define USB_SET_BESL_DEEP(p) (((p) & 0xf) << 12)
897899
#define USB_GET_BESL_BASELINE(p) (((p) & (0xf << 8)) >> 8)
898900
#define USB_GET_BESL_DEEP(p) (((p) & (0xf << 12)) >> 12)
899901
} __attribute__((packed));

0 commit comments

Comments
 (0)