diff options
author | Sebastian Andrzej Siewior <bigeasy@linutronix.de> | 2012-12-03 14:07:05 -0500 |
---|---|---|
committer | Felipe Balbi <balbi@ti.com> | 2013-01-10 05:38:52 -0500 |
commit | 8f900a9a6e2691441ad763952d640ac44220e5dc (patch) | |
tree | 5f00b9cba299d1dfa035bf3dc13cb1029e39381a | |
parent | 98f3a1b90795d7216de0d56157868d174317f91a (diff) |
usb: gadget: consider link speed for bMaxPower
The USB 2.0 specification says that bMaxPower is the maximum power
consumption expressed in 2 mA units and the USB 3.0 specification says
that it is expressed in 8 mA units.
This patch renames bMaxPower to MaxPower and the various /2 and *2 are
removed. Before reporting the config descriptor, the proper value is
computer based on the speed, all in-tree users are updated. MaxPower is
also increased to u16 so we can store the nokia gadget value which is
larger than the max value allowed for u8.
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
-rw-r--r-- | drivers/usb/gadget/composite.c | 27 | ||||
-rw-r--r-- | drivers/usb/gadget/gmidi.c | 2 | ||||
-rw-r--r-- | drivers/usb/gadget/nokia.c | 4 | ||||
-rw-r--r-- | drivers/usb/gadget/webcam.c | 2 | ||||
-rw-r--r-- | include/linux/usb/composite.h | 5 |
5 files changed, 30 insertions, 10 deletions
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c index 2a6bfe759c29..71475b6d8568 100644 --- a/drivers/usb/gadget/composite.c +++ b/drivers/usb/gadget/composite.c | |||
@@ -320,6 +320,25 @@ int usb_interface_id(struct usb_configuration *config, | |||
320 | } | 320 | } |
321 | EXPORT_SYMBOL_GPL(usb_interface_id); | 321 | EXPORT_SYMBOL_GPL(usb_interface_id); |
322 | 322 | ||
323 | static u8 encode_bMaxPower(enum usb_device_speed speed, | ||
324 | struct usb_configuration *c) | ||
325 | { | ||
326 | unsigned val; | ||
327 | |||
328 | if (c->MaxPower) | ||
329 | val = c->MaxPower; | ||
330 | else | ||
331 | val = CONFIG_USB_GADGET_VBUS_DRAW; | ||
332 | if (!val) | ||
333 | return 0; | ||
334 | switch (speed) { | ||
335 | case USB_SPEED_SUPER: | ||
336 | return DIV_ROUND_UP(val, 8); | ||
337 | default: | ||
338 | return DIV_ROUND_UP(val, 2); | ||
339 | }; | ||
340 | } | ||
341 | |||
323 | static int config_buf(struct usb_configuration *config, | 342 | static int config_buf(struct usb_configuration *config, |
324 | enum usb_device_speed speed, void *buf, u8 type) | 343 | enum usb_device_speed speed, void *buf, u8 type) |
325 | { | 344 | { |
@@ -339,7 +358,7 @@ static int config_buf(struct usb_configuration *config, | |||
339 | c->bConfigurationValue = config->bConfigurationValue; | 358 | c->bConfigurationValue = config->bConfigurationValue; |
340 | c->iConfiguration = config->iConfiguration; | 359 | c->iConfiguration = config->iConfiguration; |
341 | c->bmAttributes = USB_CONFIG_ATT_ONE | config->bmAttributes; | 360 | c->bmAttributes = USB_CONFIG_ATT_ONE | config->bmAttributes; |
342 | c->bMaxPower = config->bMaxPower ? : (CONFIG_USB_GADGET_VBUS_DRAW / 2); | 361 | c->bMaxPower = encode_bMaxPower(speed, config); |
343 | 362 | ||
344 | /* There may be e.g. OTG descriptors */ | 363 | /* There may be e.g. OTG descriptors */ |
345 | if (config->descriptors) { | 364 | if (config->descriptors) { |
@@ -656,7 +675,7 @@ static int set_config(struct usb_composite_dev *cdev, | |||
656 | } | 675 | } |
657 | 676 | ||
658 | /* when we return, be sure our power usage is valid */ | 677 | /* when we return, be sure our power usage is valid */ |
659 | power = c->bMaxPower ? (2 * c->bMaxPower) : CONFIG_USB_GADGET_VBUS_DRAW; | 678 | power = c->MaxPower ? c->MaxPower : CONFIG_USB_GADGET_VBUS_DRAW; |
660 | done: | 679 | done: |
661 | usb_gadget_vbus_draw(gadget, power); | 680 | usb_gadget_vbus_draw(gadget, power); |
662 | if (result >= 0 && cdev->delayed_status) | 681 | if (result >= 0 && cdev->delayed_status) |
@@ -1518,10 +1537,10 @@ composite_resume(struct usb_gadget *gadget) | |||
1518 | f->resume(f); | 1537 | f->resume(f); |
1519 | } | 1538 | } |
1520 | 1539 | ||
1521 | maxpower = cdev->config->bMaxPower; | 1540 | maxpower = cdev->config->MaxPower; |
1522 | 1541 | ||
1523 | usb_gadget_vbus_draw(gadget, maxpower ? | 1542 | usb_gadget_vbus_draw(gadget, maxpower ? |
1524 | (2 * maxpower) : CONFIG_USB_GADGET_VBUS_DRAW); | 1543 | maxpower : CONFIG_USB_GADGET_VBUS_DRAW); |
1525 | } | 1544 | } |
1526 | 1545 | ||
1527 | cdev->suspended = 0; | 1546 | cdev->suspended = 0; |
diff --git a/drivers/usb/gadget/gmidi.c b/drivers/usb/gadget/gmidi.c index 881aab86ae99..e879e2c9f461 100644 --- a/drivers/usb/gadget/gmidi.c +++ b/drivers/usb/gadget/gmidi.c | |||
@@ -125,7 +125,7 @@ static struct usb_configuration midi_config = { | |||
125 | .bConfigurationValue = 1, | 125 | .bConfigurationValue = 1, |
126 | /* .iConfiguration = DYNAMIC */ | 126 | /* .iConfiguration = DYNAMIC */ |
127 | .bmAttributes = USB_CONFIG_ATT_ONE, | 127 | .bmAttributes = USB_CONFIG_ATT_ONE, |
128 | .bMaxPower = CONFIG_USB_GADGET_VBUS_DRAW / 2, | 128 | .MaxPower = CONFIG_USB_GADGET_VBUS_DRAW, |
129 | }; | 129 | }; |
130 | 130 | ||
131 | static int __init midi_bind_config(struct usb_configuration *c) | 131 | static int __init midi_bind_config(struct usb_configuration *c) |
diff --git a/drivers/usb/gadget/nokia.c b/drivers/usb/gadget/nokia.c index 661600abace8..1475d663b527 100644 --- a/drivers/usb/gadget/nokia.c +++ b/drivers/usb/gadget/nokia.c | |||
@@ -133,7 +133,7 @@ static struct usb_configuration nokia_config_500ma_driver = { | |||
133 | .bConfigurationValue = 1, | 133 | .bConfigurationValue = 1, |
134 | /* .iConfiguration = DYNAMIC */ | 134 | /* .iConfiguration = DYNAMIC */ |
135 | .bmAttributes = USB_CONFIG_ATT_ONE, | 135 | .bmAttributes = USB_CONFIG_ATT_ONE, |
136 | .bMaxPower = 250, /* 500mA */ | 136 | .MaxPower = 500, |
137 | }; | 137 | }; |
138 | 138 | ||
139 | static struct usb_configuration nokia_config_100ma_driver = { | 139 | static struct usb_configuration nokia_config_100ma_driver = { |
@@ -141,7 +141,7 @@ static struct usb_configuration nokia_config_100ma_driver = { | |||
141 | .bConfigurationValue = 2, | 141 | .bConfigurationValue = 2, |
142 | /* .iConfiguration = DYNAMIC */ | 142 | /* .iConfiguration = DYNAMIC */ |
143 | .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER, | 143 | .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER, |
144 | .bMaxPower = 50, /* 100 mA */ | 144 | .MaxPower = 100, |
145 | }; | 145 | }; |
146 | 146 | ||
147 | static int __init nokia_bind(struct usb_composite_dev *cdev) | 147 | static int __init nokia_bind(struct usb_composite_dev *cdev) |
diff --git a/drivers/usb/gadget/webcam.c b/drivers/usb/gadget/webcam.c index 69cf5c2cd335..8cef1e658c29 100644 --- a/drivers/usb/gadget/webcam.c +++ b/drivers/usb/gadget/webcam.c | |||
@@ -336,7 +336,7 @@ static struct usb_configuration webcam_config_driver = { | |||
336 | .bConfigurationValue = 1, | 336 | .bConfigurationValue = 1, |
337 | .iConfiguration = 0, /* dynamic */ | 337 | .iConfiguration = 0, /* dynamic */ |
338 | .bmAttributes = USB_CONFIG_ATT_SELFPOWER, | 338 | .bmAttributes = USB_CONFIG_ATT_SELFPOWER, |
339 | .bMaxPower = CONFIG_USB_GADGET_VBUS_DRAW / 2, | 339 | .MaxPower = CONFIG_USB_GADGET_VBUS_DRAW, |
340 | }; | 340 | }; |
341 | 341 | ||
342 | static int /* __init_or_exit */ | 342 | static int /* __init_or_exit */ |
diff --git a/include/linux/usb/composite.h b/include/linux/usb/composite.h index b09c37e04a91..dc512c9432d7 100644 --- a/include/linux/usb/composite.h +++ b/include/linux/usb/composite.h | |||
@@ -184,7 +184,8 @@ int config_ep_by_speed(struct usb_gadget *g, struct usb_function *f, | |||
184 | * @bConfigurationValue: Copied into configuration descriptor. | 184 | * @bConfigurationValue: Copied into configuration descriptor. |
185 | * @iConfiguration: Copied into configuration descriptor. | 185 | * @iConfiguration: Copied into configuration descriptor. |
186 | * @bmAttributes: Copied into configuration descriptor. | 186 | * @bmAttributes: Copied into configuration descriptor. |
187 | * @bMaxPower: Copied into configuration descriptor. | 187 | * @MaxPower: Power consumtion in mA. Used to compute bMaxPower in the |
188 | * configuration descriptor after considering the bus speed. | ||
188 | * @cdev: assigned by @usb_add_config() before calling @bind(); this is | 189 | * @cdev: assigned by @usb_add_config() before calling @bind(); this is |
189 | * the device associated with this configuration. | 190 | * the device associated with this configuration. |
190 | * | 191 | * |
@@ -230,7 +231,7 @@ struct usb_configuration { | |||
230 | u8 bConfigurationValue; | 231 | u8 bConfigurationValue; |
231 | u8 iConfiguration; | 232 | u8 iConfiguration; |
232 | u8 bmAttributes; | 233 | u8 bmAttributes; |
233 | u8 bMaxPower; | 234 | u16 MaxPower; |
234 | 235 | ||
235 | struct usb_composite_dev *cdev; | 236 | struct usb_composite_dev *cdev; |
236 | 237 | ||