]> err.no Git - linux-2.6/blobdiff - drivers/usb/gadget/zero.c
Merge branch 'for-2.6.26' of master.kernel.org:/pub/scm/linux/kernel/git/jwboyer...
[linux-2.6] / drivers / usb / gadget / zero.c
index fcfe869acb942bb36dcb742666d285f7de0cd931..fce4924dbbe88b6c49dbea3fe33221e224aece05 100644 (file)
@@ -1,47 +1,29 @@
 /*
  * zero.c -- Gadget Zero, for USB development
  *
- * Copyright (C) 2003-2004 David Brownell
+ * Copyright (C) 2003-2007 David Brownell
  * All rights reserved.
  *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions, and the following disclaimer,
- *    without modification.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. The names of the above-listed copyright holders may not be used
- *    to endorse or promote products derived from this software without
- *    specific prior written permission.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
  *
- * ALTERNATIVELY, this software may be distributed under the terms of the
- * GNU General Public License ("GPL") as published by the Free Software
- * Foundation, either version 2 of that License or (at your option) any
- * later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
  *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
 
 /*
  * 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.
- *
- * Hardware details are visible (see CONFIG_USB_ZERO_* below) but don't
- * affect most of the driver.
+ * Some hardware details are visible, but don't affect most of the driver.
  *
  * 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".
  *   buflen=N          default N=4096, buffer size used
  *   qlen=N            default N=32, how many buffers in the loopback queue
  *   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
  * simpler if they also don't support high speed operation (like this
  * driver does).
+ *
+ * Why is *this* driver using two configurations, rather than setting up
+ * two interfaces with different functions?  To help verify that multiple
+ * configuration infrastucture is working correctly; also, so that it can
+ * work with low capability USB controllers without four bulk endpoints.
  */
 
-#define DEBUG 1
-// #define VERBOSE
+/* #define VERBOSE_DEBUG */
 
-#include <linux/module.h>
 #include <linux/kernel.h>
-#include <linux/delay.h>
-#include <linux/ioport.h>
-#include <linux/slab.h>
-#include <linux/errno.h>
-#include <linux/init.h>
-#include <linux/timer.h>
-#include <linux/list.h>
-#include <linux/interrupt.h>
 #include <linux/utsname.h>
 #include <linux/device.h>
-#include <linux/moduleparam.h>
-
-#include <asm/byteorder.h>
-#include <asm/io.h>
-#include <asm/irq.h>
-#include <asm/system.h>
-#include <asm/unaligned.h>
 
 #include <linux/usb/ch9.h>
-#include <linux/usb_gadget.h>
+#include <linux/usb/gadget.h>
 
 #include "gadget_chips.h"
 
 
 /*-------------------------------------------------------------------------*/
 
-#define DRIVER_VERSION         "St Patrick's Day 2004"
+#define DRIVER_VERSION         "Earth Day 2008"
 
-static const char shortname [] = "zero";
-static const char longname [] = "Gadget Zero";
+static const char shortname[] = "zero";
+static const char longname[] = "Gadget Zero";
 
-static const char source_sink [] = "source and sink data";
-static const char loopback [] = "loop input to output";
+static const char source_sink[] = "source and sink data";
+static const char loopback[] = "loop input to output";
 
 /*-------------------------------------------------------------------------*/
 
@@ -131,30 +102,16 @@ struct zero_dev {
        struct timer_list       resume;
 };
 
