From 33376c1c043c05077b4ac79c33804266f6c45e49 Mon Sep 17 00:00:00 2001 From: David Brownell Date: Mon, 18 Aug 2008 17:45:07 -0700 Subject: usb gadget: link fixes for network gadget Change how the Ethernet/RNDIS gadget driver builds: don't use separate compilation, since it works poorly when key parts are library code (with init sections etc). Instead be as close as we can to "gcc --combine ...". This is a bit more complicated than most of the others because it had to resolve a few symbol collisions. Signed-off-by: David Brownell Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/ether.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'drivers/usb/gadget/ether.c') diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c index bcac2e68660d..944c8e889ab4 100644 --- a/drivers/usb/gadget/ether.c +++ b/drivers/usb/gadget/ether.c @@ -96,6 +96,28 @@ static inline bool has_rndis(void) /*-------------------------------------------------------------------------*/ +/* + * Kbuild is not very cooperative with respect to linking separately + * compiled library objects into one module. So for now we won't use + * separate compilation ... ensuring init/exit sections work to shrink + * the runtime footprint, and giving us at least some parts of what + * a "gcc --combine ... part1.c part2.c part3.c ... " build would. + */ +#include "composite.c" +#include "usbstring.c" +#include "config.c" +#include "epautoconf.c" + +#include "f_ecm.c" +#include "f_subset.c" +#ifdef CONFIG_USB_ETH_RNDIS +#include "f_rndis.c" +#include "rndis.c" +#endif +#include "u_ether.c" + +/*-------------------------------------------------------------------------*/ + /* DO NOT REUSE THESE IDs with a protocol-incompatible driver!! Ever!! * Instead: allocate your own, using normal USB-IF procedures. */ @@ -293,7 +315,8 @@ static int __init eth_bind(struct usb_composite_dev *cdev) * but if the controller isn't recognized at all then * that assumption is a bit more likely to be wrong. */ - WARNING(cdev, "controller '%s' not recognized; trying %s\n", + dev_warn(&gadget->dev, + "controller '%s' not recognized; trying %s\n", gadget->name, eth_config_driver.label); device_desc.bcdDevice = @@ -332,7 +355,8 @@ static int __init eth_bind(struct usb_composite_dev *cdev) if (status < 0) goto fail; - INFO(cdev, "%s, version: " DRIVER_VERSION "\n", DRIVER_DESC); + dev_info(&gadget->dev, "%s, version: " DRIVER_VERSION "\n", + DRIVER_DESC); return 0; -- cgit v1.2.3-59-g8ed1b From 36e893d25aa2abcae0f11ef263de0e8322641386 Mon Sep 17 00:00:00 2001 From: David Brownell Date: Fri, 12 Sep 2008 09:39:06 -0700 Subject: usb gadget: USB_GADGET_VBUS_DRAW Kconfig option Offer a "how much VBUS power to request" configuration option for USB gadgets that aren't using board-specific customization of their gadget or (composite) configuration drivers. Also remove a couple pointless "depends on USB_GADGET" bits from the Kconfig text; booleans inside an "if USB_GADGET" will already have that dependency. Based on a patch from Justin Clacherty. Signed-off-by: David Brownell Cc: Justin Clacherty Tested-by: Robert Jarzmik Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/Kconfig | 23 ++++++++++++++++++++--- drivers/usb/gadget/cdc2.c | 1 - drivers/usb/gadget/composite.c | 4 ++-- drivers/usb/gadget/ether.c | 2 -- drivers/usb/gadget/f_loopback.c | 1 - drivers/usb/gadget/f_sourcesink.c | 1 - drivers/usb/gadget/file_storage.c | 2 +- drivers/usb/gadget/gmidi.c | 2 +- drivers/usb/gadget/printer.c | 3 +-- drivers/usb/gadget/serial.c | 1 - 10 files changed, 25 insertions(+), 15 deletions(-) (limited to 'drivers/usb/gadget/ether.c') diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig index c0dfd9be3115..1a72715bce8a 100644 --- a/drivers/usb/gadget/Kconfig +++ b/drivers/usb/gadget/Kconfig @@ -45,7 +45,7 @@ if USB_GADGET config USB_GADGET_DEBUG boolean "Debugging messages (DEVELOPMENT)" - depends on USB_GADGET && DEBUG_KERNEL + depends on DEBUG_KERNEL help Many controller and gadget drivers will print some debugging messages if you use this option to ask for those messages. @@ -59,7 +59,7 @@ config USB_GADGET_DEBUG config USB_GADGET_DEBUG_FILES boolean "Debugging information files (DEVELOPMENT)" - depends on USB_GADGET && PROC_FS + depends on PROC_FS help Some of the drivers in the "gadget" framework can expose debugging information in files such as /proc/driver/udc @@ -70,7 +70,7 @@ config USB_GADGET_DEBUG_FILES config USB_GADGET_DEBUG_FS boolean "Debugging information files in debugfs (DEVELOPMENT)" - depends on USB_GADGET && DEBUG_FS + depends on DEBUG_FS help Some of the drivers in the "gadget" framework can expose debugging information in files under /sys/kernel/debug/. @@ -79,6 +79,23 @@ config USB_GADGET_DEBUG_FS Enable these files by choosing "Y" here. If in doubt, or to conserve kernel memory, say "N". +config USB_GADGET_VBUS_DRAW + int "Maximum VBUS Power usage (2-500 mA)" + range 2 500 + default 2 + help + Some devices need to draw power from USB when they are + configured, perhaps to operate circuitry or to recharge + batteries. This is in addition to any local power supply, + such as an AC adapter or batteries. + + Enter the maximum power your device draws through USB, in + milliAmperes. The permitted range of values is 2 - 500 mA; + 0 mA would be legal, but can make some hosts misbehave. + + This value will be used except for system-specific gadget + drivers that have more specific information. + config USB_GADGET_SELECTED boolean diff --git a/drivers/usb/gadget/cdc2.c b/drivers/usb/gadget/cdc2.c index a724fc149850..5495b171cf29 100644 --- a/drivers/usb/gadget/cdc2.c +++ b/drivers/usb/gadget/cdc2.c @@ -155,7 +155,6 @@ static struct usb_configuration cdc_config_driver = { .bConfigurationValue = 1, /* .iConfiguration = DYNAMIC */ .bmAttributes = USB_CONFIG_ATT_SELFPOWER, - .bMaxPower = 1, /* 2 mA, minimal */ }; /*-------------------------------------------------------------------------*/ diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c index f79fdb839cb8..f2da0269e1b1 100644 --- a/drivers/usb/gadget/composite.c +++ b/drivers/usb/gadget/composite.c @@ -245,7 +245,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; + c->bMaxPower = config->bMaxPower ? : (CONFIG_USB_GADGET_VBUS_DRAW / 2); /* There may be e.g. OTG descriptors */ if (config->descriptors) { @@ -432,7 +432,7 @@ static int set_config(struct usb_composite_dev *cdev, } /* when we return, be sure our power usage is valid */ - power = 2 * c->bMaxPower; + power = c->bMaxPower ? (2 * c->bMaxPower) : CONFIG_USB_GADGET_VBUS_DRAW; done: usb_gadget_vbus_draw(gadget, power); return result; diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c index 944c8e889ab4..37252d0012a7 100644 --- a/drivers/usb/gadget/ether.c +++ b/drivers/usb/gadget/ether.c @@ -242,7 +242,6 @@ static struct usb_configuration rndis_config_driver = { .bConfigurationValue = 2, /* .iConfiguration = DYNAMIC */ .bmAttributes = USB_CONFIG_ATT_SELFPOWER, - .bMaxPower = 1, /* 2 mA, minimal */ }; /*-------------------------------------------------------------------------*/ @@ -271,7 +270,6 @@ static struct usb_configuration eth_config_driver = { .bConfigurationValue = 1, /* .iConfiguration = DYNAMIC */ .bmAttributes = USB_CONFIG_ATT_SELFPOWER, - .bMaxPower = 1, /* 2 mA, minimal */ }; /*-------------------------------------------------------------------------*/ diff --git a/drivers/usb/gadget/f_loopback.c b/drivers/usb/gadget/f_loopback.c index 87dde012dacc..8affe1dfc2c1 100644 --- a/drivers/usb/gadget/f_loopback.c +++ b/drivers/usb/gadget/f_loopback.c @@ -352,7 +352,6 @@ static struct usb_configuration loopback_driver = { .bind = loopback_bind_config, .bConfigurationValue = 2, .bmAttributes = USB_CONFIG_ATT_SELFPOWER, - .bMaxPower = 1, /* 2 mA, minimal */ /* .iConfiguration = DYNAMIC */ }; diff --git a/drivers/usb/gadget/f_sourcesink.c b/drivers/usb/gadget/f_sourcesink.c index f18c3a14d72a..dc84d26d2835 100644 --- a/drivers/usb/gadget/f_sourcesink.c +++ b/drivers/usb/gadget/f_sourcesink.c @@ -552,7 +552,6 @@ static struct usb_configuration sourcesink_driver = { .setup = sourcesink_setup, .bConfigurationValue = 3, .bmAttributes = USB_CONFIG_ATT_SELFPOWER, - .bMaxPower = 1, /* 2 mA, minimal */ /* .iConfiguration = DYNAMIC */ }; diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c index e0f616f39ba0..c4e62a6297d7 100644 --- a/drivers/usb/gadget/file_storage.c +++ b/drivers/usb/gadget/file_storage.c @@ -851,7 +851,7 @@ config_desc = { .bConfigurationValue = CONFIG_VALUE, .iConfiguration = STRING_CONFIG, .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER, - .bMaxPower = 1, // self-powered + .bMaxPower = CONFIG_USB_GADGET_VBUS_DRAW / 2, }; static struct usb_otg_descriptor diff --git a/drivers/usb/gadget/gmidi.c b/drivers/usb/gadget/gmidi.c index 6eee760410d6..60d3f9e9b51f 100644 --- a/drivers/usb/gadget/gmidi.c +++ b/drivers/usb/gadget/gmidi.c @@ -222,7 +222,7 @@ static struct usb_config_descriptor config_desc = { * power properties of the device. Is it selfpowered? */ .bmAttributes = USB_CONFIG_ATT_ONE, - .bMaxPower = 1, + .bMaxPower = CONFIG_USB_GADGET_VBUS_DRAW / 2, }; /* B.3.1 Standard AC Interface Descriptor */ diff --git a/drivers/usb/gadget/printer.c b/drivers/usb/gadget/printer.c index 00b7ed5013a6..5a3034fdfe47 100644 --- a/drivers/usb/gadget/printer.c +++ b/drivers/usb/gadget/printer.c @@ -252,7 +252,7 @@ static struct usb_config_descriptor config_desc = { .bConfigurationValue = DEV_CONFIG_VALUE, .iConfiguration = 0, .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER, - .bMaxPower = 1 /* Self-Powered */ + .bMaxPower = CONFIG_USB_GADGET_VBUS_DRAW / 2, }; static struct usb_interface_descriptor intf_desc = { @@ -1476,7 +1476,6 @@ autoconf_fail: if (gadget->is_otg) { otg_desc.bmAttributes |= USB_OTG_HNP, config_desc.bmAttributes |= USB_CONFIG_ATT_WAKEUP; - config_desc.bMaxPower = 4; } spin_lock_init(&dev->lock); diff --git a/drivers/usb/gadget/serial.c b/drivers/usb/gadget/serial.c index 2dee848b2f59..37879af1c433 100644 --- a/drivers/usb/gadget/serial.c +++ b/drivers/usb/gadget/serial.c @@ -159,7 +159,6 @@ static struct usb_configuration serial_config_driver = { /* .bConfigurationValue = f(use_acm) */ /* .iConfiguration = DYNAMIC */ .bmAttributes = USB_CONFIG_ATT_SELFPOWER, - .bMaxPower = 1, /* 2 mA, minimal */ }; static int __init gs_bind(struct usb_composite_dev *cdev) -- cgit v1.2.3-59-g8ed1b