diff options
author | David Brownell <david-b@pacbell.net> | 2007-08-02 02:58:22 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2007-10-12 17:55:03 -0400 |
commit | a4e3ef5597e26dad006544d38b9ab6ff42382b76 (patch) | |
tree | ea35833ffe27301bd058f64dda90d190decc0265 /drivers/usb/gadget/inode.c | |
parent | a1d534bb23e5c5c28fb6f6fb48588362df0907e8 (diff) |
USB: gadget: gadget_is_{dualspeed,otg} predicates and cleanup
This adds two small inlines to the gadget stack, which will
often evaluate to compile-time constants. That can help
shrink object code and remove #ifdeffery.
- gadget_is_dualspeed(), currently always a compile-time
constant (depending on which controller is selected).
- gadget_is_otg(), usually a compile time "false", but this
is a runtime test if the platform enables OTG (since it's
reasonable to populate boards with different USB sockets).
It also updates two peripheral controller drivers to use these:
- fsl_usb2_udc, mostly OTG-related bugfixes: non-OTG devices
must follow the rules about drawing VBUS power, and OTG ones
need to reject invalid SET_FEATURE requests.
- omap_udc, just scrubbing a bit of #ifdeffery.
And also gadgetfs, which lost some #ifdefs and moved to a more
standard handling of DEBUG and VERBOSE_DEBUG.
The main benefits come from patches which will follow.
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/gadget/inode.c')
-rw-r--r-- | drivers/usb/gadget/inode.c | 44 |
1 files changed, 20 insertions, 24 deletions
diff --git a/drivers/usb/gadget/inode.c b/drivers/usb/gadget/inode.c index 173004f60fea..129eda5358f7 100644 --- a/drivers/usb/gadget/inode.c +++ b/drivers/usb/gadget/inode.c | |||
@@ -20,8 +20,7 @@ | |||
20 | */ | 20 | */ |
21 | 21 | ||
22 | 22 | ||
23 | // #define DEBUG /* data to help fault diagnosis */ | 23 | /* #define VERBOSE_DEBUG */ |
24 | // #define VERBOSE /* extra debug messages (success too) */ | ||
25 | 24 | ||
26 | #include <linux/init.h> | 25 | #include <linux/init.h> |
27 | #include <linux/module.h> | 26 | #include <linux/module.h> |
@@ -253,7 +252,7 @@ static const char *CHIP; | |||
253 | do { } while (0) | 252 | do { } while (0) |
254 | #endif /* DEBUG */ | 253 | #endif /* DEBUG */ |
255 | 254 | ||
256 | #ifdef VERBOSE | 255 | #ifdef VERBOSE_DEBUG |
257 | #define VDEBUG DBG | 256 | #define VDEBUG DBG |
258 | #else | 257 | #else |
259 | #define VDEBUG(dev,fmt,args...) \ | 258 | #define VDEBUG(dev,fmt,args...) \ |
@@ -1010,11 +1009,12 @@ ep0_read (struct file *fd, char __user *buf, size_t len, loff_t *ptr) | |||
1010 | /* assume that was SET_CONFIGURATION */ | 1009 | /* assume that was SET_CONFIGURATION */ |
1011 | if (dev->current_config) { | 1010 | if (dev->current_config) { |
1012 | unsigned power; | 1011 | unsigned power; |
1013 | #ifdef CONFIG_USB_GADGET_DUALSPEED | 1012 | |
1014 | if (dev->gadget->speed == USB_SPEED_HIGH) | 1013 | if (gadget_is_dualspeed(dev->gadget) |
1014 | && (dev->gadget->speed | ||
1015 | == USB_SPEED_HIGH)) | ||
1015 | power = dev->hs_config->bMaxPower; | 1016 | power = dev->hs_config->bMaxPower; |
1016 | else | 1017 | else |
1017 | #endif | ||
1018 | power = dev->config->bMaxPower; | 1018 | power = dev->config->bMaxPower; |
1019 | usb_gadget_vbus_draw(dev->gadget, 2 * power); | 1019 | usb_gadget_vbus_draw(dev->gadget, 2 * power); |
1020 | } | 1020 | } |
@@ -1355,24 +1355,21 @@ static int | |||
1355 | config_buf (struct dev_data *dev, u8 type, unsigned index) | 1355 | config_buf (struct dev_data *dev, u8 type, unsigned index) |
1356 | { | 1356 | { |
1357 | int len; | 1357 | int len; |
1358 | #ifdef CONFIG_USB_GADGET_DUALSPEED | 1358 | int hs = 0; |
1359 | int hs; | ||
1360 | #endif | ||
1361 | 1359 | ||
1362 | /* only one configuration */ | 1360 | /* only one configuration */ |
1363 | if (index > 0) | 1361 | if (index > 0) |
1364 | return -EINVAL; | 1362 | return -EINVAL; |
1365 | 1363 | ||
1366 | #ifdef CONFIG_USB_GADGET_DUALSPEED | 1364 | if (gadget_is_dualspeed(dev->gadget)) { |
1367 | hs = (dev->gadget->speed == USB_SPEED_HIGH); | 1365 | hs = (dev->gadget->speed == USB_SPEED_HIGH); |
1368 | if (type == USB_DT_OTHER_SPEED_CONFIG) | 1366 | if (type == USB_DT_OTHER_SPEED_CONFIG) |
1369 | hs = !hs; | 1367 | hs = !hs; |
1368 | } | ||
1370 | if (hs) { | 1369 | if (hs) { |
1371 | dev->req->buf = dev->hs_config; | 1370 | dev->req->buf = dev->hs_config; |
1372 | len = le16_to_cpu(dev->hs_config->wTotalLength); | 1371 | len = le16_to_cpu(dev->hs_config->wTotalLength); |
1373 | } else | 1372 | } else { |
1374 | #endif | ||
1375 | { | ||
1376 | dev->req->buf = dev->config; | 1373 | dev->req->buf = dev->config; |
1377 | len = le16_to_cpu(dev->config->wTotalLength); | 1374 | len = le16_to_cpu(dev->config->wTotalLength); |
1378 | } | 1375 | } |
@@ -1393,13 +1390,13 @@ gadgetfs_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) | |||
1393 | spin_lock (&dev->lock); | 1390 | spin_lock (&dev->lock); |
1394 | dev->setup_abort = 0; | 1391 | dev->setup_abort = 0; |
1395 | if (dev->state == STATE_DEV_UNCONNECTED) { | 1392 | if (dev->state == STATE_DEV_UNCONNECTED) { |
1396 | #ifdef CONFIG_USB_GADGET_DUALSPEED | 1393 | if (gadget_is_dualspeed(gadget) |
1397 | if (gadget->speed == USB_SPEED_HIGH && dev->hs_config == NULL) { | 1394 | && gadget->speed == USB_SPEED_HIGH |
1395 | && dev->hs_config == NULL) { | ||
1398 | spin_unlock(&dev->lock); | 1396 | spin_unlock(&dev->lock); |
1399 | ERROR (dev, "no high speed config??\n"); | 1397 | ERROR (dev, "no high speed config??\n"); |
1400 | return -EINVAL; | 1398 | return -EINVAL; |
1401 | } | 1399 | } |
1402 | #endif /* CONFIG_USB_GADGET_DUALSPEED */ | ||
1403 | 1400 | ||
1404 | dev->state = STATE_DEV_CONNECTED; | 1401 | dev->state = STATE_DEV_CONNECTED; |
1405 | dev->dev->bMaxPacketSize0 = gadget->ep0->maxpacket; | 1402 | dev->dev->bMaxPacketSize0 = gadget->ep0->maxpacket; |
@@ -1469,13 +1466,12 @@ gadgetfs_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) | |||
1469 | // user mode expected to disable endpoints | 1466 | // user mode expected to disable endpoints |
1470 | } else { | 1467 | } else { |
1471 | u8 config, power; | 1468 | u8 config, power; |
1472 | #ifdef CONFIG_USB_GADGET_DUALSPEED | 1469 | |
1473 | if (gadget->speed == USB_SPEED_HIGH) { | 1470 | if (gadget_is_dualspeed(gadget) |
1471 | && gadget->speed == USB_SPEED_HIGH) { | ||
1474 | config = dev->hs_config->bConfigurationValue; | 1472 | config = dev->hs_config->bConfigurationValue; |
1475 | power = dev->hs_config->bMaxPower; | 1473 | power = dev->hs_config->bMaxPower; |
1476 | } else | 1474 | } else { |
1477 | #endif | ||
1478 | { | ||
1479 | config = dev->config->bConfigurationValue; | 1475 | config = dev->config->bConfigurationValue; |
1480 | power = dev->config->bMaxPower; | 1476 | power = dev->config->bMaxPower; |
1481 | } | 1477 | } |