Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 354628
b: refs/heads/master
c: 8f900a9
h: refs/heads/master
v: v3
  • Loading branch information
Sebastian Andrzej Siewior authored and Felipe Balbi committed Jan 10, 2013
1 parent d882acd commit 83d87f6
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 11 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 98f3a1b90795d7216de0d56157868d174317f91a
refs/heads/master: 8f900a9a6e2691441ad763952d640ac44220e5dc
27 changes: 23 additions & 4 deletions trunk/drivers/usb/gadget/composite.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,25 @@ int usb_interface_id(struct usb_configuration *config,
}
EXPORT_SYMBOL_GPL(usb_interface_id);

static u8 encode_bMaxPower(enum usb_device_speed speed,
struct usb_configuration *c)
{
unsigned val;

if (c->MaxPower)
val = c->MaxPower;
else
val = CONFIG_USB_GADGET_VBUS_DRAW;
if (!val)
return 0;
switch (speed) {
case USB_SPEED_SUPER:
return DIV_ROUND_UP(val, 8);
default:
return DIV_ROUND_UP(val, 2);
};
}

static int config_buf(struct usb_configuration *config,
enum usb_device_speed speed, void *buf, u8 type)
{
Expand All @@ -339,7 +358,7 @@ static int config_buf(struct usb_configuration *config,
c->bConfigurationValue = config->bConfigurationValue;
c->iConfiguration = config->iConfiguration;
c->bmAttributes = USB_CONFIG_ATT_ONE | config->bmAttributes;
c->bMaxPower = config->bMaxPower ? : (CONFIG_USB_GADGET_VBUS_DRAW / 2);
c->bMaxPower = encode_bMaxPower(speed, config);

/* There may be e.g. OTG descriptors */
if (config->descriptors) {
Expand Down Expand Up @@ -656,7 +675,7 @@ static int set_config(struct usb_composite_dev *cdev,
}

/* when we return, be sure our power usage is valid */
power = c->bMaxPower ? (2 * c->bMaxPower) : CONFIG_USB_GADGET_VBUS_DRAW;
power = c->MaxPower ? c->MaxPower : CONFIG_USB_GADGET_VBUS_DRAW;
done:
usb_gadget_vbus_draw(gadget, power);
if (result >= 0 && cdev->delayed_status)
Expand Down Expand Up @@ -1518,10 +1537,10 @@ composite_resume(struct usb_gadget *gadget)
f->resume(f);
}

maxpower = cdev->config->bMaxPower;
maxpower = cdev->config->MaxPower;

usb_gadget_vbus_draw(gadget, maxpower ?
(2 * maxpower) : CONFIG_USB_GADGET_VBUS_DRAW);
maxpower : CONFIG_USB_GADGET_VBUS_DRAW);
}

cdev->suspended = 0;
Expand Down
2 changes: 1 addition & 1 deletion trunk/drivers/usb/gadget/gmidi.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ static struct usb_configuration midi_config = {
.bConfigurationValue = 1,
/* .iConfiguration = DYNAMIC */
.bmAttributes = USB_CONFIG_ATT_ONE,
.bMaxPower = CONFIG_USB_GADGET_VBUS_DRAW / 2,
.MaxPower = CONFIG_USB_GADGET_VBUS_DRAW,
};

static int __init midi_bind_config(struct usb_configuration *c)
Expand Down
4 changes: 2 additions & 2 deletions trunk/drivers/usb/gadget/nokia.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,15 @@ static struct usb_configuration nokia_config_500ma_driver = {
.bConfigurationValue = 1,
/* .iConfiguration = DYNAMIC */
.bmAttributes = USB_CONFIG_ATT_ONE,
.bMaxPower = 250, /* 500mA */
.MaxPower = 500,
};

static struct usb_configuration nokia_config_100ma_driver = {
.label = "Self Powered",
.bConfigurationValue = 2,
/* .iConfiguration = DYNAMIC */
.bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER,
.bMaxPower = 50, /* 100 mA */
.MaxPower = 100,
};

static int __init nokia_bind(struct usb_composite_dev *cdev)
Expand Down
2 changes: 1 addition & 1 deletion trunk/drivers/usb/gadget/webcam.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ static struct usb_configuration webcam_config_driver = {
.bConfigurationValue = 1,
.iConfiguration = 0, /* dynamic */
.bmAttributes = USB_CONFIG_ATT_SELFPOWER,
.bMaxPower = CONFIG_USB_GADGET_VBUS_DRAW / 2,
.MaxPower = CONFIG_USB_GADGET_VBUS_DRAW,
};

static int /* __init_or_exit */
Expand Down
5 changes: 3 additions & 2 deletions trunk/include/linux/usb/composite.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ int config_ep_by_speed(struct usb_gadget *g, struct usb_function *f,
* @bConfigurationValue: Copied into configuration descriptor.
* @iConfiguration: Copied into configuration descriptor.
* @bmAttributes: Copied into configuration descriptor.
* @bMaxPower: Copied into configuration descriptor.
* @MaxPower: Power consumtion in mA. Used to compute bMaxPower in the
* configuration descriptor after considering the bus speed.
* @cdev: assigned by @usb_add_config() before calling @bind(); this is
* the device associated with this configuration.
*
Expand Down Expand Up @@ -230,7 +231,7 @@ struct usb_configuration {
u8 bConfigurationValue;
u8 iConfiguration;
u8 bmAttributes;
u8 bMaxPower;
u16 MaxPower;

struct usb_composite_dev *cdev;

Expand Down

0 comments on commit 83d87f6

Please sign in to comment.