Commit 7472f38b authored by David Brownell's avatar David Brownell Committed by Greg Kroah-Hartman

usb: gadget zero style fixups (mostly whitespace)

Minor updates to "Gadget Zero".

 - Primarily these are whitespace updates to address the fact that since
   this was written, Documentation/CodingStyle was changed to disapprove
   of parts of the original coding style.

 - Update a few comments that weren't quite correct, notably mentioning
   the "autoresume" module parameter.
Signed-off-by: default avatarDavid Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent f371e750
...@@ -23,9 +23,7 @@ ...@@ -23,9 +23,7 @@
/* /*
* Gadget Zero only needs two bulk endpoints, and is an example of how you * Gadget Zero only needs two bulk endpoints, and is an example of how you
* can write a hardware-agnostic gadget driver running inside a USB device. * can write a hardware-agnostic gadget driver running inside a USB device.
* * Some hardware details are visible, but don't affect most of the driver.
* Hardware details are visible (see CONFIG_USB_ZERO_* below) but don't
* affect most of the driver.
* *
* Use it with the Linux host/master side "usbtest" driver to get a basic * Use it with the Linux host/master side "usbtest" driver to get a basic
* functional test of your device-side usb stack, or with "usb-skeleton". * functional test of your device-side usb stack, or with "usb-skeleton".
...@@ -37,6 +35,7 @@ ...@@ -37,6 +35,7 @@
* buflen=N default N=4096, buffer size used * buflen=N default N=4096, buffer size used
* qlen=N default N=32, how many buffers in the loopback queue * qlen=N default N=32, how many buffers in the loopback queue
* loopdefault default false, list loopback config first * loopdefault default false, list loopback config first
* autoresume=N default N=0, seconds before triggering remote wakeup
* *
* Many drivers will only have one configuration, letting them be much * Many drivers will only have one configuration, letting them be much
* simpler if they also don't support high speed operation (like this * simpler if they also don't support high speed operation (like this
...@@ -62,13 +61,13 @@ ...@@ -62,13 +61,13 @@
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
#define DRIVER_VERSION "Lughnasadh, 2007" #define DRIVER_VERSION "Earth Day 2008"
static const char shortname [] = "zero"; static const char shortname[] = "zero";
static const char longname [] = "Gadget Zero"; static const char longname[] = "Gadget Zero";
static const char source_sink [] = "source and sink data"; static const char source_sink[] = "source and sink data";
static const char loopback [] = "loop input to output"; static const char loopback[] = "loop input to output";
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
...@@ -120,16 +119,16 @@ static unsigned buflen = 4096; ...@@ -120,16 +119,16 @@ static unsigned buflen = 4096;
static unsigned qlen = 32; static unsigned qlen = 32;
static unsigned pattern = 0; static unsigned pattern = 0;
module_param (buflen, uint, S_IRUGO); module_param(buflen, uint, S_IRUGO);
module_param (qlen, uint, S_IRUGO); module_param(qlen, uint, S_IRUGO);
module_param (pattern, uint, S_IRUGO|S_IWUSR); module_param(pattern, uint, S_IRUGO|S_IWUSR);
/* /*
* if it's nonzero, autoresume says how many seconds to wait * if it's nonzero, autoresume says how many seconds to wait
* before trying to wake up the host after suspend. * before trying to wake up the host after suspend.
*/ */
static unsigned autoresume = 0; static unsigned autoresume = 0;
module_param (autoresume, uint, 0); module_param(autoresume, uint, 0);
/* /*
* Normally the "loopback" configuration is second (index 1) so * Normally the "loopback" configuration is second (index 1) so
...@@ -138,8 +137,7 @@ module_param (autoresume, uint, 0); ...@@ -138,8 +137,7 @@ module_param (autoresume, uint, 0);
* Or controllers (like superh) that only support one config. * Or controllers (like superh) that only support one config.
*/ */
static int loopdefault = 0; static int loopdefault = 0;
module_param(loopdefault, bool, S_IRUGO|S_IWUSR);
module_param (loopdefault, bool, S_IRUGO|S_IWUSR);
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
...@@ -176,24 +174,22 @@ module_param (loopdefault, bool, S_IRUGO|S_IWUSR); ...@@ -176,24 +174,22 @@ module_param (loopdefault, bool, S_IRUGO|S_IWUSR);
#define CONFIG_SOURCE_SINK 3 #define CONFIG_SOURCE_SINK 3
#define CONFIG_LOOPBACK 2 #define CONFIG_LOOPBACK 2
static struct usb_device_descriptor static struct usb_device_descriptor device_desc = {
device_desc = {
.bLength = sizeof device_desc, .bLength = sizeof device_desc,
.bDescriptorType = USB_DT_DEVICE, .bDescriptorType = USB_DT_DEVICE,
.bcdUSB = __constant_cpu_to_le16 (0x0200), .bcdUSB = __constant_cpu_to_le16(0x0200),
.bDeviceClass = USB_CLASS_VENDOR_SPEC, .bDeviceClass = USB_CLASS_VENDOR_SPEC,
.idVendor = __constant_cpu_to_le16 (DRIVER_VENDOR_NUM), .idVendor = __constant_cpu_to_le16(DRIVER_VENDOR_NUM),
.idProduct = __constant_cpu_to_le16 (DRIVER_PRODUCT_NUM), .idProduct = __constant_cpu_to_le16(DRIVER_PRODUCT_NUM),
.iManufacturer = STRING_MANUFACTURER, .iManufacturer = STRING_MANUFACTURER,
.iProduct = STRING_PRODUCT, .iProduct = STRING_PRODUCT,
.iSerialNumber = STRING_SERIAL, .iSerialNumber = STRING_SERIAL,
.bNumConfigurations = 2, .bNumConfigurations = 2,
}; };
static struct usb_config_descriptor static struct usb_config_descriptor source_sink_config = {
source_sink_config = {
.bLength = sizeof source_sink_config, .bLength = sizeof source_sink_config,
.bDescriptorType = USB_DT_CONFIG, .bDescriptorType = USB_DT_CONFIG,
...@@ -205,8 +201,7 @@ source_sink_config = { ...@@ -205,8 +201,7 @@ source_sink_config = {
.bMaxPower = 1, /* self-powered */ .bMaxPower = 1, /* self-powered */
}; };
static struct usb_config_descriptor static struct usb_config_descriptor loopback_config = {
loopback_config = {
.bLength = sizeof loopback_config, .bLength = sizeof loopback_config,
.bDescriptorType = USB_DT_CONFIG, .bDescriptorType = USB_DT_CONFIG,
...@@ -218,8 +213,7 @@ loopback_config = { ...@@ -218,8 +213,7 @@ loopback_config = {
.bMaxPower = 1, /* self-powered */ .bMaxPower = 1, /* self-powered */
}; };
static struct usb_otg_descriptor static struct usb_otg_descriptor otg_descriptor = {
otg_descriptor = {
.bLength = sizeof otg_descriptor, .bLength = sizeof otg_descriptor,
.bDescriptorType = USB_DT_OTG, .bDescriptorType = USB_DT_OTG,
...@@ -228,8 +222,7 @@ otg_descriptor = { ...@@ -228,8 +222,7 @@ otg_descriptor = {
/* one interface in each configuration */ /* one interface in each configuration */
static const struct usb_interface_descriptor static const struct usb_interface_descriptor source_sink_intf = {
source_sink_intf = {
.bLength = sizeof source_sink_intf, .bLength = sizeof source_sink_intf,
.bDescriptorType = USB_DT_INTERFACE, .bDescriptorType = USB_DT_INTERFACE,
...@@ -238,8 +231,7 @@ source_sink_intf = { ...@@ -238,8 +231,7 @@ source_sink_intf = {
.iInterface = STRING_SOURCE_SINK, .iInterface = STRING_SOURCE_SINK,
}; };
static const struct usb_interface_descriptor static const struct usb_interface_descriptor loopback_intf = {
loopback_intf = {
.bLength = sizeof loopback_intf, .bLength = sizeof loopback_intf,
.bDescriptorType = USB_DT_INTERFACE, .bDescriptorType = USB_DT_INTERFACE,
...@@ -250,8 +242,7 @@ loopback_intf = { ...@@ -250,8 +242,7 @@ loopback_intf = {
/* two full speed bulk endpoints; their use is config-dependent */ /* two full speed bulk endpoints; their use is config-dependent */
static struct usb_endpoint_descriptor static struct usb_endpoint_descriptor fs_source_desc = {
fs_source_desc = {
.bLength = USB_DT_ENDPOINT_SIZE, .bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT, .bDescriptorType = USB_DT_ENDPOINT,
...@@ -259,8 +250,7 @@ fs_source_desc = { ...@@ -259,8 +250,7 @@ fs_source_desc = {
.bmAttributes = USB_ENDPOINT_XFER_BULK, .bmAttributes = USB_ENDPOINT_XFER_BULK,
}; };
static struct usb_endpoint_descriptor static struct usb_endpoint_descriptor fs_sink_desc = {
fs_sink_desc = {
.bLength = USB_DT_ENDPOINT_SIZE, .bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT, .bDescriptorType = USB_DT_ENDPOINT,
...@@ -268,7 +258,7 @@ fs_sink_desc = { ...@@ -268,7 +258,7 @@ fs_sink_desc = {
.bmAttributes = USB_ENDPOINT_XFER_BULK, .bmAttributes = USB_ENDPOINT_XFER_BULK,
}; };
static const struct usb_descriptor_header *fs_source_sink_function [] = { static const struct usb_descriptor_header *fs_source_sink_function[] = {
(struct usb_descriptor_header *) &otg_descriptor, (struct usb_descriptor_header *) &otg_descriptor,
(struct usb_descriptor_header *) &source_sink_intf, (struct usb_descriptor_header *) &source_sink_intf,
(struct usb_descriptor_header *) &fs_sink_desc, (struct usb_descriptor_header *) &fs_sink_desc,
...@@ -276,7 +266,7 @@ static const struct usb_descriptor_header *fs_source_sink_function [] = { ...@@ -276,7 +266,7 @@ static const struct usb_descriptor_header *fs_source_sink_function [] = {
NULL, NULL,
}; };
static const struct usb_descriptor_header *fs_loopback_function [] = { static const struct usb_descriptor_header *fs_loopback_function[] = {
(struct usb_descriptor_header *) &otg_descriptor, (struct usb_descriptor_header *) &otg_descriptor,
(struct usb_descriptor_header *) &loopback_intf, (struct usb_descriptor_header *) &loopback_intf,
(struct usb_descriptor_header *) &fs_sink_desc, (struct usb_descriptor_header *) &fs_sink_desc,
...@@ -293,36 +283,33 @@ static const struct usb_descriptor_header *fs_loopback_function [] = { ...@@ -293,36 +283,33 @@ static const struct usb_descriptor_header *fs_loopback_function [] = {
* for the config descriptor. * for the config descriptor.
*/ */
static struct usb_endpoint_descriptor static struct usb_endpoint_descriptor hs_source_desc = {
hs_source_desc = {
.bLength = USB_DT_ENDPOINT_SIZE, .bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT, .bDescriptorType = USB_DT_ENDPOINT,
.bmAttributes = USB_ENDPOINT_XFER_BULK, .bmAttributes = USB_ENDPOINT_XFER_BULK,
.wMaxPacketSize = __constant_cpu_to_le16 (512), .wMaxPacketSize = __constant_cpu_to_le16(512),
}; };
static struct usb_endpoint_descriptor static struct usb_endpoint_descriptor hs_sink_desc = {
hs_sink_desc = {
.bLength = USB_DT_ENDPOINT_SIZE, .bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT, .bDescriptorType = USB_DT_ENDPOINT,
.bmAttributes = USB_ENDPOINT_XFER_BULK, .bmAttributes = USB_ENDPOINT_XFER_BULK,
.wMaxPacketSize = __constant_cpu_to_le16 (512), .wMaxPacketSize = __constant_cpu_to_le16(512),
}; };
static struct usb_qualifier_descriptor static struct usb_qualifier_descriptor dev_qualifier = {
dev_qualifier = {
.bLength = sizeof dev_qualifier, .bLength = sizeof dev_qualifier,
.bDescriptorType = USB_DT_DEVICE_QUALIFIER, .bDescriptorType = USB_DT_DEVICE_QUALIFIER,
.bcdUSB = __constant_cpu_to_le16 (0x0200), .bcdUSB = __constant_cpu_to_le16(0x0200),
.bDeviceClass = USB_CLASS_VENDOR_SPEC, .bDeviceClass = USB_CLASS_VENDOR_SPEC,
.bNumConfigurations = 2, .bNumConfigurations = 2,
}; };
static const struct usb_descriptor_header *hs_source_sink_function [] = { static const struct usb_descriptor_header *hs_source_sink_function[] = {
(struct usb_descriptor_header *) &otg_descriptor, (struct usb_descriptor_header *) &otg_descriptor,
(struct usb_descriptor_header *) &source_sink_intf, (struct usb_descriptor_header *) &source_sink_intf,
(struct usb_descriptor_header *) &hs_source_desc, (struct usb_descriptor_header *) &hs_source_desc,
...@@ -330,7 +317,7 @@ static const struct usb_descriptor_header *hs_source_sink_function [] = { ...@@ -330,7 +317,7 @@ static const struct usb_descriptor_header *hs_source_sink_function [] = {
NULL, NULL,
}; };
static const struct usb_descriptor_header *hs_loopback_function [] = { static const struct usb_descriptor_header *hs_loopback_function[] = {
(struct usb_descriptor_header *) &otg_descriptor, (struct usb_descriptor_header *) &otg_descriptor,
(struct usb_descriptor_header *) &loopback_intf, (struct usb_descriptor_header *) &loopback_intf,
(struct usb_descriptor_header *) &hs_source_desc, (struct usb_descriptor_header *) &hs_source_desc,
...@@ -355,7 +342,7 @@ static char serial[] = "0123456789.0123456789.0123456789"; ...@@ -355,7 +342,7 @@ static char serial[] = "0123456789.0123456789.0123456789";
/* static strings, in UTF-8 */ /* static strings, in UTF-8 */
static struct usb_string strings [] = { static struct usb_string strings[] = {
{ STRING_MANUFACTURER, manufacturer, }, { STRING_MANUFACTURER, manufacturer, },
{ STRING_PRODUCT, longname, }, { STRING_PRODUCT, longname, },
{ STRING_SERIAL, serial, }, { STRING_SERIAL, serial, },
...@@ -364,7 +351,7 @@ static struct usb_string strings [] = { ...@@ -364,7 +351,7 @@ static struct usb_string strings [] = {
{ } /* end of list */ { } /* end of list */
}; };
static struct usb_gadget_strings stringtab = { static struct usb_gadget_strings stringtab = {
.language = 0x0409, /* en-us */ .language = 0x0409, /* en-us */
.strings = strings, .strings = strings,
}; };
...@@ -387,8 +374,7 @@ static struct usb_gadget_strings stringtab = { ...@@ -387,8 +374,7 @@ static struct usb_gadget_strings stringtab = {
* high bandwidth modes at high speed. (Maybe work like Intel's test * high bandwidth modes at high speed. (Maybe work like Intel's test
* device?) * device?)
*/ */
static int static int config_buf(struct usb_gadget *gadget,
config_buf (struct usb_gadget *gadget,
u8 *buf, u8 type, unsigned index) u8 *buf, u8 type, unsigned index)
{ {
int is_source_sink; int is_source_sink;
...@@ -419,7 +405,7 @@ config_buf (struct usb_gadget *gadget, ...@@ -419,7 +405,7 @@ config_buf (struct usb_gadget *gadget,
if (!gadget_is_otg(gadget)) if (!gadget_is_otg(gadget))
function++; function++;
len = usb_gadget_config_buf (is_source_sink len = usb_gadget_config_buf(is_source_sink
? &source_sink_config ? &source_sink_config
: &loopback_config, : &loopback_config,
buf, USB_BUFSIZ, function); buf, USB_BUFSIZ, function);
...@@ -431,27 +417,26 @@ config_buf (struct usb_gadget *gadget, ...@@ -431,27 +417,26 @@ config_buf (struct usb_gadget *gadget,
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
static struct usb_request * static struct usb_request *alloc_ep_req(struct usb_ep *ep, unsigned length)
alloc_ep_req (struct usb_ep *ep, unsigned length)
{ {
struct usb_request *req; struct usb_request *req;
req = usb_ep_alloc_request (ep, GFP_ATOMIC); req = usb_ep_alloc_request(ep, GFP_ATOMIC);
if (req) { if (req) {
req->length = length; req->length = length;
req->buf = kmalloc(length, GFP_ATOMIC); req->buf = kmalloc(length, GFP_ATOMIC);
if (!req->buf) { if (!req->buf) {
usb_ep_free_request (ep, req); usb_ep_free_request(ep, req);
req = NULL; req = NULL;
} }
} }
return req; return req;
} }
static void free_ep_req (struct usb_ep *ep, struct usb_request *req) static void free_ep_req(struct usb_ep *ep, struct usb_request *req)
{ {
kfree(req->buf); kfree(req->buf);
usb_ep_free_request (ep, req); usb_ep_free_request(ep, req);
} }
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
...@@ -472,7 +457,7 @@ static void free_ep_req (struct usb_ep *ep, struct usb_request *req) ...@@ -472,7 +457,7 @@ static void free_ep_req (struct usb_ep *ep, struct usb_request *req)
/* optionally require specific source/sink data patterns */ /* optionally require specific source/sink data patterns */
static int static int
check_read_data ( check_read_data(
struct zero_dev *dev, struct zero_dev *dev,
struct usb_ep *ep, struct usb_ep *ep,
struct usb_request *req struct usb_request *req
...@@ -498,8 +483,8 @@ check_read_data ( ...@@ -498,8 +483,8 @@ check_read_data (
continue; continue;
break; break;
} }
ERROR (dev, "bad OUT byte, buf [%d] = %d\n", i, *buf); ERROR(dev, "bad OUT byte, buf[%d] = %d\n", i, *buf);
usb_ep_set_halt (ep); usb_ep_set_halt(ep);
return -EINVAL; return -EINVAL;
} }
return 0; return 0;
...@@ -512,7 +497,7 @@ static void reinit_write_data(struct usb_ep *ep, struct usb_request *req) ...@@ -512,7 +497,7 @@ static void reinit_write_data(struct usb_ep *ep, struct usb_request *req)
switch (pattern) { switch (pattern) {
case 0: case 0:
memset (req->buf, 0, req->length); memset(req->buf, 0, req->length);
break; break;
case 1: case 1:
for (i = 0; i < req->length; i++) for (i = 0; i < req->length; i++)
...@@ -525,7 +510,7 @@ static void reinit_write_data(struct usb_ep *ep, struct usb_request *req) ...@@ -525,7 +510,7 @@ static void reinit_write_data(struct usb_ep *ep, struct usb_request *req)
* irq delay between end of one request and start of the next. * irq delay between end of one request and start of the next.
* that prevents using hardware dma queues. * that prevents using hardware dma queues.
*/ */
static void source_sink_complete (struct usb_ep *ep, struct usb_request *req) static void source_sink_complete(struct usb_ep *ep, struct usb_request *req)
{ {
struct zero_dev *dev = ep->driver_data; struct zero_dev *dev = ep->driver_data;
int status = req->status; int status = req->status;
...@@ -534,8 +519,8 @@ static void source_sink_complete (struct usb_ep *ep, struct usb_request *req) ...@@ -534,8 +519,8 @@ static void source_sink_complete (struct usb_ep *ep, struct usb_request *req)
case 0: /* normal completion? */ case 0: /* normal completion? */
if (ep == dev->out_ep) { if (ep == dev->out_ep) {
check_read_data (dev, ep, req); check_read_data(dev, ep, req);
memset (req->buf, 0x55, req->length); memset(req->buf, 0x55, req->length);
} else } else
reinit_write_data(ep, req); reinit_write_data(ep, req);
break; break;
...@@ -544,11 +529,11 @@ static void source_sink_complete (struct usb_ep *ep, struct usb_request *req) ...@@ -544,11 +529,11 @@ static void source_sink_complete (struct usb_ep *ep, struct usb_request *req)
case -ECONNABORTED: /* hardware forced ep reset */ case -ECONNABORTED: /* hardware forced ep reset */
case -ECONNRESET: /* request dequeued */ case -ECONNRESET: /* request dequeued */
case -ESHUTDOWN: /* disconnect from host */ case -ESHUTDOWN: /* disconnect from host */
VDBG (dev, "%s gone (%d), %d/%d\n", ep->name, status, VDBG(dev, "%s gone (%d), %d/%d\n", ep->name, status,
req->actual, req->length); req->actual, req->length);
if (ep == dev->out_ep) if (ep == dev->out_ep)
check_read_data (dev, ep, req); check_read_data(dev, ep, req);
free_ep_req (ep, req); free_ep_req(ep, req);
return; return;
case -EOVERFLOW: /* buffer overrun on read means that case -EOVERFLOW: /* buffer overrun on read means that
...@@ -557,18 +542,18 @@ static void source_sink_complete (struct usb_ep *ep, struct usb_request *req) ...@@ -557,18 +542,18 @@ static void source_sink_complete (struct usb_ep *ep, struct usb_request *req)
*/ */
default: default:
#if 1 #if 1
DBG (dev, "%s complete --> %d, %d/%d\n", ep->name, DBG(dev, "%s complete --> %d, %d/%d\n", ep->name,
status, req->actual, req->length); status, req->actual, req->length);
#endif #endif
case -EREMOTEIO: /* short read */ case -EREMOTEIO: /* short read */
break; break;
} }
status = usb_ep_queue (ep, req, GFP_ATOMIC); status = usb_ep_queue(ep, req, GFP_ATOMIC);
if (status) { if (status) {
ERROR (dev, "kill %s: resubmit %d bytes --> %d\n", ERROR(dev, "kill %s: resubmit %d bytes --> %d\n",
ep->name, req->length, status); ep->name, req->length, status);
usb_ep_set_halt (ep); usb_ep_set_halt(ep);
/* FIXME recover later ... somehow */ /* FIXME recover later ... somehow */
} }
} }
...@@ -578,24 +563,24 @@ static struct usb_request *source_sink_start_ep(struct usb_ep *ep) ...@@ -578,24 +563,24 @@ static struct usb_request *source_sink_start_ep(struct usb_ep *ep)
struct usb_request *req; struct usb_request *req;
int status; int status;
req = alloc_ep_req (ep, buflen); req = alloc_ep_req(ep, buflen);
if (!req) if (!req)
return NULL; return NULL;
memset (req->buf, 0, req->length); memset(req->buf, 0, req->length);
req->complete = source_sink_complete; req->complete = source_sink_complete;
if (strcmp (ep->name, EP_IN_NAME) == 0) if (strcmp(ep->name, EP_IN_NAME) == 0)
reinit_write_data(ep, req); reinit_write_data(ep, req);
else else
memset (req->buf, 0x55, req->length); memset(req->buf, 0x55, req->length);
status = usb_ep_queue(ep, req, GFP_ATOMIC); status = usb_ep_queue(ep, req, GFP_ATOMIC);
if (status) { if (status) {
struct zero_dev *dev = ep->driver_data; struct zero_dev *dev = ep->driver_data;
ERROR (dev, "start %s --> %d\n", ep->name, status); ERROR(dev, "start %s --> %d\n", ep->name, status);
free_ep_req (ep, req); free_ep_req(ep, req);
req = NULL; req = NULL;
} }
...@@ -608,34 +593,34 @@ static int set_source_sink_config(struct zero_dev *dev) ...@@ -608,34 +593,34 @@ static int set_source_sink_config(struct zero_dev *dev)
struct usb_ep *ep; struct usb_ep *ep;
struct usb_gadget *gadget = dev->gadget; struct usb_gadget *gadget = dev->gadget;
gadget_for_each_ep (ep, gadget) { gadget_for_each_ep(ep, gadget) {
const struct usb_endpoint_descriptor *d; const struct usb_endpoint_descriptor *d;
/* one endpoint writes (sources) zeroes in (to the host) */ /* one endpoint writes (sources) zeroes in (to the host) */
if (strcmp (ep->name, EP_IN_NAME) == 0) { if (strcmp(ep->name, EP_IN_NAME) == 0) {
d = ep_desc (gadget, &hs_source_desc, &fs_source_desc); d = ep_desc(gadget, &hs_source_desc, &fs_source_desc);
result = usb_ep_enable (ep, d); result = usb_ep_enable(ep, d);
if (result == 0) { if (result == 0) {
ep->driver_data = dev; ep->driver_data = dev;
if (source_sink_start_ep(ep) != NULL) { if (source_sink_start_ep(ep) != NULL) {
dev->in_ep = ep; dev->in_ep = ep;
continue; continue;
} }
usb_ep_disable (ep); usb_ep_disable(ep);
result = -EIO; result = -EIO;
} }
/* one endpoint reads (sinks) anything out (from the host) */ /* one endpoint reads (sinks) anything out (from the host) */
} else if (strcmp (ep->name, EP_OUT_NAME) == 0) { } else if (strcmp(ep->name, EP_OUT_NAME) == 0) {
d = ep_desc (gadget, &hs_sink_desc, &fs_sink_desc); d = ep_desc(gadget, &hs_sink_desc, &fs_sink_desc);
result = usb_ep_enable (ep, d); result = usb_ep_enable(ep, d);
if (result == 0) { if (result == 0) {
ep->driver_data = dev; ep->driver_data = dev;
if (source_sink_start_ep(ep) != NULL) { if (source_sink_start_ep(ep) != NULL) {
dev->out_ep = ep; dev->out_ep = ep;
continue; continue;
} }
usb_ep_disable (ep); usb_ep_disable(ep);
result = -EIO; result = -EIO;
} }
...@@ -644,11 +629,11 @@ static int set_source_sink_config(struct zero_dev *dev) ...@@ -644,11 +629,11 @@ static int set_source_sink_config(struct zero_dev *dev)
continue; continue;
/* stop on error */ /* stop on error */
ERROR (dev, "can't start %s, result %d\n", ep->name, result); ERROR(dev, "can't start %s, result %d\n", ep->name, result);
break; break;
} }
if (result == 0) if (result == 0)
DBG (dev, "buflen %d\n", buflen); DBG(dev, "buflen %d\n", buflen);
/* caller is responsible for cleanup on error */ /* caller is responsible for cleanup on error */
return result; return result;
...@@ -656,7 +641,7 @@ static int set_source_sink_config(struct zero_dev *dev) ...@@ -656,7 +641,7 @@ static int set_source_sink_config(struct zero_dev *dev)
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
static void loopback_complete (struct usb_ep *ep, struct usb_request *req) static void loopback_complete(struct usb_ep *ep, struct usb_request *req)
{ {
struct zero_dev *dev = ep->driver_data; struct zero_dev *dev = ep->driver_data;
int status = req->status; int status = req->status;
...@@ -668,19 +653,19 @@ static void loopback_complete (struct usb_ep *ep, struct usb_request *req) ...@@ -668,19 +653,19 @@ static void loopback_complete (struct usb_ep *ep, struct usb_request *req)
/* loop this OUT packet back IN to the host */ /* loop this OUT packet back IN to the host */
req->zero = (req->actual < req->length); req->zero = (req->actual < req->length);
req->length = req->actual; req->length = req->actual;
status = usb_ep_queue (dev->in_ep, req, GFP_ATOMIC); status = usb_ep_queue(dev->in_ep, req, GFP_ATOMIC);
if (status == 0) if (status == 0)
return; return;
/* "should never get here" */ /* "should never get here" */
ERROR (dev, "can't loop %s to %s: %d\n", ERROR(dev, "can't loop %s to %s: %d\n",
ep->name, dev->in_ep->name, ep->name, dev->in_ep->name,
status); status);
} }
/* queue the buffer for some later OUT packet */ /* queue the buffer for some later OUT packet */
req->length = buflen; req->length = buflen;
status = usb_ep_queue (dev->out_ep, req, GFP_ATOMIC); status = usb_ep_queue(dev->out_ep, req, GFP_ATOMIC);
if (status == 0) if (status == 0)
return; return;
...@@ -688,7 +673,7 @@ static void loopback_complete (struct usb_ep *ep, struct usb_request *req) ...@@ -688,7 +673,7 @@ static void loopback_complete (struct usb_ep *ep, struct usb_request *req)
/* FALLTHROUGH */ /* FALLTHROUGH */
default: default:
ERROR (dev, "%s loop complete --> %d, %d/%d\n", ep->name, ERROR(dev, "%s loop complete --> %d, %d/%d\n", ep->name,
status, req->actual, req->length); status, req->actual, req->length);
/* FALLTHROUGH */ /* FALLTHROUGH */
...@@ -700,7 +685,7 @@ static void loopback_complete (struct usb_ep *ep, struct usb_request *req) ...@@ -700,7 +685,7 @@ static void loopback_complete (struct usb_ep *ep, struct usb_request *req)
case -ECONNABORTED: /* hardware forced ep reset */ case -ECONNABORTED: /* hardware forced ep reset */
case -ECONNRESET: /* request dequeued */ case -ECONNRESET: /* request dequeued */
case -ESHUTDOWN: /* disconnect from host */ case -ESHUTDOWN: /* disconnect from host */
free_ep_req (ep, req); free_ep_req(ep, req);
return; return;
} }
} }
...@@ -711,13 +696,13 @@ static int set_loopback_config(struct zero_dev *dev) ...@@ -711,13 +696,13 @@ static int set_loopback_config(struct zero_dev *dev)
struct usb_ep *ep; struct usb_ep *ep;
struct usb_gadget *gadget = dev->gadget; struct usb_gadget *gadget = dev->gadget;
gadget_for_each_ep (ep, gadget) { gadget_for_each_ep(ep, gadget) {
const struct usb_endpoint_descriptor *d; const struct usb_endpoint_descriptor *d;
/* one endpoint writes data back IN to the host */ /* one endpoint writes data back IN to the host */
if (strcmp (ep->name, EP_IN_NAME) == 0) { if (strcmp(ep->name, EP_IN_NAME) == 0) {
d = ep_desc (gadget, &hs_source_desc, &fs_source_desc); d = ep_desc(gadget, &hs_source_desc, &fs_source_desc);
result = usb_ep_enable (ep, d); result = usb_ep_enable(ep, d);
if (result == 0) { if (result == 0) {
ep->driver_data = dev; ep->driver_data = dev;
dev->in_ep = ep; dev->in_ep = ep;
...@@ -725,9 +710,9 @@ static int set_loopback_config(struct zero_dev *dev) ...@@ -725,9 +710,9 @@ static int set_loopback_config(struct zero_dev *dev)
} }
/* one endpoint just reads OUT packets */ /* one endpoint just reads OUT packets */
} else if (strcmp (ep->name, EP_OUT_NAME) == 0) { } else if (strcmp(ep->name, EP_OUT_NAME) == 0) {
d = ep_desc (gadget, &hs_sink_desc, &fs_sink_desc); d = ep_desc(gadget, &hs_sink_desc, &fs_sink_desc);
result = usb_ep_enable (ep, d); result = usb_ep_enable(ep, d);
if (result == 0) { if (result == 0) {
ep->driver_data = dev; ep->driver_data = dev;
dev->out_ep = ep; dev->out_ep = ep;
...@@ -739,7 +724,7 @@ static int set_loopback_config(struct zero_dev *dev) ...@@ -739,7 +724,7 @@ static int set_loopback_config(struct zero_dev *dev)
continue; continue;
/* stop on error */ /* stop on error */
ERROR (dev, "can't enable %s, result %d\n", ep->name, result); ERROR(dev, "can't enable %s, result %d\n", ep->name, result);
break; break;
} }
...@@ -753,19 +738,19 @@ static int set_loopback_config(struct zero_dev *dev) ...@@ -753,19 +738,19 @@ static int set_loopback_config(struct zero_dev *dev)
ep = dev->out_ep; ep = dev->out_ep;
for (i = 0; i < qlen && result == 0; i++) { for (i = 0; i < qlen && result == 0; i++) {
req = alloc_ep_req (ep, buflen); req = alloc_ep_req(ep, buflen);
if (req) { if (req) {
req->complete = loopback_complete; req->complete = loopback_complete;
result = usb_ep_queue (ep, req, GFP_ATOMIC); result = usb_ep_queue(ep, req, GFP_ATOMIC);
if (result) if (result)
DBG (dev, "%s queue req --> %d\n", DBG(dev, "%s queue req --> %d\n",
ep->name, result); ep->name, result);
} else } else
result = -ENOMEM; result = -ENOMEM;
} }
} }
if (result == 0) if (result == 0)
DBG (dev, "qlen %d, buflen %d\n", qlen, buflen); DBG(dev, "qlen %d, buflen %d\n", qlen, buflen);
/* caller is responsible for cleanup on error */ /* caller is responsible for cleanup on error */
return result; return result;
...@@ -773,26 +758,26 @@ static int set_loopback_config(struct zero_dev *dev) ...@@ -773,26 +758,26 @@ static int set_loopback_config(struct zero_dev *dev)
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
static void zero_reset_config (struct zero_dev *dev) static void zero_reset_config(struct zero_dev *dev)
{ {
if (dev->config == 0) if (dev->config == 0)
return; return;
DBG (dev, "reset config\n"); DBG(dev, "reset config\n");
/* just disable endpoints, forcing completion of pending i/o. /* just disable endpoints, forcing completion of pending i/o.
* all our completion handlers free their requests in this case. * all our completion handlers free their requests in this case.
*/ */
if (dev->in_ep) { if (dev->in_ep) {
usb_ep_disable (dev->in_ep); usb_ep_disable(dev->in_ep);
dev->in_ep = NULL; dev->in_ep = NULL;
} }
if (dev->out_ep) { if (dev->out_ep) {
usb_ep_disable (dev->out_ep); usb_ep_disable(dev->out_ep);
dev->out_ep = NULL; dev->out_ep = NULL;
} }
dev->config = 0; dev->config = 0;
del_timer (&dev->resume); del_timer(&dev->resume);
} }
/* change our operational config. this code must agree with the code /* change our operational config. this code must agree with the code
...@@ -813,12 +798,12 @@ static int zero_set_config(struct zero_dev *dev, unsigned number) ...@@ -813,12 +798,12 @@ static int zero_set_config(struct zero_dev *dev, unsigned number)
if (number == dev->config) if (number == dev->config)
return 0; return 0;
if (gadget_is_sa1100 (gadget) && dev->config) { if (gadget_is_sa1100(gadget) && dev->config) {
/* tx fifo is full, but we can't clear it...*/ /* tx fifo is full, but we can't clear it...*/
ERROR(dev, "can't change configurations\n"); ERROR(dev, "can't change configurations\n");
return -ESPIPE; return -ESPIPE;
} }
zero_reset_config (dev); zero_reset_config(dev);
switch (number) { switch (number) {
case CONFIG_SOURCE_SINK: case CONFIG_SOURCE_SINK:
...@@ -837,7 +822,7 @@ static int zero_set_config(struct zero_dev *dev, unsigned number) ...@@ -837,7 +822,7 @@ static int zero_set_config(struct zero_dev *dev, unsigned number)
if (!result && (!dev->in_ep || !dev->out_ep)) if (!result && (!dev->in_ep || !dev->out_ep))
result = -ENODEV; result = -ENODEV;
if (result) if (result)
zero_reset_config (dev); zero_reset_config(dev);
else { else {
char *speed; char *speed;
...@@ -849,7 +834,7 @@ static int zero_set_config(struct zero_dev *dev, unsigned number) ...@@ -849,7 +834,7 @@ static int zero_set_config(struct zero_dev *dev, unsigned number)
} }
dev->config = number; dev->config = number;
INFO (dev, "%s speed config #%d: %s\n", speed, number, INFO(dev, "%s speed config #%d: %s\n", speed, number,
(number == CONFIG_SOURCE_SINK) (number == CONFIG_SOURCE_SINK)
? source_sink : loopback); ? source_sink : loopback);
} }
...@@ -858,10 +843,10 @@ static int zero_set_config(struct zero_dev *dev, unsigned number) ...@@ -858,10 +843,10 @@ static int zero_set_config(struct zero_dev *dev, unsigned number)
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
static void zero_setup_complete (struct usb_ep *ep, struct usb_request *req) static void zero_setup_complete(struct usb_ep *ep, struct usb_request *req)
{ {
if (req->status || req->actual != req->length) if (req->status || req->actual != req->length)
DBG ((struct zero_dev *) ep->driver_data, DBG((struct zero_dev *) ep->driver_data,
"setup complete --> %d, %d/%d\n", "setup complete --> %d, %d/%d\n",
req->status, req->actual, req->length); req->status, req->actual, req->length);
} }
...@@ -874,9 +859,9 @@ static void zero_setup_complete (struct usb_ep *ep, struct usb_request *req) ...@@ -874,9 +859,9 @@ static void zero_setup_complete (struct usb_ep *ep, struct usb_request *req)
* the work is in config-specific setup. * the work is in config-specific setup.
*/ */
static int static int
zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) zero_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
{ {
struct zero_dev *dev = get_gadget_data (gadget); struct zero_dev *dev = get_gadget_data(gadget);
struct usb_request *req = dev->req; struct usb_request *req = dev->req;
int value = -EOPNOTSUPP; int value = -EOPNOTSUPP;
u16 w_index = le16_to_cpu(ctrl->wIndex); u16 w_index = le16_to_cpu(ctrl->wIndex);
...@@ -895,14 +880,14 @@ zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) ...@@ -895,14 +880,14 @@ zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
switch (w_value >> 8) { switch (w_value >> 8) {
case USB_DT_DEVICE: case USB_DT_DEVICE:
value = min (w_length, (u16) sizeof device_desc); value = min(w_length, (u16) sizeof device_desc);
memcpy (req->buf, &device_desc, value); memcpy(req->buf, &device_desc, value);
break; break;
case USB_DT_DEVICE_QUALIFIER: case USB_DT_DEVICE_QUALIFIER:
if (!gadget_is_dualspeed(gadget)) if (!gadget_is_dualspeed(gadget))
break; break;
value = min (w_length, (u16) sizeof dev_qualifier); value = min(w_length, (u16) sizeof dev_qualifier);
memcpy (req->buf, &dev_qualifier, value); memcpy(req->buf, &dev_qualifier, value);
break; break;
case USB_DT_OTHER_SPEED_CONFIG: case USB_DT_OTHER_SPEED_CONFIG:
...@@ -910,11 +895,11 @@ zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) ...@@ -910,11 +895,11 @@ zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
break; break;
// FALLTHROUGH // FALLTHROUGH
case USB_DT_CONFIG: case USB_DT_CONFIG:
value = config_buf (gadget, req->buf, value = config_buf(gadget, req->buf,
w_value >> 8, w_value >> 8,
w_value & 0xff); w_value & 0xff);
if (value >= 0) if (value >= 0)
value = min (w_length, (u16) value); value = min(w_length, (u16) value);
break; break;
case USB_DT_STRING: case USB_DT_STRING:
...@@ -923,10 +908,10 @@ zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) ...@@ -923,10 +908,10 @@ zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
* add string tables for other languages, using * add string tables for other languages, using
* any UTF-8 characters * any UTF-8 characters
*/ */
value = usb_gadget_get_string (&stringtab, value = usb_gadget_get_string(&stringtab,
w_value & 0xff, req->buf); w_value & 0xff, req->buf);
if (value >= 0) if (value >= 0)
value = min (w_length, (u16) value); value = min(w_length, (u16) value);
break; break;
} }
break; break;
...@@ -936,20 +921,20 @@ zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) ...@@ -936,20 +921,20 @@ zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
if (ctrl->bRequestType != 0) if (ctrl->bRequestType != 0)
goto unknown; goto unknown;
if (gadget->a_hnp_support) if (gadget->a_hnp_support)
DBG (dev, "HNP available\n"); DBG(dev, "HNP available\n");
else if (gadget->a_alt_hnp_support) else if (gadget->a_alt_hnp_support)
DBG (dev, "HNP needs a different root port\n"); DBG(dev, "HNP needs a different root port\n");
else else
VDBG (dev, "HNP inactive\n"); VDBG(dev, "HNP inactive\n");
spin_lock (&dev->lock); spin_lock(&dev->lock);
value = zero_set_config(dev, w_value); value = zero_set_config(dev, w_value);
spin_unlock (&dev->lock); spin_unlock(&dev->lock);
break; break;
case USB_REQ_GET_CONFIGURATION: case USB_REQ_GET_CONFIGURATION:
if (ctrl->bRequestType != USB_DIR_IN) if (ctrl->bRequestType != USB_DIR_IN)
goto unknown; goto unknown;
*(u8 *)req->buf = dev->config; *(u8 *)req->buf = dev->config;
value = min (w_length, (u16) 1); value = min(w_length, (u16) 1);
break; break;
/* until we add altsetting support, or other interfaces, /* until we add altsetting support, or other interfaces,
...@@ -959,7 +944,7 @@ zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) ...@@ -959,7 +944,7 @@ zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
case USB_REQ_SET_INTERFACE: case USB_REQ_SET_INTERFACE:
if (ctrl->bRequestType != USB_RECIP_INTERFACE) if (ctrl->bRequestType != USB_RECIP_INTERFACE)
goto unknown; goto unknown;
spin_lock (&dev->lock); spin_lock(&dev->lock);
if (dev->config && w_index == 0 && w_value == 0) { if (dev->config && w_index == 0 && w_value == 0) {
u8 config = dev->config; u8 config = dev->config;
...@@ -970,11 +955,11 @@ zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) ...@@ -970,11 +955,11 @@ zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
* if we had more than one interface we couldn't * if we had more than one interface we couldn't
* use this "reset the config" shortcut. * use this "reset the config" shortcut.
*/ */
zero_reset_config (dev); zero_reset_config(dev);
zero_set_config(dev, config); zero_set_config(dev, config);
value = 0; value = 0;
} }
spin_unlock (&dev->lock); spin_unlock(&dev->lock);
break; break;
case USB_REQ_GET_INTERFACE: case USB_REQ_GET_INTERFACE:
if (ctrl->bRequestType != (USB_DIR_IN|USB_RECIP_INTERFACE)) if (ctrl->bRequestType != (USB_DIR_IN|USB_RECIP_INTERFACE))
...@@ -986,7 +971,7 @@ zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) ...@@ -986,7 +971,7 @@ zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
break; break;
} }
*(u8 *)req->buf = 0; *(u8 *)req->buf = 0;
value = min (w_length, (u16) 1); value = min(w_length, (u16) 1);
break; break;
/* /*
...@@ -1018,7 +1003,7 @@ zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) ...@@ -1018,7 +1003,7 @@ zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
default: default:
unknown: unknown:
VDBG (dev, VDBG(dev,
"unknown control req%02x.%02x v%04x i%04x l%d\n", "unknown control req%02x.%02x v%04x i%04x l%d\n",
ctrl->bRequestType, ctrl->bRequest, ctrl->bRequestType, ctrl->bRequest,
w_value, w_index, w_length); w_value, w_index, w_length);
...@@ -1028,11 +1013,11 @@ zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) ...@@ -1028,11 +1013,11 @@ zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
if (value >= 0) { if (value >= 0) {
req->length = value; req->length = value;
req->zero = value < w_length; req->zero = value < w_length;
value = usb_ep_queue (gadget->ep0, req, GFP_ATOMIC); value = usb_ep_queue(gadget->ep0, req, GFP_ATOMIC);
if (value < 0) { if (value < 0) {
DBG (dev, "ep_queue --> %d\n", value); DBG(dev, "ep_queue --> %d\n", value);
req->status = 0; req->status = 0;
zero_setup_complete (gadget->ep0, req); zero_setup_complete(gadget->ep0, req);
} }
} }
...@@ -1040,28 +1025,26 @@ zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) ...@@ -1040,28 +1025,26 @@ zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
return value; return value;
} }
static void static void zero_disconnect(struct usb_gadget *gadget)
zero_disconnect (struct usb_gadget *gadget)
{ {
struct zero_dev *dev = get_gadget_data (gadget); struct zero_dev *dev = get_gadget_data(gadget);
unsigned long flags; unsigned long flags;
spin_lock_irqsave (&dev->lock, flags); spin_lock_irqsave(&dev->lock, flags);
zero_reset_config (dev); zero_reset_config(dev);
/* a more significant application might have some non-usb /* a more significant application might have some non-usb
* activities to quiesce here, saving resources like power * activities to quiesce here, saving resources like power
* or pushing the notification up a network stack. * or pushing the notification up a network stack.
*/ */
spin_unlock_irqrestore (&dev->lock, flags); spin_unlock_irqrestore(&dev->lock, flags);
/* next we may get setup() calls to enumerate new connections; /* next we may get setup() calls to enumerate new connections;
* or an unbind() during shutdown (including removing module). * or an unbind() during shutdown (including removing module).
*/ */
} }
static void static void zero_autoresume(unsigned long _dev)
zero_autoresume (unsigned long _dev)
{ {
struct zero_dev *dev = (struct zero_dev *) _dev; struct zero_dev *dev = (struct zero_dev *) _dev;
int status; int status;
...@@ -1070,32 +1053,30 @@ zero_autoresume (unsigned long _dev) ...@@ -1070,32 +1053,30 @@ zero_autoresume (unsigned long _dev)
* more significant than just a timer firing... * more significant than just a timer firing...
*/ */
if (dev->gadget->speed != USB_SPEED_UNKNOWN) { if (dev->gadget->speed != USB_SPEED_UNKNOWN) {
status = usb_gadget_wakeup (dev->gadget); status = usb_gadget_wakeup(dev->gadget);
DBG (dev, "wakeup --> %d\n", status); DBG(dev, "wakeup --> %d\n", status);
} }
} }
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
static void /* __init_or_exit */ static void zero_unbind(struct usb_gadget *gadget)
zero_unbind (struct usb_gadget *gadget)
{ {
struct zero_dev *dev = get_gadget_data (gadget); struct zero_dev *dev = get_gadget_data(gadget);
DBG (dev, "unbind\n"); DBG(dev, "unbind\n");
/* we've already been disconnected ... no i/o is active */ /* we've already been disconnected ... no i/o is active */
if (dev->req) { if (dev->req) {
dev->req->length = USB_BUFSIZ; dev->req->length = USB_BUFSIZ;
free_ep_req (gadget->ep0, dev->req); free_ep_req(gadget->ep0, dev->req);
} }
del_timer_sync (&dev->resume); del_timer_sync(&dev->resume);
kfree (dev); kfree(dev);
set_gadget_data (gadget, NULL); set_gadget_data(gadget, NULL);
} }
static int __init static int __init zero_bind(struct usb_gadget *gadget)
zero_bind (struct usb_gadget *gadget)
{ {
struct zero_dev *dev; struct zero_dev *dev;
struct usb_ep *ep; struct usb_ep *ep;
...@@ -1111,8 +1092,8 @@ zero_bind (struct usb_gadget *gadget) ...@@ -1111,8 +1092,8 @@ zero_bind (struct usb_gadget *gadget)
* autoconfigure on any sane usb controller driver, * autoconfigure on any sane usb controller driver,
* but there may also be important quirks to address. * but there may also be important quirks to address.
*/ */
usb_ep_autoconfig_reset (gadget); usb_ep_autoconfig_reset(gadget);
ep = usb_ep_autoconfig (gadget, &fs_source_desc); ep = usb_ep_autoconfig(gadget, &fs_source_desc);
if (!ep) { if (!ep) {
autoconf_fail: autoconf_fail:
pr_err("%s: can't autoconfigure on %s\n", pr_err("%s: can't autoconfigure on %s\n",
...@@ -1122,15 +1103,15 @@ zero_bind (struct usb_gadget *gadget) ...@@ -1122,15 +1103,15 @@ zero_bind (struct usb_gadget *gadget)
EP_IN_NAME = ep->name; EP_IN_NAME = ep->name;
ep->driver_data = ep; /* claim */ ep->driver_data = ep; /* claim */
ep = usb_ep_autoconfig (gadget, &fs_sink_desc); ep = usb_ep_autoconfig(gadget, &fs_sink_desc);
if (!ep) if (!ep)
goto autoconf_fail; goto autoconf_fail;
EP_OUT_NAME = ep->name; EP_OUT_NAME = ep->name;
ep->driver_data = ep; /* claim */ ep->driver_data = ep; /* claim */
gcnum = usb_gadget_controller_number (gadget); gcnum = usb_gadget_controller_number(gadget);
if (gcnum >= 0) if (gcnum >= 0)
device_desc.bcdDevice = cpu_to_le16 (0x0200 + gcnum); device_desc.bcdDevice = cpu_to_le16(0x0200 + gcnum);
else { else {
/* gadget zero is so simple (for now, no altsettings) that /* gadget zero is so simple (for now, no altsettings) that
* it SHOULD NOT have problems with bulk-capable hardware. * it SHOULD NOT have problems with bulk-capable hardware.
...@@ -1141,7 +1122,7 @@ zero_bind (struct usb_gadget *gadget) ...@@ -1141,7 +1122,7 @@ zero_bind (struct usb_gadget *gadget)
*/ */
pr_warning("%s: controller '%s' not recognized\n", pr_warning("%s: controller '%s' not recognized\n",
shortname, gadget->name); shortname, gadget->name);
device_desc.bcdDevice = __constant_cpu_to_le16 (0x9999); device_desc.bcdDevice = __constant_cpu_to_le16(0x9999);
} }
...@@ -1149,12 +1130,12 @@ zero_bind (struct usb_gadget *gadget) ...@@ -1149,12 +1130,12 @@ zero_bind (struct usb_gadget *gadget)
dev = kzalloc(sizeof(*dev), GFP_KERNEL); dev = kzalloc(sizeof(*dev), GFP_KERNEL);
if (!dev) if (!dev)
return -ENOMEM; return -ENOMEM;
spin_lock_init (&dev->lock); spin_lock_init(&dev->lock);
dev->gadget = gadget; dev->gadget = gadget;
set_gadget_data (gadget, dev); set_gadget_data(gadget, dev);
/* preallocate control response and buffer */ /* preallocate control response and buffer */
dev->req = usb_ep_alloc_request (gadget->ep0, GFP_KERNEL); dev->req = usb_ep_alloc_request(gadget->ep0, GFP_KERNEL);
if (!dev->req) if (!dev->req)
goto enomem; goto enomem;
dev->req->buf = kmalloc(USB_BUFSIZ, GFP_KERNEL); dev->req->buf = kmalloc(USB_BUFSIZ, GFP_KERNEL);
...@@ -1182,9 +1163,9 @@ zero_bind (struct usb_gadget *gadget) ...@@ -1182,9 +1163,9 @@ zero_bind (struct usb_gadget *gadget)
loopback_config.bmAttributes |= USB_CONFIG_ATT_WAKEUP; loopback_config.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
} }
usb_gadget_set_selfpowered (gadget); usb_gadget_set_selfpowered(gadget);
init_timer (&dev->resume); init_timer(&dev->resume);
dev->resume.function = zero_autoresume; dev->resume.function = zero_autoresume;
dev->resume.data = (unsigned long) dev; dev->resume.data = (unsigned long) dev;
if (autoresume) { if (autoresume) {
...@@ -1194,45 +1175,43 @@ zero_bind (struct usb_gadget *gadget) ...@@ -1194,45 +1175,43 @@ zero_bind (struct usb_gadget *gadget)
gadget->ep0->driver_data = dev; gadget->ep0->driver_data = dev;
INFO (dev, "%s, version: " DRIVER_VERSION "\n", longname); INFO(dev, "%s, version: " DRIVER_VERSION "\n", longname);
INFO (dev, "using %s, OUT %s IN %s\n", gadget->name, INFO(dev, "using %s, OUT %s IN %s\n", gadget->name,
EP_OUT_NAME, EP_IN_NAME); EP_OUT_NAME, EP_IN_NAME);
snprintf (manufacturer, sizeof manufacturer, "%s %s with %s", snprintf(manufacturer, sizeof manufacturer, "%s %s with %s",
init_utsname()->sysname, init_utsname()->release, init_utsname()->sysname, init_utsname()->release,
gadget->name); gadget->name);
return 0; return 0;
enomem: enomem:
zero_unbind (gadget); zero_unbind(gadget);
return -ENOMEM; return -ENOMEM;
} }
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
static void static void zero_suspend(struct usb_gadget *gadget)
zero_suspend (struct usb_gadget *gadget)
{ {
struct zero_dev *dev = get_gadget_data (gadget); struct zero_dev *dev = get_gadget_data(gadget);
if (gadget->speed == USB_SPEED_UNKNOWN) if (gadget->speed == USB_SPEED_UNKNOWN)
return; return;
if (autoresume) { if (autoresume) {
mod_timer (&dev->resume, jiffies + (HZ * autoresume)); mod_timer(&dev->resume, jiffies + (HZ * autoresume));
DBG (dev, "suspend, wakeup in %d seconds\n", autoresume); DBG(dev, "suspend, wakeup in %d seconds\n", autoresume);
} else } else
DBG (dev, "suspend\n"); DBG(dev, "suspend\n");
} }
static void static void zero_resume(struct usb_gadget *gadget)
zero_resume (struct usb_gadget *gadget)
{ {
struct zero_dev *dev = get_gadget_data (gadget); struct zero_dev *dev = get_gadget_data(gadget);
DBG (dev, "resume\n"); DBG(dev, "resume\n");
del_timer (&dev->resume); del_timer(&dev->resume);
} }
...@@ -1264,15 +1243,15 @@ MODULE_AUTHOR("David Brownell"); ...@@ -1264,15 +1243,15 @@ MODULE_AUTHOR("David Brownell");
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
static int __init init (void) static int __init init(void)
{ {
return usb_gadget_register_driver (&zero_driver); return usb_gadget_register_driver(&zero_driver);
} }
module_init (init); module_init(init);
static void __exit cleanup (void) static void __exit cleanup(void)
{ {
usb_gadget_unregister_driver (&zero_driver); usb_gadget_unregister_driver(&zero_driver);
} }
module_exit (cleanup); module_exit(cleanup);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment