usb: f_uac1: adds support for SS and SSP
authorPerr Zhang <perr@usb7.net>
Wed, 13 Dec 2023 11:21:06 +0000 (19:21 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 15 Dec 2023 12:54:37 +0000 (13:54 +0100)
Patch adds support of SS and SSP speed.
Tested with rockchip rk3399 dwc3

Signed-off-by: Perr Zhang <perr@usb7.net>
Link: https://lore.kernel.org/r/20231213112106.605260-1-strongbox8@zoho.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/gadget/function/f_uac1.c

index 6f0e1d803dc244d820905870dd6288bdbbd77832..78634ea7863a7d1919427d37365aef63f021e4a7 100644 (file)
@@ -292,6 +292,77 @@ static struct usb_descriptor_header *f_audio_desc[] = {
        NULL,
 };
 
+/* Standard ISO OUT Endpoint Descriptor */
+static struct usb_endpoint_descriptor ss_as_out_ep_desc  = {
+       .bLength =              USB_DT_ENDPOINT_AUDIO_SIZE,
+       .bDescriptorType =      USB_DT_ENDPOINT,
+       .bEndpointAddress =     USB_DIR_OUT,
+       .bmAttributes =         USB_ENDPOINT_SYNC_ADAPTIVE
+                               | USB_ENDPOINT_XFER_ISOC,
+       .wMaxPacketSize =       cpu_to_le16(UAC1_OUT_EP_MAX_PACKET_SIZE),
+       .bInterval =            4,
+};
+
+static struct usb_ss_ep_comp_descriptor ss_as_out_ep_desc_comp = {
+       .bLength                = sizeof(ss_as_out_ep_desc_comp),
+       .bDescriptorType        = USB_DT_SS_ENDPOINT_COMP,
+       .bMaxBurst              = 0,
+       .bmAttributes           = 0,
+       /* wBytesPerInterval = DYNAMIC */
+};
+
+/* Standard ISO OUT Endpoint Descriptor */
+static struct usb_endpoint_descriptor ss_as_in_ep_desc  = {
+       .bLength =              USB_DT_ENDPOINT_AUDIO_SIZE,
+       .bDescriptorType =      USB_DT_ENDPOINT,
+       .bEndpointAddress =     USB_DIR_IN,
+       .bmAttributes =         USB_ENDPOINT_SYNC_ASYNC
+                               | USB_ENDPOINT_XFER_ISOC,
+       .wMaxPacketSize =       cpu_to_le16(UAC1_OUT_EP_MAX_PACKET_SIZE),
+       .bInterval =            4,
+};
+
+static struct usb_ss_ep_comp_descriptor ss_as_in_ep_desc_comp = {
+       .bLength                = sizeof(ss_as_in_ep_desc_comp),
+       .bDescriptorType        = USB_DT_SS_ENDPOINT_COMP,
+       .bMaxBurst              = 0,
+       .bmAttributes           = 0,
+       /* wBytesPerInterval = DYNAMIC */
+};
+
+static struct usb_descriptor_header *f_audio_ss_desc[] = {
+       (struct usb_descriptor_header *)&ac_interface_desc,
+       (struct usb_descriptor_header *)&ac_header_desc,
+
+       (struct usb_descriptor_header *)&usb_out_it_desc,
+       (struct usb_descriptor_header *)&io_out_ot_desc,
+       (struct usb_descriptor_header *)&io_in_it_desc,
+       (struct usb_descriptor_header *)&usb_in_ot_desc,
+
+       (struct usb_descriptor_header *)&as_out_interface_alt_0_desc,
+       (struct usb_descriptor_header *)&as_out_interface_alt_1_desc,
+       (struct usb_descriptor_header *)&as_out_header_desc,
+
+       (struct usb_descriptor_header *)&as_out_type_i_desc,
+
+       //(struct usb_descriptor_header *)&as_out_ep_desc,
+       (struct usb_descriptor_header *)&ss_as_out_ep_desc,
+       (struct usb_descriptor_header *)&ss_as_out_ep_desc_comp,
+       (struct usb_descriptor_header *)&as_iso_out_desc,
+
+       (struct usb_descriptor_header *)&as_in_interface_alt_0_desc,
+       (struct usb_descriptor_header *)&as_in_interface_alt_1_desc,
+       (struct usb_descriptor_header *)&as_in_header_desc,
+
+       (struct usb_descriptor_header *)&as_in_type_i_desc,
+
+       //(struct usb_descriptor_header *)&as_in_ep_desc,
+       (struct usb_descriptor_header *)&ss_as_in_ep_desc,
+       (struct usb_descriptor_header *)&ss_as_in_ep_desc_comp,
+       (struct usb_descriptor_header *)&as_iso_in_desc,
+       NULL,
+};
+
 enum {
        STR_AC_IF,
        STR_USB_OUT_IT,
@@ -1352,6 +1423,7 @@ static int f_audio_bind(struct usb_configuration *c, struct usb_function *f)
                ep = usb_ep_autoconfig(cdev->gadget, &as_out_ep_desc);
                if (!ep)
                        goto err_free_fu;
+               ss_as_out_ep_desc.bEndpointAddress = as_out_ep_desc.bEndpointAddress;
                audio->out_ep = ep;
                audio->out_ep->desc = &as_out_ep_desc;
        }
@@ -1360,6 +1432,7 @@ static int f_audio_bind(struct usb_configuration *c, struct usb_function *f)
                ep = usb_ep_autoconfig(cdev->gadget, &as_in_ep_desc);
                if (!ep)
                        goto err_free_fu;
+               ss_as_in_ep_desc.bEndpointAddress = as_in_ep_desc.bEndpointAddress;
                audio->in_ep = ep;
                audio->in_ep->desc = &as_in_ep_desc;
        }
@@ -1367,8 +1440,8 @@ static int f_audio_bind(struct usb_configuration *c, struct usb_function *f)
        setup_descriptor(audio_opts);
 
        /* copy descriptors, and track endpoint copies */
-       status = usb_assign_descriptors(f, f_audio_desc, f_audio_desc, NULL,
-                                       NULL);
+       status = usb_assign_descriptors(f, f_audio_desc, f_audio_desc, f_audio_ss_desc,
+                                       f_audio_ss_desc);
        if (status)
                goto err_free_fu;