From: Jean-Jacques Hiblot Date: Thu, 24 Oct 2019 17:44:00 +0200 Subject: [U-Boot] [PATCH] usb: composite: add BOS descriptor support to composite framework In-Reply-To: References: Message-ID: <99e0ff64-267e-aa74-d87f-4bb752d801a2@ti.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable To: u-boot@lists.denx.de + Vignesh and Roger On 24/10/2019 13:22, Michal Simek wrote: > po 14. 10. 2019 v 14:52 odes=C3=ADlatel Michal Simek > napsal: >> From: T Karthik Reddy >> >> To add usb-3.0 support to peripheral device add BOS & SS capability >> descriptors to gadget composite framework. >> >> Signed-off-by: T Karthik Reddy >> Signed-off-by: Siva Durga Prasad Paladugu >> Signed-off-by: Michal Simek >> --- >> >> drivers/usb/gadget/composite.c | 61 ++++++++++++++++++++++++++++++---- >> include/linux/usb/ch9.h | 3 ++ >> include/linux/usb/gadget.h | 9 +++++ >> 3 files changed, 67 insertions(+), 6 deletions(-) >> >> diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composi= te.c >> index c7e762374752..618a7d5016ee 100644 >> --- a/drivers/usb/gadget/composite.c >> +++ b/drivers/usb/gadget/composite.c >> @@ -688,6 +688,57 @@ static void composite_setup_complete(struct usb_ep = *ep, struct usb_request *req) >> req->status, req->actual, req->length); >> } >> >> +static int bos_desc(struct usb_composite_dev *cdev) >> +{ >> + struct usb_ext_cap_descriptor *usb_ext; >> + struct usb_bos_descriptor *bos =3D cdev->req->buf; >> + >> + bos->bLength =3D USB_DT_BOS_SIZE; >> + bos->bDescriptorType =3D USB_DT_BOS; >> + >> + bos->wTotalLength =3D cpu_to_le16(USB_DT_BOS_SIZE); >> + bos->bNumDeviceCaps =3D 0; >> + >> + /* >> + * A SuperSpeed device shall include the USB2.0 extension descri= ptor >> + * and shall support LPM when operating in USB2.0 HS mode. >> + */ >> + usb_ext =3D cdev->req->buf + le16_to_cpu(bos->wTotalLength); >> + bos->bNumDeviceCaps++; >> + le16_add_cpu(&bos->wTotalLength, USB_DT_USB_EXT_CAP_SIZE); >> + usb_ext->bLength =3D USB_DT_USB_EXT_CAP_SIZE; >> + usb_ext->bDescriptorType =3D USB_DT_DEVICE_CAPABILITY; >> + usb_ext->bDevCapabilityType =3D USB_CAP_TYPE_EXT; >> + usb_ext->bmAttributes =3D >> + cpu_to_le32(USB_LPM_SUPPORT | USB_BESL_SUPPORT); >> + >> + /* >> + * The Superspeed USB Capability descriptor shall be implemented >> + * by all SuperSpeed devices. >> + */ >> + if (gadget_is_superspeed(cdev->gadget)) { >> + struct usb_ss_cap_descriptor *ss_cap; >> + >> + ss_cap =3D cdev->req->buf + le16_to_cpu(bos->wTotalLengt= h); >> + bos->bNumDeviceCaps++; >> + le16_add_cpu(&bos->wTotalLength, USB_DT_USB_SS_CAP_SIZE); >> + ss_cap->bLength =3D USB_DT_USB_SS_CAP_SIZE; >> + ss_cap->bDescriptorType =3D USB_DT_DEVICE_CAPABILITY; >> + ss_cap->bDevCapabilityType =3D USB_SS_CAP_TYPE; >> + ss_cap->bmAttributes =3D 0; /* LTM is not supported yet = */ >> + ss_cap->wSpeedSupported =3D >> + cpu_to_le16(USB_LOW_SPEED_OPERATION | >> + USB_FULL_SPEED_OPERATION | >> + USB_HIGH_SPEED_OPERATION | >> + USB_5GBPS_OPERATION); >> + ss_cap->bFunctionalitySupport =3D USB_LOW_SPEED_OPERATIO= N; >> + ss_cap->bU1devExitLat =3D USB_DEFAULT_U1_DEV_EXIT_LAT; >> + ss_cap->bU2DevExitLat =3D >> + cpu_to_le16(USB_DEFAULT_U2_DEV_EXIT_LAT); >> + } >> + return le16_to_cpu(bos->wTotalLength); >> +} >> + >> /* >> * The setup() callback implements all the ep0 functionality that's >> * not handled lower down, in hardware or the hardware driver(like >> @@ -776,12 +827,10 @@ composite_setup(struct usb_gadget *gadget, const s= truct usb_ctrlrequest *ctrl) >> value =3D min(w_length, (u16) value); >> break; >> case USB_DT_BOS: >> - /* >> - * The USB compliance test (USB 2.0 Command Veri= fier) >> - * issues this request. We should not run into t= he >> - * default path here. But return for now until >> - * the superspeed support is added. >> - */ >> + if (gadget_is_superspeed(cdev->gadget)) >> + value =3D bos_desc(cdev); >> + if (value >=3D 0) >> + value =3D min(w_length, (u16)value); >> break; >> default: >> goto unknown; >> diff --git a/include/linux/usb/ch9.h b/include/linux/usb/ch9.h >> index 264c9712a33a..989a5fcbd966 100644 >> --- a/include/linux/usb/ch9.h >> +++ b/include/linux/usb/ch9.h >> @@ -878,6 +878,9 @@ struct usb_ss_cap_descriptor { /* Link = Power Management */ >> __le16 bU2DevExitLat; >> } __attribute__((packed)); >> >> +#define USB_DEFAULT_U1_DEV_EXIT_LAT 0x01 /* Less then 1 microsec = */ >> +#define USB_DEFAULT_U2_DEV_EXIT_LAT 0x01F4 /* Less then 500 microse= c */ >> + >> #define USB_DT_USB_SS_CAP_SIZE 10 >> >> /* >> diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h >> index 497798a32a87..58bfaddd036a 100644 >> --- a/include/linux/usb/gadget.h >> +++ b/include/linux/usb/gadget.h >> @@ -566,6 +566,15 @@ static inline int gadget_is_otg(struct usb_gadget *= g) >> #endif >> } >> >> +/** >> + * gadget_is_superspeed() - return true if the hardware handles supersp= eed >> + * @g: controller that might support superspeed >> + */ >> +static inline int gadget_is_superspeed(struct usb_gadget *g) >> +{ >> + return g->max_speed >=3D USB_SPEED_SUPER; >> +} >> + >> /** >> * usb_gadget_frame_number - returns the current frame number >> * @gadget: controller that reports the frame number >> -- >> 2.17.1 >> > Any comment on this one? > M > >