Skip to content

Commit

Permalink
usb: gadget: composite: Add function to get descriptors
Browse files Browse the repository at this point in the history
There are a couple places in the code that get the function descriptors
based on the speed. Move this lookup into a function call and add
support to handle the SuperSpeedPlus descriptors as well.

Signed-off-by: John Youn <[email protected]>
Signed-off-by: Felipe Balbi <[email protected]>
  • Loading branch information
jysnps authored and felipebalbi committed Mar 4, 2016
1 parent a4afd01 commit f3bdbe3
Showing 1 changed file with 32 additions and 21 deletions.
53 changes: 32 additions & 21 deletions drivers/usb/gadget/composite.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,36 @@ static struct usb_gadget_strings **get_containers_gs(
return (struct usb_gadget_strings **)uc->stash;
}

/**
* function_descriptors() - get function descriptors for speed
* @f: the function
* @speed: the speed
*
* Returns the descriptors or NULL if not set.
*/
static struct usb_descriptor_header **
function_descriptors(struct usb_function *f,
enum usb_device_speed speed)
{
struct usb_descriptor_header **descriptors;

switch (speed) {
case USB_SPEED_SUPER_PLUS:
descriptors = f->ssp_descriptors;
break;
case USB_SPEED_SUPER:
descriptors = f->ss_descriptors;
break;
case USB_SPEED_HIGH:
descriptors = f->hs_descriptors;
break;
default:
descriptors = f->fs_descriptors;
}

return descriptors;
}

/**
* next_ep_desc() - advance to the next EP descriptor
* @t: currect pointer within descriptor array
Expand Down Expand Up @@ -419,17 +449,7 @@ static int config_buf(struct usb_configuration *config,
list_for_each_entry(f, &config->functions, list) {
struct usb_descriptor_header **descriptors;

switch (speed) {
case USB_SPEED_SUPER:
descriptors = f->ss_descriptors;
break;
case USB_SPEED_HIGH:
descriptors = f->hs_descriptors;
break;
default:
descriptors = f->fs_descriptors;
}

descriptors = function_descriptors(f, speed);
if (!descriptors)
continue;
status = usb_descriptor_fillbuf(next, len,
Expand Down Expand Up @@ -740,16 +760,7 @@ static int set_config(struct usb_composite_dev *cdev,
* function's setup callback instead of the current
* configuration's setup callback.
*/
switch (gadget->speed) {
case USB_SPEED_SUPER:
descriptors = f->ss_descriptors;
break;
case USB_SPEED_HIGH:
descriptors = f->hs_descriptors;
break;
default:
descriptors = f->fs_descriptors;
}
descriptors = function_descriptors(f, gadget->speed);

for (; *descriptors; ++descriptors) {
struct usb_endpoint_descriptor *ep;
Expand Down

0 comments on commit f3bdbe3

Please sign in to comment.