-#define xprintk(d,level,fmt,args...) \
-       dev_printk(level , &(d)->gadget->dev , fmt , ## args)
-
-#ifdef DEBUG
-#define DBG(dev,fmt,args...) \
-       xprintk(dev , KERN_DEBUG , fmt , ## args)
-#else
-#define DBG(dev,fmt,args...) \
-       do { } while (0)
-#endif /* DEBUG */
-
-#ifdef VERBOSE
-#define VDBG   DBG
-#else
-#define VDBG(dev,fmt,args...) \
-       do { } while (0)
-#endif /* VERBOSE */
-
-#define ERROR(dev,fmt,args...) \
-       xprintk(dev , KERN_ERR , fmt , ## args)
-#define WARN(dev,fmt,args...) \
-       xprintk(dev , KERN_WARNING , fmt , ## args)
-#define INFO(dev,fmt,args...) \
-       xprintk(dev , KERN_INFO , fmt , ## args)
+#define DBG(d, fmt, args...) \
+       dev_dbg(&(d)->gadget->dev , fmt , ## args)
+#define VDBG(d, fmt, args...) \
+       dev_vdbg(&(d)->gadget->dev , fmt , ## args)
+#define ERROR(d, fmt, args...) \
+       dev_err(&(d)->gadget->dev , fmt , ## args)
+#define WARN(d, fmt, args...) \
+       dev_warn(&(d)->gadget->dev , fmt , ## args)
+#define INFO(d, fmt, args...) \
+       dev_info(&(d)->gadget->dev , fmt , ## args)
 
 /*-------------------------------------------------------------------------*/
 
@@ -162,16 +119,16 @@ static unsigned buflen = 4096;
 static unsigned qlen = 32;
 static unsigned pattern = 0;
 
-module_param (buflen, uint, S_IRUGO);
-module_param (qlen, uint, S_IRUGO);
-module_param (pattern, uint, S_IRUGO|S_IWUSR);
+module_param(buflen, uint, S_IRUGO);
+module_param(qlen, uint, S_IRUGO);
+module_param(pattern, uint, S_IRUGO|S_IWUSR);
 
 /*
  * if it's nonzero, autoresume says how many seconds to wait
  * before trying to wake up the host after suspend.
  */
 static unsigned autoresume = 0;
-module_param (autoresume, uint, 0);
+module_param(autoresume, uint, 0);
 
 /*
  * Normally the "loopback" configuration is second (index 1) so
@@ -180,8 +137,7 @@ module_param (autoresume, uint, 0);
  * Or controllers (like superh) that only support one config.
  */
 static int loopdefault = 0;
-
-module_param (loopdefault, bool, S_IRUGO|S_IWUSR);
+module_param(loopdefault, bool, S_IRUGO|S_IWUSR);
 
 /*-------------------------------------------------------------------------*/
 
@@ -218,24 +174,22 @@ module_param (loopdefault, bool, S_IRUGO|S_IWUSR);
 #define        CONFIG_SOURCE_SINK      3
 #define        CONFIG_LOOPBACK         2
 
-static struct usb_device_descriptor
-device_desc = {
+static struct usb_device_descriptor device_desc = {
        .bLength =              sizeof device_desc,
        .bDescriptorType =      USB_DT_DEVICE,
 
-       .bcdUSB =               __constant_cpu_to_le16 (0x0200),
+       .bcdUSB =               __constant_cpu_to_le16(0x0200),
        .bDeviceClass =         USB_CLASS_VENDOR_SPEC,
 
-       .idVendor =             __constant_cpu_to_le16 (DRIVER_VENDOR_NUM),
-       .idProduct =            __constant_cpu_to_le16 (DRIVER_PRODUCT_NUM),
+       .idVendor =             __constant_cpu_to_le16(DRIVER_VENDOR_NUM),
+       .idProduct =            __constant_cpu_to_le16(DRIVER_PRODUCT_NUM),
        .iManufacturer =        STRING_MANUFACTURER,
        .iProduct =             STRING_PRODUCT,
        .iSerialNumber =        STRING_SERIAL,
        .bNumConfigurations =   2,
 };
 
-static struct usb_config_descriptor
-source_sink_config = {
+static struct usb_config_descriptor source_sink_config = {
        .bLength =              sizeof source_sink_config,
        .bDescriptorType =      USB_DT_CONFIG,
 
@@ -247,8 +201,7 @@ source_sink_config = {
        .bMaxPower =            1,      /* self-powered */
 };
 
-static struct usb_config_descriptor
-loopback_config = {
+static struct usb_config_descriptor loopback_config = {
        .bLength =              sizeof loopback_config,
        .bDescriptorType =      USB_DT_CONFIG,
 
@@ -260,8 +213,7 @@ loopback_config = {
        .bMaxPower =            1,      /* self-powered */
 };
 
-static struct usb_otg_descriptor
-otg_descriptor = {
+static struct usb_otg_descriptor otg_descriptor = {
        .bLength =              sizeof otg_descriptor,
        .bDescriptorType =      USB_DT_OTG,
 
@@ -270,8 +222,7 @@ otg_descriptor = {
 
 /* one interface in each configuration */
 
-static const struct usb_interface_descriptor
-source_sink_intf = {
+static const struct usb_interface_descriptor source_sink_intf = {
        .bLength =              sizeof source_sink_intf,
        .bDescriptorType =      USB_DT_INTERFACE,
 
@@ -280,8 +231,7 @@ source_sink_intf = {
        .iInterface =           STRING_SOURCE_SINK,
 };
 
-static const struct usb_interface_descriptor
-loopback_intf = {
+static const struct usb_interface_descriptor loopback_intf = {
        .bLength =              sizeof loopback_intf,
        .bDescriptorType =      USB_DT_INTERFACE,
 
@@ -292,8 +242,7 @@ loopback_intf = {
 
 /* two full speed bulk endpoints; their use is config-dependent */
 
-static struct usb_endpoint_descriptor
-fs_source_desc = {
+static struct usb_endpoint_descriptor fs_source_desc = {
        .bLength =              USB_DT_ENDPOINT_SIZE,
        .bDescriptorType =      USB_DT_ENDPOINT,
 
@@ -301,8 +250,7 @@ fs_source_desc = {
        .bmAttributes =         USB_ENDPOINT_XFER_BULK,
 };
 
-static struct usb_endpoint_descriptor
-fs_sink_desc = {
+static struct usb_endpoint_descriptor fs_sink_desc = {
        .bLength =              USB_DT_ENDPOINT_SIZE,
        .bDescriptorType =      USB_DT_ENDPOINT,
 
@@ -310,7 +258,7 @@ fs_sink_desc = {
        .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 *) &source_sink_intf,
        (struct usb_descriptor_header *) &fs_sink_desc,
@@ -318,7 +266,7 @@ static const struct usb_descriptor_header *fs_source_sink_function [] = {
        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 *) &loopback_intf,
        (struct usb_descriptor_header *) &fs_sink_desc,
@@ -326,8 +274,6 @@ static const struct usb_descriptor_header *fs_loopback_function [] = {
        NULL,
 };
 
-#ifdef CONFIG_USB_GADGET_DUALSPEED
-
 /*
  * usb 2.0 devices need to expose both high speed and full speed
  * descriptors, unless they only run at full speed.
@@ -337,36 +283,33 @@ static const struct usb_descriptor_header *fs_loopback_function [] = {
  * for the config descriptor.
  */
 
-static struct usb_endpoint_descriptor
-hs_source_desc = {
+static struct usb_endpoint_descriptor hs_source_desc = {
        .bLength =              USB_DT_ENDPOINT_SIZE,
        .bDescriptorType =      USB_DT_ENDPOINT,
 
        .bmAttributes =         USB_ENDPOINT_XFER_BULK,
-       .wMaxPacketSize =       __constant_cpu_to_le16 (512),
+       .wMaxPacketSize =       __constant_cpu_to_le16(512),
 };
 
-static struct usb_endpoint_descriptor
-hs_sink_desc = {
+static struct usb_endpoint_descriptor hs_sink_desc = {
        .bLength =              USB_DT_ENDPOINT_SIZE,
        .bDescriptorType =      USB_DT_ENDPOINT,
 
        .bmAttributes =         USB_ENDPOINT_XFER_BULK,
-       .wMaxPacketSize =       __constant_cpu_to_le16 (512),
+       .wMaxPacketSize =       __constant_cpu_to_le16(512),
 };
 
-static struct usb_qualifier_descriptor
-dev_qualifier = {
+static struct usb_qualifier_descriptor dev_qualifier = {
        .bLength =              sizeof dev_qualifier,
        .bDescriptorType =      USB_DT_DEVICE_QUALIFIER,
 
-       .bcdUSB =               __constant_cpu_to_le16 (0x0200),
+       .bcdUSB =               __constant_cpu_to_le16(0x0200),
        .bDeviceClass =         USB_CLASS_VENDOR_SPEC,
 
        .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 *) &source_sink_intf,
        (struct usb_descriptor_header *) &hs_source_desc,
@@ -374,7 +317,7 @@ static const struct usb_descriptor_header *hs_source_sink_function [] = {
        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 *) &loopback_intf,
        (struct usb_descriptor_header *) &hs_source_desc,
@@ -383,20 +326,23 @@ static const struct usb_descriptor_header *hs_loopback_function [] = {
 };
 
 /* maxpacket and other transfer characteristics vary by speed. */
-#define ep_desc(g,hs,fs) (((g)->speed==USB_SPEED_HIGH)?(hs):(fs))
-
-#else
+static inline struct usb_endpoint_descriptor *
+ep_desc(struct usb_gadget *g, struct usb_endpoint_descriptor *hs,
+               struct usb_endpoint_descriptor *fs)
+{
+       if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH)
+               return hs;
+       return fs;
+}
 
-/* if there's no high speed support, maxpacket doesn't change. */
-#define ep_desc(g,hs,fs) fs
+static char manufacturer[50];
 
-#endif /* !CONFIG_USB_GADGET_DUALSPEED */
+/* default serial number takes at least two packets */
+static char serial[] = "0123456789.0123456789.0123456789";
 
-static char                            manufacturer [50];
-static char                            serial [40];
 
 /* static strings, in UTF-8 */
-static struct usb_string               strings [] = {
+static struct usb_string strings[] = {
        { STRING_MANUFACTURER, manufacturer, },
        { STRING_PRODUCT, longname, },
        { STRING_SERIAL, serial, },
@@ -405,7 +351,7 @@ static struct usb_string            strings [] = {
        {  }                    /* end of list */
 };
 
-static struct usb_gadget_strings       stringtab = {
+static struct usb_gadget_strings stringtab = {
        .language       = 0x0409,       /* en-us */
        .strings        = strings,
 };
@@ -428,40 +374,38 @@ static struct usb_gadget_strings  stringtab = {
  * high bandwidth modes at high speed.  (Maybe work like Intel's test
  * device?)
  */
-static int
-config_buf (struct usb_gadget *gadget,
+static int config_buf(struct usb_gadget *gadget,
                u8 *buf, u8 type, unsigned index)
 {
        int                             is_source_sink;
        int                             len;
        const struct usb_descriptor_header **function;
-#ifdef CONFIG_USB_GADGET_DUALSPEED
-       int                             hs = (gadget->speed == USB_SPEED_HIGH);
-#endif
+       int                             hs = 0;
 
        /* two configurations will always be index 0 and index 1 */
        if (index > 1)
                return -EINVAL;
        is_source_sink = loopdefault ? (index == 1) : (index == 0);
 
-#ifdef CONFIG_USB_GADGET_DUALSPEED
-       if (type == USB_DT_OTHER_SPEED_CONFIG)
-               hs = !hs;
+       if (gadget_is_dualspeed(gadget)) {
+               hs = (gadget->speed == USB_SPEED_HIGH);
+               if (type == USB_DT_OTHER_SPEED_CONFIG)
+                       hs = !hs;
+       }
        if (hs)
                function = is_source_sink
                        ? hs_source_sink_function
                        : hs_loopback_function;
        else
-#endif
                function = is_source_sink
                        ? fs_source_sink_function
                        : fs_loopback_function;
 
        /* for now, don't advertise srp-only devices */
-       if (!gadget->is_otg)
+       if (!gadget_is_otg(gadget))
                function++;
 
-       len = usb_gadget_config_buf (is_source_sink
+       len = usb_gadget_config_buf(is_source_sink
                                        ? &source_sink_config
                                        : &loopback_config,
                        buf, USB_BUFSIZ, function);
@@ -473,35 +417,47 @@ config_buf (struct usb_gadget *gadget,
 
 /*-------------------------------------------------------------------------*/
 
-static struct usb_request *
-alloc_ep_req (struct usb_ep *ep, unsigned length)
+static struct usb_request *alloc_ep_req(struct usb_ep *ep, unsigned length)
 {
        struct usb_request      *req;
 
-       req = usb_ep_alloc_request (ep, GFP_ATOMIC);
+       req = usb_ep_alloc_request(ep, GFP_ATOMIC);
        if (req) {
                req->length = length;
                req->buf = kmalloc(length, GFP_ATOMIC);
                if (!req->buf) {
-                       usb_ep_free_request (ep, req);
+                       usb_ep_free_request(ep, req);
                        req = NULL;
                }
        }
        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);
-       usb_ep_free_request (ep, req);
+       usb_ep_free_request(ep, req);
 }
 
 /*-------------------------------------------------------------------------*/
 
+/*
+ * SOURCE/SINK FUNCTION ... a primary testing vehicle for USB peripherals,
+ * this just sinks bulk packets OUT to the peripheral and sources them IN
+ * to the host, optionally with specific data patterns.
+ *
+ * In terms of control messaging, this supports all the standard requests
+ * plus two that support control-OUT tests.
+ *
+ * Note that because this doesn't queue more than one request at a time,
+ * some other function must be used to test queueing logic.  The network
+ * link (g_ether) is probably the best option for that.
+ */
+
 /* optionally require specific source/sink data patterns  */
 
 static int
-check_read_data (
+check_read_data(
        struct zero_dev         *dev,
        struct usb_ep           *ep,
        struct usb_request      *req
@@ -527,26 +483,21 @@ check_read_data (
                                continue;
                        break;
                }
-               ERROR (dev, "bad OUT byte, buf [%d] = %d\n", i, *buf);
-               usb_ep_set_halt (ep);
+               ERROR(dev, "bad OUT byte, buf[%d] = %d\n", i, *buf);
+               usb_ep_set_halt(ep);
                return -EINVAL;
        }
        return 0;
 }
 
-static void
-reinit_write_data (
-       struct zero_dev         *dev,
-       struct usb_ep           *ep,
-       struct usb_request      *req
-)
+static void reinit_write_data(struct usb_ep *ep, struct usb_request *req)
 {
        unsigned        i;
        u8              *buf = req->buf;
 
        switch (pattern) {
        case 0:
-               memset (req->buf, 0, req->length);
+               memset(req->buf, 0, req->length);
                break;
        case 1:
                for  (i = 0; i < req->length; i++)
@@ -559,30 +510,30 @@ reinit_write_data (
  * irq delay between end of one request and start of the next.
  * 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;
        int             status = req->status;
 
        switch (status) {
 
-       case 0:                         /* normal completion? */
+       case 0:                         /* normal completion? */
                if (ep == dev->out_ep) {
-                       check_read_data (dev, ep, req);
-                       memset (req->buf, 0x55, req->length);
+                       check_read_data(dev, ep, req);
+                       memset(req->buf, 0x55, req->length);
                } else
-                       reinit_write_data (dev, ep, req);
+                       reinit_write_data(ep, req);
                break;
 
        /* this endpoint is normally active while we're configured */
-       case -ECONNABORTED:             /* hardware forced ep reset */
+       case -ECONNABORTED:             /* hardware forced ep reset */
        case -ECONNRESET:               /* request dequeued */
        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);
                if (ep == dev->out_ep)
-                       check_read_data (dev, ep, req);
-               free_ep_req (ep, req);
+                       check_read_data(dev, ep, req);
+               free_ep_req(ep, req);
                return;
 
        case -EOVERFLOW:                /* buffer overrun on read means that
@@ -591,89 +542,85 @@ static void source_sink_complete (struct usb_ep *ep, struct usb_request *req)
                                         */
        default:
 #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);
 #endif
        case -EREMOTEIO:                /* short read */
                break;
        }
 
-       status = usb_ep_queue (ep, req, GFP_ATOMIC);
+       status = usb_ep_queue(ep, req, GFP_ATOMIC);
        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);
-               usb_ep_set_halt (ep);
+               usb_ep_set_halt(ep);
                /* FIXME recover later ... somehow */
        }
 }
 
-static struct usb_request *
-source_sink_start_ep (struct usb_ep *ep, gfp_t gfp_flags)
+static struct usb_request *source_sink_start_ep(struct usb_ep *ep)
 {
        struct usb_request      *req;
        int                     status;
 
-       req = alloc_ep_req (ep, buflen);
+       req = alloc_ep_req(ep, buflen);
        if (!req)
                return NULL;
 
-       memset (req->buf, 0, req->length);
+       memset(req->buf, 0, req->length);
        req->complete = source_sink_complete;
 
-       if (strcmp (ep->name, EP_IN_NAME) == 0)
-               reinit_write_data (ep->driver_data, ep, req);
+       if (strcmp(ep->name, EP_IN_NAME) == 0)
+               reinit_write_data(ep, req);
        else
-               memset (req->buf, 0x55, req->length);
+               memset(req->buf, 0x55, req->length);
 
-       status = usb_ep_queue (ep, req, gfp_flags);
+       status = usb_ep_queue(ep, req, GFP_ATOMIC);
        if (status) {
                struct zero_dev *dev = ep->driver_data;
 
-               ERROR (dev, "start %s --> %d\n", ep->name, status);
-               free_ep_req (ep, req);
+               ERROR(dev, "start %s --> %d\n", ep->name, status);
+               free_ep_req(ep, req);
                req = NULL;
        }
 
        return req;
 }
 
-static int
-set_source_sink_config (struct zero_dev *dev, gfp_t gfp_flags)
+static int set_source_sink_config(struct zero_dev *dev)
 {
        int                     result = 0;
        struct usb_ep           *ep;
        struct usb_gadget       *gadget = dev->gadget;
 
-       gadget_for_each_ep (ep, gadget) {
+       gadget_for_each_ep(ep, gadget) {
                const struct usb_endpoint_descriptor    *d;
 
                /* one endpoint writes (sources) zeroes in (to the host) */
-               if (strcmp (ep->name, EP_IN_NAME) == 0) {
-                       d = ep_desc (gadget, &hs_source_desc, &fs_source_desc);
-                       result = usb_ep_enable (ep, d);
+               if (strcmp(ep->name, EP_IN_NAME) == 0) {
+                       d = ep_desc(gadget, &hs_source_desc, &fs_source_desc);
+                       result = usb_ep_enable(ep, d);
                        if (result == 0) {
                                ep->driver_data = dev;
-                               if (source_sink_start_ep(ep, gfp_flags)
-                                               != NULL) {
+                               if (source_sink_start_ep(ep) != NULL) {
                                        dev->in_ep = ep;
                                        continue;
                                }
-                               usb_ep_disable (ep);
+                               usb_ep_disable(ep);
                                result = -EIO;
                        }
 
                /* one endpoint reads (sinks) anything out (from the host) */
-               } else if (strcmp (ep->name, EP_OUT_NAME) == 0) {
-                       d = ep_desc (gadget, &hs_sink_desc, &fs_sink_desc);
-                       result = usb_ep_enable (ep, d);
+               } else if (strcmp(ep->name, EP_OUT_NAME) == 0) {
+                       d = ep_desc(gadget, &hs_sink_desc, &fs_sink_desc);
+                       result = usb_ep_enable(ep, d);
                        if (result == 0) {
                                ep->driver_data = dev;
-                               if (source_sink_start_ep(ep, gfp_flags)
-                                               != NULL) {
+                               if (source_sink_start_ep(ep) != NULL) {
                                        dev->out_ep = ep;
                                        continue;
                                }
-                               usb_ep_disable (ep);
+                               usb_ep_disable(ep);
                                result = -EIO;
                        }
 
@@ -682,11 +629,11 @@ set_source_sink_config (struct zero_dev *dev, gfp_t gfp_flags)
                        continue;
 
                /* 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;
        }
        if (result == 0)
-               DBG (dev, "buflen %d\n", buflen);
+               DBG(dev, "buflen %d\n", buflen);
 
        /* caller is responsible for cleanup on error */
        return result;
@@ -694,31 +641,31 @@ set_source_sink_config (struct zero_dev *dev, gfp_t gfp_flags)
 
 /*-------------------------------------------------------------------------*/
 
-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;
        int             status = req->status;
 
        switch (status) {
 
-       case 0:                         /* normal completion? */
+       case 0:                         /* normal completion? */
                if (ep == dev->out_ep) {
                        /* loop this OUT packet back IN to the host */
                        req->zero = (req->actual < req->length);
                        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)
                                return;
 
                        /* "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,
                                status);
                }
 
                /* queue the buffer for some later OUT packet */
                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)
                        return;
 
@@ -726,7 +673,7 @@ static void loopback_complete (struct usb_ep *ep, struct usb_request *req)
                /* FALLTHROUGH */
 
        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);
                /* FALLTHROUGH */
 
@@ -735,28 +682,27 @@ static void loopback_complete (struct usb_ep *ep, struct usb_request *req)
         * rely on the hardware driver to clean up on disconnect or
         * endpoint disable.
         */
-       case -ECONNABORTED:             /* hardware forced ep reset */
+       case -ECONNABORTED:             /* hardware forced ep reset */
        case -ECONNRESET:               /* request dequeued */
        case -ESHUTDOWN:                /* disconnect from host */
-               free_ep_req (ep, req);
+               free_ep_req(ep, req);
                return;
        }
 }
 
-static int
-set_loopback_config (struct zero_dev *dev, gfp_t gfp_flags)
+static int set_loopback_config(struct zero_dev *dev)
 {
        int                     result = 0;
        struct usb_ep           *ep;
        struct usb_gadget       *gadget = dev->gadget;
 
-       gadget_for_each_ep (ep, gadget) {
+       gadget_for_each_ep(ep, gadget) {
                const struct usb_endpoint_descriptor    *d;
 
                /* one endpoint writes data back IN to the host */
-               if (strcmp (ep->name, EP_IN_NAME) == 0) {
-                       d = ep_desc (gadget, &hs_source_desc, &fs_source_desc);
-                       result = usb_ep_enable (ep, d);
+               if (strcmp(ep->name, EP_IN_NAME) == 0) {
+                       d = ep_desc(gadget, &hs_source_desc, &fs_source_desc);
+                       result = usb_ep_enable(ep, d);
                        if (result == 0) {
                                ep->driver_data = dev;
                                dev->in_ep = ep;
@@ -764,9 +710,9 @@ set_loopback_config (struct zero_dev *dev, gfp_t gfp_flags)
                        }
 
                /* one endpoint just reads OUT packets */
-               } else if (strcmp (ep->name, EP_OUT_NAME) == 0) {
-                       d = ep_desc (gadget, &hs_sink_desc, &fs_sink_desc);
-                       result = usb_ep_enable (ep, d);
+               } else if (strcmp(ep->name, EP_OUT_NAME) == 0) {
+                       d = ep_desc(gadget, &hs_sink_desc, &fs_sink_desc);
+                       result = usb_ep_enable(ep, d);
                        if (result == 0) {
                                ep->driver_data = dev;
                                dev->out_ep = ep;
@@ -778,7 +724,7 @@ set_loopback_config (struct zero_dev *dev, gfp_t gfp_flags)
                        continue;
 
                /* 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;
        }
 
@@ -792,19 +738,19 @@ set_loopback_config (struct zero_dev *dev, gfp_t gfp_flags)
 
                ep = dev->out_ep;
                for (i = 0; i < qlen && result == 0; i++) {
-                       req = alloc_ep_req (ep, buflen);
+                       req = alloc_ep_req(ep, buflen);
                        if (req) {
                                req->complete = loopback_complete;
-                               result = usb_ep_queue (ep, req, GFP_ATOMIC);
+                               result = usb_ep_queue(ep, req, GFP_ATOMIC);
                                if (result)
-                                       DBG (dev, "%s queue req --> %d\n",
+                                       DBG(dev, "%s queue req --> %d\n",
                                                        ep->name, result);
                        } else
                                result = -ENOMEM;
                }
        }
        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 */
        return result;
@@ -812,26 +758,26 @@ set_loopback_config (struct zero_dev *dev, gfp_t gfp_flags)
 
 /*-------------------------------------------------------------------------*/
 
-static void zero_reset_config (struct zero_dev *dev)
+static void zero_reset_config(struct zero_dev *dev)
 {
        if (dev->config == 0)
                return;
 
-       DBG (dev, "reset config\n");
+       DBG(dev, "reset config\n");
 
        /* just disable endpoints, forcing completion of pending i/o.
         * all our completion handlers free their requests in this case.
         */
        if (dev->in_ep) {
-               usb_ep_disable (dev->in_ep);
+               usb_ep_disable(dev->in_ep);
                dev->in_ep = NULL;
        }
        if (dev->out_ep) {
-               usb_ep_disable (dev->out_ep);
+               usb_ep_disable(dev->out_ep);
                dev->out_ep = NULL;
        }
        dev->config = 0;
-       del_timer (&dev->resume);
+       del_timer(&dev->resume);
 }
 
 /* change our operational config.  this code must agree with the code
@@ -844,8 +790,7 @@ static void zero_reset_config (struct zero_dev *dev)
  * code can do, perhaps by disallowing more than one configuration or
  * by limiting configuration choices (like the pxa2xx).
  */
-static int
-zero_set_config (struct zero_dev *dev, unsigned number, gfp_t gfp_flags)
+static int zero_set_config(struct zero_dev *dev, unsigned number)
 {
        int                     result = 0;
        struct usb_gadget       *gadget = dev->gadget;
@@ -853,19 +798,19 @@ zero_set_config (struct zero_dev *dev, unsigned number, gfp_t gfp_flags)
        if (number == dev->config)
                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...*/
-               INFO (dev, "can't change configurations\n");
+               ERROR(dev, "can't change configurations\n");
                return -ESPIPE;
        }
-       zero_reset_config (dev);
+       zero_reset_config(dev);
 
        switch (number) {
        case CONFIG_SOURCE_SINK:
-               result = set_source_sink_config (dev, gfp_flags);
+               result = set_source_sink_config(dev);
                break;
        case CONFIG_LOOPBACK:
-               result = set_loopback_config (dev, gfp_flags);
+               result = set_loopback_config(dev);
                break;
        default:
                result = -EINVAL;
@@ -877,7 +822,7 @@ zero_set_config (struct zero_dev *dev, unsigned number, gfp_t gfp_flags)
        if (!result && (!dev->in_ep || !dev->out_ep))
                result = -ENODEV;
        if (result)
-               zero_reset_config (dev);
+               zero_reset_config(dev);
        else {
                char *speed;
 
@@ -885,11 +830,11 @@ zero_set_config (struct zero_dev *dev, unsigned number, gfp_t gfp_flags)
                case USB_SPEED_LOW:     speed = "low"; break;
                case USB_SPEED_FULL:    speed = "full"; break;
                case USB_SPEED_HIGH:    speed = "high"; break;
-               default:                speed = "?"; break;
+               default:                speed = "?"; break;
                }
 
                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)
                                        ? source_sink : loopback);
        }
@@ -898,10 +843,10 @@ zero_set_config (struct zero_dev *dev, unsigned number, gfp_t gfp_flags)
 
 /*-------------------------------------------------------------------------*/
 
-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)
-               DBG ((struct zero_dev *) ep->driver_data,
+               DBG((struct zero_dev *) ep->driver_data,
                                "setup complete --> %d, %d/%d\n",
                                req->status, req->actual, req->length);
 }
@@ -914,9 +859,9 @@ static void zero_setup_complete (struct usb_ep *ep, struct usb_request *req)
  * the work is in config-specific setup.
  */
 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;
        int                     value = -EOPNOTSUPP;
        u16                     w_index = le16_to_cpu(ctrl->wIndex);
@@ -935,28 +880,26 @@ zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
                switch (w_value >> 8) {
 
                case USB_DT_DEVICE:
-                       value = min (w_length, (u16) sizeof device_desc);
-                       memcpy (req->buf, &device_desc, value);
+                       value = min(w_length, (u16) sizeof device_desc);
+                       memcpy(req->buf, &device_desc, value);
                        break;
-#ifdef CONFIG_USB_GADGET_DUALSPEED
                case USB_DT_DEVICE_QUALIFIER:
-                       if (!gadget->is_dualspeed)
+                       if (!gadget_is_dualspeed(gadget))
                                break;
-                       value = min (w_length, (u16) sizeof dev_qualifier);
-                       memcpy (req->buf, &dev_qualifier, value);
+                       value = min(w_length, (u16) sizeof dev_qualifier);
+                       memcpy(req->buf, &dev_qualifier, value);
                        break;
 
                case USB_DT_OTHER_SPEED_CONFIG:
-                       if (!gadget->is_dualspeed)
+                       if (!gadget_is_dualspeed(gadget))
                                break;
                        // FALLTHROUGH
-#endif /* CONFIG_USB_GADGET_DUALSPEED */
                case USB_DT_CONFIG:
-                       value = config_buf (gadget, req->buf,
+                       value = config_buf(gadget, req->buf,
                                        w_value >> 8,
                                        w_value & 0xff);
                        if (value >= 0)
-                               value = min (w_length, (u16) value);
+                               value = min(w_length, (u16) value);
                        break;
 
                case USB_DT_STRING:
@@ -965,10 +908,10 @@ zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
                         * add string tables for other languages, using
                         * any UTF-8 characters
                         */
-                       value = usb_gadget_get_string (&stringtab,
+                       value = usb_gadget_get_string(&stringtab,
                                        w_value & 0xff, req->buf);
                        if (value >= 0)
-                               value = min (w_length, (u16) value);
+                               value = min(w_length, (u16) value);
                        break;
                }
                break;
@@ -978,20 +921,20 @@ zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
                if (ctrl->bRequestType != 0)
                        goto unknown;
                if (gadget->a_hnp_support)
-                       DBG (dev, "HNP available\n");
+                       DBG(dev, "HNP available\n");
                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
-                       VDBG (dev, "HNP inactive\n");
-               spin_lock (&dev->lock);
-               value = zero_set_config (dev, w_value, GFP_ATOMIC);
-               spin_unlock (&dev->lock);
+                       VDBG(dev, "HNP inactive\n");
+               spin_lock(&dev->lock);
+               value = zero_set_config(dev, w_value);
+               spin_unlock(&dev->lock);
                break;
        case USB_REQ_GET_CONFIGURATION:
                if (ctrl->bRequestType != USB_DIR_IN)
                        goto unknown;
                *(u8 *)req->buf = dev->config;
-               value = min (w_length, (u16) 1);
+               value = min(w_length, (u16) 1);
                break;
 
        /* until we add altsetting support, or other interfaces,
@@ -1001,7 +944,7 @@ zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
        case USB_REQ_SET_INTERFACE:
                if (ctrl->bRequestType != USB_RECIP_INTERFACE)
                        goto unknown;
-               spin_lock (&dev->lock);
+               spin_lock(&dev->lock);
                if (dev->config && w_index == 0 && w_value == 0) {
                        u8              config = dev->config;
 
@@ -1012,11 +955,11 @@ zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
                         * if we had more than one interface we couldn't
                         * use this "reset the config" shortcut.
                         */
-                       zero_reset_config (dev);
-                       zero_set_config (dev, config, GFP_ATOMIC);
+                       zero_reset_config(dev);
+                       zero_set_config(dev, config);
                        value = 0;
                }
-               spin_unlock (&dev->lock);
+               spin_unlock(&dev->lock);
                break;
        case USB_REQ_GET_INTERFACE:
                if (ctrl->bRequestType != (USB_DIR_IN|USB_RECIP_INTERFACE))
@@ -1028,7 +971,7 @@ zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
                        break;
                }
                *(u8 *)req->buf = 0;
-               value = min (w_length, (u16) 1);
+               value = min(w_length, (u16) 1);
                break;
 
        /*
@@ -1060,7 +1003,7 @@ zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
 
        default:
 unknown:
-               VDBG (dev,
+               VDBG(dev,
                        "unknown control req%02x.%02x v%04x i%04x l%d\n",
                        ctrl->bRequestType, ctrl->bRequest,
                        w_value, w_index, w_length);
@@ -1070,11 +1013,11 @@ unknown:
        if (value >= 0) {
                req->length = value;
                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) {
-                       DBG (dev, "ep_queue --> %d\n", value);
+                       DBG(dev, "ep_queue --> %d\n", value);
                        req->status = 0;
-                       zero_setup_complete (gadget->ep0, req);
+                       zero_setup_complete(gadget->ep0, req);
                }
        }
 
@@ -1082,28 +1025,26 @@ unknown:
        return value;
 }
 
-static void
-zero_disconnect (struct usb_gadget *gadget)
+static void 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;
 
-       spin_lock_irqsave (&dev->lock, flags);
-       zero_reset_config (dev);
+       spin_lock_irqsave(&dev->lock, flags);
+       zero_reset_config(dev);
 
        /* a more significant application might have some non-usb
         * activities to quiesce here, saving resources like power
         * 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;
         * or an unbind() during shutdown (including removing module).
         */
 }
 
-static void
-zero_autoresume (unsigned long _dev)
+static void zero_autoresume(unsigned long _dev)
 {
        struct zero_dev *dev = (struct zero_dev *) _dev;
        int             status;
@@ -1112,32 +1053,30 @@ zero_autoresume (unsigned long _dev)
         * more significant than just a timer firing...
         */
        if (dev->gadget->speed != USB_SPEED_UNKNOWN) {
-               status = usb_gadget_wakeup (dev->gadget);
-               DBG (dev, "wakeup --> %d\n", status);
+               status = usb_gadget_wakeup(dev->gadget);
+               DBG(dev, "wakeup --> %d\n", status);
        }
 }
 
 /*-------------------------------------------------------------------------*/
 
-static void /* __init_or_exit */
-zero_unbind (struct usb_gadget *gadget)
+static void 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 */
        if (dev->req) {
                dev->req->length = USB_BUFSIZ;
-               free_ep_req (gadget->ep0, dev->req);
+               free_ep_req(gadget->ep0, dev->req);
        }
-       del_timer_sync (&dev->resume);
-       kfree (dev);
-       set_gadget_data (gadget, NULL);
+       del_timer_sync(&dev->resume);
+       kfree(dev);
+       set_gadget_data(gadget, NULL);
 }
 
-static int __init
-zero_bind (struct usb_gadget *gadget)
+static int __init zero_bind(struct usb_gadget *gadget)
 {
        struct zero_dev         *dev;
        struct usb_ep           *ep;
@@ -1153,26 +1092,26 @@ zero_bind (struct usb_gadget *gadget)
         * autoconfigure on any sane usb controller driver,
         * but there may also be important quirks to address.
         */
-       usb_ep_autoconfig_reset (gadget);
-       ep = usb_ep_autoconfig (gadget, &fs_source_desc);
+       usb_ep_autoconfig_reset(gadget);
+       ep = usb_ep_autoconfig(gadget, &fs_source_desc);
        if (!ep) {
 autoconf_fail:
-               printk (KERN_ERR "%s: can't autoconfigure on %s\n",
+               pr_err("%s: can't autoconfigure on %s\n",
                        shortname, gadget->name);
                return -ENODEV;
        }
        EP_IN_NAME = ep->name;
        ep->driver_data = ep;   /* claim */
-       
-       ep = usb_ep_autoconfig (gadget, &fs_sink_desc);
+
+       ep = usb_ep_autoconfig(gadget, &fs_sink_desc);
        if (!ep)
                goto autoconf_fail;
        EP_OUT_NAME = ep->name;
        ep->driver_data = ep;   /* claim */
 
-       gcnum = usb_gadget_controller_number (gadget);
+       gcnum = usb_gadget_controller_number(gadget);
        if (gcnum >= 0)
-               device_desc.bcdDevice = cpu_to_le16 (0x0200 + gcnum);
+               device_desc.bcdDevice = cpu_to_le16(0x0200 + gcnum);
        else {
                /* gadget zero is so simple (for now, no altsettings) that
                 * it SHOULD NOT have problems with bulk-capable hardware.
@@ -1181,9 +1120,9 @@ autoconf_fail:
                 * things like configuration and altsetting numbering
                 * can need hardware-specific attention though.
                 */
-               printk (KERN_WARNING "%s: controller '%s' not recognized\n",
+               pr_warning("%s: controller '%s' not recognized\n",
                        shortname, gadget->name);
-               device_desc.bcdDevice = __constant_cpu_to_le16 (0x9999);
+               device_desc.bcdDevice = __constant_cpu_to_le16(0x9999);
        }
 
 
@@ -1191,12 +1130,16 @@ autoconf_fail:
        dev = kzalloc(sizeof(*dev), GFP_KERNEL);
        if (!dev)
                return -ENOMEM;
-       spin_lock_init (&dev->lock);
+       spin_lock_init(&dev->lock);
        dev->gadget = gadget;
-       set_gadget_data (gadget, dev);
+       set_gadget_data(gadget, dev);
+
+       init_timer(&dev->resume);
+       dev->resume.function = zero_autoresume;
+       dev->resume.data = (unsigned long) dev;
 
        /* 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)
                goto enomem;
        dev->req->buf = kmalloc(USB_BUFSIZ, GFP_KERNEL);
@@ -1207,26 +1150,25 @@ autoconf_fail:
 
        device_desc.bMaxPacketSize0 = gadget->ep0->maxpacket;
 
-#ifdef CONFIG_USB_GADGET_DUALSPEED
-       /* assume ep0 uses the same value for both speeds ... */
-       dev_qualifier.bMaxPacketSize0 = device_desc.bMaxPacketSize0;
+       if (gadget_is_dualspeed(gadget)) {
+               /* assume ep0 uses the same value for both speeds ... */
+               dev_qualifier.bMaxPacketSize0 = device_desc.bMaxPacketSize0;
 
-       /* and that all endpoints are dual-speed */
-       hs_source_desc.bEndpointAddress = fs_source_desc.bEndpointAddress;
-       hs_sink_desc.bEndpointAddress = fs_sink_desc.bEndpointAddress;
-#endif
+               /* and that all endpoints are dual-speed */
+               hs_source_desc.bEndpointAddress =
+                               fs_source_desc.bEndpointAddress;
+               hs_sink_desc.bEndpointAddress =
+                               fs_sink_desc.bEndpointAddress;
+       }
 
-       if (gadget->is_otg) {
+       if (gadget_is_otg(gadget)) {
                otg_descriptor.bmAttributes |= USB_OTG_HNP,
                source_sink_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);
-       dev->resume.function = zero_autoresume;
-       dev->resume.data = (unsigned long) dev;
        if (autoresume) {
                source_sink_config.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
                loopback_config.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
@@ -1234,45 +1176,43 @@ autoconf_fail:
 
        gadget->ep0->driver_data = dev;
 
-       INFO (dev, "%s, version: " DRIVER_VERSION "\n", longname);
-       INFO (dev, "using %s, OUT %s IN %s\n", gadget->name,
+       INFO(dev, "%s, version: " DRIVER_VERSION "\n", longname);
+       INFO(dev, "using %s, OUT %s IN %s\n", gadget->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,
                gadget->name);
 
        return 0;
 
 enomem:
-       zero_unbind (gadget);
+       zero_unbind(gadget);
        return -ENOMEM;
 }
 
 /*-------------------------------------------------------------------------*/
 
-static void
-zero_suspend (struct usb_gadget *gadget)
+static void 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)
                return;
 
        if (autoresume) {
-               mod_timer (&dev->resume, jiffies + (HZ * autoresume));
-               DBG (dev, "suspend, wakeup in %d seconds\n", autoresume);
+               mod_timer(&dev->resume, jiffies + (HZ * autoresume));
+               DBG(dev, "suspend, wakeup in %d seconds\n", autoresume);
        } else
-               DBG (dev, "suspend\n");
+               DBG(dev, "suspend\n");
 }
 
-static void
-zero_resume (struct usb_gadget *gadget)
+static void 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");
-       del_timer (&dev->resume);
+       DBG(dev, "resume\n");
+       del_timer(&dev->resume);
 }
 
 
@@ -1294,30 +1234,25 @@ static struct usb_gadget_driver zero_driver = {
        .suspend        = zero_suspend,
        .resume         = zero_resume,
 
-       .driver         = {
+       .driver         = {
                .name           = (char *) shortname,
                .owner          = THIS_MODULE,
        },
 };
 
-MODULE_AUTHOR ("David Brownell");
-MODULE_LICENSE ("Dual BSD/GPL");
+MODULE_AUTHOR("David Brownell");
+MODULE_LICENSE("GPL");
 
 
-static int __init init (void)
+static int __init init(void)
 {
-       /* a real value would likely come through some id prom
-        * or module option.  this one takes at least two packets.
-        */
-       strlcpy (serial, "0123456789.0123456789.0123456789", sizeof serial);
-
-       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);