TTY: call tty_port_destroy in the rest of drivers
[linux-3.10.git] / drivers / usb / serial / usb-serial.c
index f7b263e..64bda13 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * USB Serial Converter driver
  *
- * Copyright (C) 1999 - 2005 Greg Kroah-Hartman (greg@kroah.com)
+ * Copyright (C) 1999 - 2012 Greg Kroah-Hartman (greg@kroah.com)
  * Copyright (C) 2000 Peter Berger (pberger@brimson.com)
  * Copyright (C) 2000 Al Borchers (borchers@steinerpoint.com)
  *
@@ -17,6 +17,8 @@
  *
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include <linux/kernel.h>
 #include <linux/errno.h>
 #include <linux/init.h>
 #include <linux/kfifo.h>
 #include "pl2303.h"
 
-/*
- * Version Information
- */
-#define DRIVER_AUTHOR "Greg Kroah-Hartman, greg@kroah.com, http://www.kroah.com/linux/"
+#define DRIVER_AUTHOR "Greg Kroah-Hartman <gregkh@linuxfoundation.org>"
 #define DRIVER_DESC "USB Serial Driver core"
 
-/* Driver structure we register with the USB core */
-static struct usb_driver usb_serial_driver = {
-       .name =         "usbserial",
-       .probe =        usb_serial_probe,
-       .disconnect =   usb_serial_disconnect,
-       .suspend =      usb_serial_suspend,
-       .resume =       usb_serial_resume,
-       .no_dynamic_id =        1,
-       .supports_autosuspend = 1,
-};
-
 /* There is no MODULE_DEVICE_TABLE for usbserial.c.  Instead
    the MODULE_DEVICE_TABLE declarations in each serial driver
    cause the "hotplug" program to pull in whatever module is necessary
@@ -61,7 +49,6 @@ static struct usb_driver usb_serial_driver = {
    drivers depend on it.
 */
 
-static bool debug;
 /* initially all NULL */
 static struct usb_serial *serial_table[SERIAL_TTY_MINORS];
 static DEFINE_MUTEX(table_lock);
@@ -98,7 +85,7 @@ static struct usb_serial *get_free_serial(struct usb_serial *serial,
        unsigned int i, j;
        int good_spot;
 
-       dbg("%s %d", __func__, num_ports);
+       dev_dbg(&serial->interface->dev, "%s %d\n", __func__, num_ports);
 
        *minor = 0;
        mutex_lock(&table_lock);
@@ -118,7 +105,7 @@ static struct usb_serial *get_free_serial(struct usb_serial *serial,
 
                *minor = i;
                j = 0;
-               dbg("%s - minor base = %d", __func__, *minor);
+               dev_dbg(&serial->interface->dev, "%s - minor base = %d\n", __func__, *minor);
                for (i = *minor; (i < (*minor + num_ports)) && (i < SERIAL_TTY_MINORS); ++i) {
                        serial_table[i] = serial;
                        serial->port[j++]->number = i;
@@ -134,8 +121,6 @@ static void return_serial(struct usb_serial *serial)
 {
        int i;
 
-       dbg("%s", __func__);
-
        mutex_lock(&table_lock);
        for (i = 0; i < serial->num_ports; ++i)
                serial_table[serial->minor + i] = NULL;
@@ -150,8 +135,6 @@ static void destroy_serial(struct kref *kref)
 
        serial = to_usb_serial(kref);
 
-       dbg("%s - %s", __func__, serial->type->description);
-
        /* return the minor range that this device had */
        if (serial->minor != SERIAL_TTY_NO_MINOR)
                return_serial(serial);
@@ -202,8 +185,6 @@ static int serial_install(struct tty_driver *driver, struct tty_struct *tty)
        struct usb_serial_port *port;
        int retval = -ENODEV;
 
-       dbg("%s", __func__);
-
        serial = usb_serial_get_by_index(idx);
        if (!serial)
                return retval;
@@ -218,7 +199,7 @@ static int serial_install(struct tty_driver *driver, struct tty_struct *tty)
        if (retval)
                goto error_get_interface;
 
-       retval = tty_standard_install(driver, tty);
+       retval = tty_port_install(&port->port, driver, tty);
        if (retval)
                goto error_init_termios;
 
@@ -267,7 +248,7 @@ static int serial_open(struct tty_struct *tty, struct file *filp)
 {
        struct usb_serial_port *port = tty->driver_data;
 
-       dbg("%s - port %d", __func__, port->number);
+       dev_dbg(tty->dev, "%s - port %d\n", __func__, port->number);
        return tty_port_open(&port->port, tty, filp);
 }
 
@@ -298,14 +279,16 @@ static void serial_down(struct tty_port *tport)
 static void serial_hangup(struct tty_struct *tty)
 {
        struct usb_serial_port *port = tty->driver_data;
-       dbg("%s - port %d", __func__, port->number);
+
+       dev_dbg(tty->dev, "%s - port %d\n", __func__, port->number);
        tty_port_hangup(&port->port);
 }
 
 static void serial_close(struct tty_struct *tty, struct file *filp)
 {
        struct usb_serial_port *port = tty->driver_data;
-       dbg("%s - port %d", __func__, port->number);
+
+       dev_dbg(tty->dev, "%s - port %d\n", __func__, port->number);
        tty_port_close(&port->port, tty, filp);
 }
 
@@ -316,8 +299,7 @@ static void serial_close(struct tty_struct *tty, struct file *filp)
  * Do the resource freeing and refcount dropping for the port.
  * Avoid freeing the console.
  *
- * Called asynchronously after the last tty kref is dropped,
- * and the tty layer has already done the tty_shutdown(tty);
+ * Called asynchronously after the last tty kref is dropped.
  */
 static void serial_cleanup(struct tty_struct *tty)
 {
@@ -331,7 +313,7 @@ static void serial_cleanup(struct tty_struct *tty)
        if (port->port.console)
                return;
 
-       dbg("%s - port %d", __func__, port->number);
+       dev_dbg(tty->dev, "%s - port %d\n", __func__, port->number);
 
        tty->driver_data = NULL;
 
@@ -356,7 +338,8 @@ static int serial_write(struct tty_struct *tty, const unsigned char *buf,
        if (port->serial->dev->state == USB_STATE_NOTATTACHED)
                goto exit;
 
-       dbg("%s - port %d, %d byte(s)", __func__, port->number, count);
+       dev_dbg(tty->dev, "%s - port %d, %d byte(s)\n", __func__,
+               port->number, count);
 
        /* pass on to the driver specific version of this function */
        retval = port->serial->type->write(tty, port, buf, count);
@@ -369,7 +352,8 @@ exit:
 static int serial_write_room(struct tty_struct *tty)
 {
        struct usb_serial_port *port = tty->driver_data;
-       dbg("%s - port %d", __func__, port->number);
+
+       dev_dbg(tty->dev, "%s - port %d\n", __func__, port->number);
        /* pass on to the driver specific version of this function */
        return port->serial->type->write_room(tty);
 }
@@ -377,7 +361,8 @@ static int serial_write_room(struct tty_struct *tty)
 static int serial_chars_in_buffer(struct tty_struct *tty)
 {
        struct usb_serial_port *port = tty->driver_data;
-       dbg("%s - port %d", __func__, port->number);
+
+       dev_dbg(tty->dev, "%s - port %d\n", __func__, port->number);
 
        /* if the device was unplugged then any remaining characters
           fell out of the connector ;) */
@@ -390,7 +375,8 @@ static int serial_chars_in_buffer(struct tty_struct *tty)
 static void serial_throttle(struct tty_struct *tty)
 {
        struct usb_serial_port *port = tty->driver_data;
-       dbg("%s - port %d", __func__, port->number);
+
+       dev_dbg(tty->dev, "%s - port %d\n", __func__, port->number);
 
        /* pass on to the driver specific version of this function */
        if (port->serial->type->throttle)
@@ -400,7 +386,8 @@ static void serial_throttle(struct tty_struct *tty)
 static void serial_unthrottle(struct tty_struct *tty)
 {
        struct usb_serial_port *port = tty->driver_data;
-       dbg("%s - port %d", __func__, port->number);
+
+       dev_dbg(tty->dev, "%s - port %d\n", __func__, port->number);
 
        /* pass on to the driver specific version of this function */
        if (port->serial->type->unthrottle)
@@ -413,7 +400,8 @@ static int serial_ioctl(struct tty_struct *tty,
        struct usb_serial_port *port = tty->driver_data;
        int retval = -ENODEV;
 
-       dbg("%s - port %d, cmd 0x%.4x", __func__, port->number, cmd);
+       dev_dbg(tty->dev, "%s - port %d, cmd 0x%.4x\n", __func__,
+               port->number, cmd);
 
        /* pass on to the driver specific version of this function
           if it is available */
@@ -427,21 +415,22 @@ static int serial_ioctl(struct tty_struct *tty,
 static void serial_set_termios(struct tty_struct *tty, struct ktermios *old)
 {
        struct usb_serial_port *port = tty->driver_data;
-       dbg("%s - port %d", __func__, port->number);
+
+       dev_dbg(tty->dev, "%s - port %d\n", __func__, port->number);
 
        /* pass on to the driver specific version of this function
           if it is available */
        if (port->serial->type->set_termios)
                port->serial->type->set_termios(tty, port, old);
        else
-               tty_termios_copy_hw(tty->termios, old);
+               tty_termios_copy_hw(&tty->termios, old);
 }
 
 static int serial_break(struct tty_struct *tty, int break_state)
 {
        struct usb_serial_port *port = tty->driver_data;
 
-       dbg("%s - port %d", __func__, port->number);
+       dev_dbg(tty->dev, "%s - port %d\n", __func__, port->number);
 
        /* pass on to the driver specific version of this function
           if it is available */
@@ -456,7 +445,6 @@ static int serial_proc_show(struct seq_file *m, void *v)
        int i;
        char tmp[40];
 
-       dbg("%s", __func__);
        seq_puts(m, "usbserinfo:1.0 driver:2.0\n");
        for (i = 0; i < SERIAL_TTY_MINORS; ++i) {
                serial = usb_serial_get_by_index(i);
@@ -501,7 +489,7 @@ static int serial_tiocmget(struct tty_struct *tty)
 {
        struct usb_serial_port *port = tty->driver_data;
 
-       dbg("%s - port %d", __func__, port->number);
+       dev_dbg(tty->dev, "%s - port %d\n", __func__, port->number);
 
        if (port->serial->type->tiocmget)
                return port->serial->type->tiocmget(tty);
@@ -513,7 +501,7 @@ static int serial_tiocmset(struct tty_struct *tty,
 {
        struct usb_serial_port *port = tty->driver_data;
 
-       dbg("%s - port %d", __func__, port->number);
+       dev_dbg(tty->dev, "%s - port %d\n", __func__, port->number);
 
        if (port->serial->type->tiocmset)
                return port->serial->type->tiocmset(tty, set, clear);
@@ -525,7 +513,7 @@ static int serial_get_icount(struct tty_struct *tty,
 {
        struct usb_serial_port *port = tty->driver_data;
 
-       dbg("%s - port %d", __func__, port->number);
+       dev_dbg(tty->dev, "%s - port %d\n", __func__, port->number);
 
        if (port->serial->type->get_icount)
                return port->serial->type->get_icount(tty, icount);
@@ -549,12 +537,12 @@ static void usb_serial_port_work(struct work_struct *work)
                container_of(work, struct usb_serial_port, work);
        struct tty_struct *tty;
 
-       dbg("%s - port %d", __func__, port->number);
-
        tty = tty_port_tty_get(&port->port);
        if (!tty)
                return;
 
+       dev_dbg(tty->dev, "%s - port %d\n", __func__, port->number);
+
        tty_wakeup(tty);
        tty_kref_put(tty);
 }
@@ -587,7 +575,7 @@ static void port_release(struct device *dev)
        struct usb_serial_port *port = to_usb_serial_port(dev);
        int i;
 
-       dbg ("%s - %s", __func__, dev_name(dev));
+       dev_dbg(dev, "%s\n", __func__);
 
        /*
         * Stop all the traffic before cancelling the work, so that
@@ -609,6 +597,7 @@ static void port_release(struct device *dev)
        kfifo_free(&port->write_fifo);
        kfree(port->interrupt_in_buffer);
        kfree(port->interrupt_out_buffer);
+       tty_port_destroy(&port->port);
        kfree(port);
 }
 
@@ -656,12 +645,12 @@ static const struct usb_device_id *get_iface_id(struct usb_serial_driver *drv,
 
        id = usb_match_id(intf, drv->id_table);
        if (id) {
-               dbg("static descriptor matches");
+               dev_dbg(&intf->dev, "static descriptor matches\n");
                goto exit;
        }
        id = match_dynamic_id(intf, drv);
        if (id)
-               dbg("dynamic descriptor matches");
+               dev_dbg(&intf->dev, "dynamic descriptor matches\n");
 exit:
        return id;
 }
@@ -670,12 +659,14 @@ exit:
 static struct usb_serial_driver *search_serial_device(
                                        struct usb_interface *iface)
 {
-       const struct usb_device_id *id;
+       const struct usb_device_id *id = NULL;
        struct usb_serial_driver *drv;
+       struct usb_driver *driver = to_usb_driver(iface->dev.driver);
 
        /* Check if the usb id matches a known device */
        list_for_each_entry(drv, &usb_serial_driver_list, driver_list) {
-               id = get_iface_id(drv, iface);
+               if (drv->usb_driver == driver)
+                       id = get_iface_id(drv, iface);
                if (id)
                        return drv;
        }
@@ -710,9 +701,10 @@ static const struct tty_port_operations serial_port_ops = {
        .shutdown = serial_down,
 };
 
-int usb_serial_probe(struct usb_interface *interface,
+static int usb_serial_probe(struct usb_interface *interface,
                               const struct usb_device_id *id)
 {
+       struct device *ddev = &interface->dev;
        struct usb_device *dev = interface_to_usbdev(interface);
        struct usb_serial *serial = NULL;
        struct usb_serial_port *port;
@@ -739,13 +731,13 @@ int usb_serial_probe(struct usb_interface *interface,
        type = search_serial_device(interface);
        if (!type) {
                mutex_unlock(&table_lock);
-               dbg("none matched");
+               dev_dbg(ddev, "none matched\n");
                return -ENODEV;
        }
 
        if (!try_module_get(type->driver.owner)) {
                mutex_unlock(&table_lock);
-               dev_err(&interface->dev, "module get failed, exiting\n");
+               dev_err(ddev, "module get failed, exiting\n");
                return -EIO;
        }
        mutex_unlock(&table_lock);
@@ -753,7 +745,7 @@ int usb_serial_probe(struct usb_interface *interface,
        serial = create_serial(dev, interface, type);
        if (!serial) {
                module_put(type->driver.owner);
-               dev_err(&interface->dev, "%s - out of memory\n", __func__);
+               dev_err(ddev, "%s - out of memory\n", __func__);
                return -ENOMEM;
        }
 
@@ -765,8 +757,8 @@ int usb_serial_probe(struct usb_interface *interface,
                retval = type->probe(serial, id);
 
                if (retval) {
-                       dbg("sub driver rejected device");
-                       kfree(serial);
+                       dev_dbg(ddev, "sub driver rejected device\n");
+                       usb_serial_put(serial);
                        module_put(type->driver.owner);
                        return retval;
                }
@@ -780,28 +772,28 @@ int usb_serial_probe(struct usb_interface *interface,
 
                if (usb_endpoint_is_bulk_in(endpoint)) {
                        /* we found a bulk in endpoint */
-                       dbg("found bulk in on endpoint %d", i);
+                       dev_dbg(ddev, "found bulk in on endpoint %d\n", i);
                        bulk_in_endpoint[num_bulk_in] = endpoint;
                        ++num_bulk_in;
                }
 
                if (usb_endpoint_is_bulk_out(endpoint)) {
                        /* we found a bulk out endpoint */
-                       dbg("found bulk out on endpoint %d", i);
+                       dev_dbg(ddev, "found bulk out on endpoint %d\n", i);
                        bulk_out_endpoint[num_bulk_out] = endpoint;
                        ++num_bulk_out;
                }
 
                if (usb_endpoint_is_int_in(endpoint)) {
                        /* we found a interrupt in endpoint */
-                       dbg("found interrupt in on endpoint %d", i);
+                       dev_dbg(ddev, "found interrupt in on endpoint %d\n", i);
                        interrupt_in_endpoint[num_interrupt_in] = endpoint;
                        ++num_interrupt_in;
                }
 
                if (usb_endpoint_is_int_out(endpoint)) {
                        /* we found an interrupt out endpoint */
-                       dbg("found interrupt out on endpoint %d", i);
+                       dev_dbg(ddev, "found interrupt out on endpoint %d\n", i);
                        interrupt_out_endpoint[num_interrupt_out] = endpoint;
                        ++num_interrupt_out;
                }
@@ -825,7 +817,7 @@ int usb_serial_probe(struct usb_interface *interface,
                                endpoint = &iface_desc->endpoint[i].desc;
                                if (usb_endpoint_is_int_in(endpoint)) {
                                        /* we found a interrupt in endpoint */
-                                       dbg("found interrupt in for Prolific device on separate interface");
+                                       dev_dbg(ddev, "found interrupt in for Prolific device on separate interface\n");
                                        interrupt_in_endpoint[num_interrupt_in] = endpoint;
                                        ++num_interrupt_in;
                                }
@@ -837,8 +829,8 @@ int usb_serial_probe(struct usb_interface *interface,
                 * properly during a later invocation of usb_serial_probe
                 */
                if (num_bulk_in == 0 || num_bulk_out == 0) {
-                       dev_info(&interface->dev, "PL-2303 hack: descriptors matched but endpoints did not\n");
-                       kfree(serial);
+                       dev_info(ddev, "PL-2303 hack: descriptors matched but endpoints did not\n");
+                       usb_serial_put(serial);
                        module_put(type->driver.owner);
                        return -ENODEV;
                }
@@ -850,12 +842,13 @@ int usb_serial_probe(struct usb_interface *interface,
        if (type == &usb_serial_generic_device) {
                num_ports = num_bulk_out;
                if (num_ports == 0) {
-                       dev_err(&interface->dev,
-                           "Generic device with no bulk out, not allowed.\n");
-                       kfree(serial);
+                       dev_err(ddev, "Generic device with no bulk out, not allowed.\n");
+                       usb_serial_put(serial);
                        module_put(type->driver.owner);
                        return -EIO;
                }
+               dev_info(ddev, "The \"generic\" usb-serial driver is only for testing and one-off prototypes.\n");
+               dev_info(ddev, "Tell linux-usb@vger.kernel.org to add your device to a proper driver.\n");
        }
 #endif
        if (!num_ports) {
@@ -873,8 +866,7 @@ int usb_serial_probe(struct usb_interface *interface,
        serial->num_interrupt_out = num_interrupt_out;
 
        /* found all that we need */
-       dev_info(&interface->dev, "%s converter detected\n",
-                       type->description);
+       dev_info(ddev, "%s converter detected\n", type->description);
 
        /* create our ports, we need as many as the max endpoints */
        /* we don't use num_ports here because some devices have more
@@ -885,8 +877,7 @@ int usb_serial_probe(struct usb_interface *interface,
        max_endpoints = max(max_endpoints, (int)serial->num_ports);
        serial->num_port_pointers = max_endpoints;
 
-       dbg("%s - setting up %d port structures for this device",
-                                               __func__, max_endpoints);
+       dev_dbg(ddev, "setting up %d port structures for this device", max_endpoints);
        for (i = 0; i < max_endpoints; ++i) {
                port = kzalloc(sizeof(struct usb_serial_port), GFP_KERNEL);
                if (!port)
@@ -919,15 +910,13 @@ int usb_serial_probe(struct usb_interface *interface,
                        set_bit(j, &port->read_urbs_free);
                        port->read_urbs[j] = usb_alloc_urb(0, GFP_KERNEL);
                        if (!port->read_urbs[j]) {
-                               dev_err(&interface->dev,
-                                               "No free urbs available\n");
+                               dev_err(ddev, "No free urbs available\n");
                                goto probe_error;
                        }
                        port->bulk_in_buffers[j] = kmalloc(buffer_size,
                                                                GFP_KERNEL);
                        if (!port->bulk_in_buffers[j]) {
-                               dev_err(&interface->dev,
-                                       "Couldn't allocate bulk_in_buffer\n");
+                               dev_err(ddev, "Couldn't allocate bulk_in_buffer\n");
                                goto probe_error;
                        }
                        usb_fill_bulk_urb(port->read_urbs[j], dev,
@@ -957,15 +946,13 @@ int usb_serial_probe(struct usb_interface *interface,
                        set_bit(j, &port->write_urbs_free);
                        port->write_urbs[j] = usb_alloc_urb(0, GFP_KERNEL);
                        if (!port->write_urbs[j]) {
-                               dev_err(&interface->dev,
-                                               "No free urbs available\n");
+                               dev_err(ddev, "No free urbs available\n");
                                goto probe_error;
                        }
                        port->bulk_out_buffers[j] = kmalloc(buffer_size,
                                                                GFP_KERNEL);
                        if (!port->bulk_out_buffers[j]) {
-                               dev_err(&interface->dev,
-                                       "Couldn't allocate bulk_out_buffer\n");
+                               dev_err(ddev, "Couldn't allocate bulk_out_buffer\n");
                                goto probe_error;
                        }
                        usb_fill_bulk_urb(port->write_urbs[j], dev,
@@ -986,8 +973,7 @@ int usb_serial_probe(struct usb_interface *interface,
                        port = serial->port[i];
                        port->interrupt_in_urb = usb_alloc_urb(0, GFP_KERNEL);
                        if (!port->interrupt_in_urb) {
-                               dev_err(&interface->dev,
-                                               "No free urbs available\n");
+                               dev_err(ddev, "No free urbs available\n");
                                goto probe_error;
                        }
                        buffer_size = usb_endpoint_maxp(endpoint);
@@ -996,8 +982,7 @@ int usb_serial_probe(struct usb_interface *interface,
                        port->interrupt_in_buffer = kmalloc(buffer_size,
                                                                GFP_KERNEL);
                        if (!port->interrupt_in_buffer) {
-                               dev_err(&interface->dev,
-                                   "Couldn't allocate interrupt_in_buffer\n");
+                               dev_err(ddev, "Couldn't allocate interrupt_in_buffer\n");
                                goto probe_error;
                        }
                        usb_fill_int_urb(port->interrupt_in_urb, dev,
@@ -1008,7 +993,7 @@ int usb_serial_probe(struct usb_interface *interface,
                                endpoint->bInterval);
                }
        } else if (num_interrupt_in) {
-               dbg("the device claims to support interrupt in transfers, but read_int_callback is not defined");
+               dev_dbg(ddev, "The device claims to support interrupt in transfers, but read_int_callback is not defined\n");
        }
 
        if (serial->type->write_int_callback) {
@@ -1017,8 +1002,7 @@ int usb_serial_probe(struct usb_interface *interface,
                        port = serial->port[i];
                        port->interrupt_out_urb = usb_alloc_urb(0, GFP_KERNEL);
                        if (!port->interrupt_out_urb) {
-                               dev_err(&interface->dev,
-                                               "No free urbs available\n");
+                               dev_err(ddev, "No free urbs available\n");
                                goto probe_error;
                        }
                        buffer_size = usb_endpoint_maxp(endpoint);
@@ -1028,8 +1012,7 @@ int usb_serial_probe(struct usb_interface *interface,
                        port->interrupt_out_buffer = kmalloc(buffer_size,
                                                                GFP_KERNEL);
                        if (!port->interrupt_out_buffer) {
-                               dev_err(&interface->dev,
-                                 "Couldn't allocate interrupt_out_buffer\n");
+                               dev_err(ddev, "Couldn't allocate interrupt_out_buffer\n");
                                goto probe_error;
                        }
                        usb_fill_int_urb(port->interrupt_out_urb, dev,
@@ -1040,7 +1023,7 @@ int usb_serial_probe(struct usb_interface *interface,
                                endpoint->bInterval);
                }
        } else if (num_interrupt_out) {
-               dbg("the device claims to support interrupt out transfers, but write_int_callback is not defined");
+               dev_dbg(ddev, "The device claims to support interrupt out transfers, but write_int_callback is not defined\n");
        }
 
        usb_set_intfdata(interface, serial);
@@ -1068,7 +1051,7 @@ int usb_serial_probe(struct usb_interface *interface,
        serial->disconnected = 1;
 
        if (get_free_serial(serial, num_ports, &minor) == NULL) {
-               dev_err(&interface->dev, "No more free serial devices\n");
+               dev_err(ddev, "No more free serial devices\n");
                goto probe_error;
        }
        serial->minor = minor;
@@ -1077,18 +1060,17 @@ int usb_serial_probe(struct usb_interface *interface,
        for (i = 0; i < num_ports; ++i) {
                port = serial->port[i];
                dev_set_name(&port->dev, "ttyUSB%d", port->number);
-               dbg ("%s - registering %s", __func__, dev_name(&port->dev));
+               dev_dbg(ddev, "registering %s", dev_name(&port->dev));
                device_enable_async_suspend(&port->dev);
 
                retval = device_add(&port->dev);
                if (retval)
-                       dev_err(&port->dev, "Error registering port device, "
-                               "continuing\n");
+                       dev_err(ddev, "Error registering port device, continuing\n");
        }
 
        serial->disconnected = 0;
 
-       usb_serial_console_init(debug, minor);
+       usb_serial_console_init(minor);
 exit:
        module_put(type->driver.owner);
        return 0;
@@ -1098,9 +1080,8 @@ probe_error:
        module_put(type->driver.owner);
        return -EIO;
 }
-EXPORT_SYMBOL_GPL(usb_serial_probe);
 
-void usb_serial_disconnect(struct usb_interface *interface)
+static void usb_serial_disconnect(struct usb_interface *interface)
 {
        int i;
        struct usb_serial *serial = usb_get_intfdata(interface);
@@ -1108,7 +1089,6 @@ void usb_serial_disconnect(struct usb_interface *interface)
        struct usb_serial_port *port;
 
        usb_serial_console_disconnect(serial);
-       dbg("%s", __func__);
 
        mutex_lock(&serial->disc_mutex);
        /* must set a flag, to signal subdrivers */
@@ -1135,7 +1115,6 @@ void usb_serial_disconnect(struct usb_interface *interface)
        usb_serial_put(serial);
        dev_info(dev, "device disconnected\n");
 }
-EXPORT_SYMBOL_GPL(usb_serial_disconnect);
 
 int usb_serial_suspend(struct usb_interface *intf, pm_message_t message)
 {
@@ -1179,6 +1158,22 @@ int usb_serial_resume(struct usb_interface *intf)
 }
 EXPORT_SYMBOL(usb_serial_resume);
 
+static int usb_serial_reset_resume(struct usb_interface *intf)
+{
+       struct usb_serial *serial = usb_get_intfdata(intf);
+       int rv;
+
+       serial->suspending = 0;
+       if (serial->type->reset_resume)
+               rv = serial->type->reset_resume(serial);
+       else {
+               rv = -EOPNOTSUPP;
+               intf->needs_binding = 1;
+       }
+
+       return rv;
+}
+
 static const struct tty_operations serial_ops = {
        .open =                 serial_open,
        .close =                serial_close,
@@ -1202,6 +1197,17 @@ static const struct tty_operations serial_ops = {
 
 struct tty_driver *usb_serial_tty_driver;
 
+/* Driver structure we register with the USB core */
+static struct usb_driver usb_serial_driver = {
+       .name =         "usbserial",
+       .probe =        usb_serial_probe,
+       .disconnect =   usb_serial_disconnect,
+       .suspend =      usb_serial_suspend,
+       .resume =       usb_serial_resume,
+       .no_dynamic_id =        1,
+       .supports_autosuspend = 1,
+};
+
 static int __init usb_serial_init(void)
 {
        int i;
@@ -1217,8 +1223,7 @@ static int __init usb_serial_init(void)
 
        result = bus_register(&usb_serial_bus_type);
        if (result) {
-               printk(KERN_ERR "usb-serial: %s - registering bus driver "
-                      "failed\n", __func__);
+               pr_err("%s - registering bus driver failed\n", __func__);
                goto exit_bus;
        }
 
@@ -1238,29 +1243,24 @@ static int __init usb_serial_init(void)
        tty_set_operations(usb_serial_tty_driver, &serial_ops);
        result = tty_register_driver(usb_serial_tty_driver);
        if (result) {
-               printk(KERN_ERR "usb-serial: %s - tty_register_driver failed\n",
-                      __func__);
+               pr_err("%s - tty_register_driver failed\n", __func__);
                goto exit_reg_driver;
        }
 
        /* register the USB driver */
        result = usb_register(&usb_serial_driver);
        if (result < 0) {
-               printk(KERN_ERR "usb-serial: %s - usb_register failed\n",
-                      __func__);
+               pr_err("%s - usb_register failed\n", __func__);
                goto exit_tty;
        }
 
        /* register the generic driver, if we should */
-       result = usb_serial_generic_register(debug);
+       result = usb_serial_generic_register();
        if (result < 0) {
-               printk(KERN_ERR "usb-serial: %s - registering generic "
-                      "driver failed\n", __func__);
+               pr_err("%s - registering generic driver failed\n", __func__);
                goto exit_generic;
        }
 
-       printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_DESC "\n");
-
        return result;
 
 exit_generic:
@@ -1273,8 +1273,7 @@ exit_reg_driver:
        bus_unregister(&usb_serial_bus_type);
 
 exit_bus:
-       printk(KERN_ERR "usb-serial: %s - returning with error %d\n",
-              __func__, result);
+       pr_err("%s - returning with error %d\n", __func__, result);
        put_tty_driver(usb_serial_tty_driver);
        return result;
 }
@@ -1300,7 +1299,7 @@ module_exit(usb_serial_exit);
        do {                                                            \
                if (!type->function) {                                  \
                        type->function = usb_serial_generic_##function; \
-                       dbg("Had to override the " #function            \
+                       pr_debug("Had to override the " #function       \
                                " usb serial operation with the generic one.");\
                        }                                               \
        } while (0)
@@ -1343,12 +1342,10 @@ static int usb_serial_register(struct usb_serial_driver *driver)
 
        retval = usb_serial_bus_register(driver);
        if (retval) {
-               printk(KERN_ERR "usb-serial: problem %d when registering "
-                      "driver %s\n", retval, driver->description);
+               pr_err("problem %d when registering driver %s\n", retval, driver->description);
                list_del(&driver->driver_list);
        } else
-               printk(KERN_INFO "USB Serial support registered for %s\n",
-                                               driver->description);
+               pr_info("USB Serial support registered for %s\n", driver->description);
 
        mutex_unlock(&table_lock);
        return retval;
@@ -1356,8 +1353,7 @@ static int usb_serial_register(struct usb_serial_driver *driver)
 
 static void usb_serial_deregister(struct usb_serial_driver *device)
 {
-       printk(KERN_INFO "USB Serial deregistering driver %s\n",
-              device->description);
+       pr_info("USB Serial deregistering driver %s\n", device->description);
        mutex_lock(&table_lock);
        list_del(&device->driver_list);
        usb_serial_bus_deregister(device);
@@ -1366,18 +1362,19 @@ static void usb_serial_deregister(struct usb_serial_driver *device)
 
 /**
  * usb_serial_register_drivers - register drivers for a usb-serial module
- * @udriver: usb_driver used for matching devices/interfaces
  * @serial_drivers: NULL-terminated array of pointers to drivers to be registered
+ * @name: name of the usb_driver for this set of @serial_drivers
+ * @id_table: list of all devices this @serial_drivers set binds to
  *
- * Registers @udriver and all the drivers in the @serial_drivers array.
- * Automatically fills in the .no_dynamic_id and PM fields in @udriver and
- * the .usb_driver field in each serial driver.
+ * Registers all the drivers in the @serial_drivers array, and dynamically
+ * creates a struct usb_driver with the name @name and id_table of @id_table.
  */
-int usb_serial_register_drivers(struct usb_driver *udriver,
-               struct usb_serial_driver * const serial_drivers[])
+int usb_serial_register_drivers(struct usb_serial_driver *const serial_drivers[],
+                               const char *name,
+                               const struct usb_device_id *id_table)
 {
        int rc;
-       const struct usb_device_id *saved_id_table;
+       struct usb_driver *udriver;
        struct usb_serial_driver * const *sd;
 
        /*
@@ -1388,18 +1385,31 @@ int usb_serial_register_drivers(struct usb_driver *udriver,
         * Performance hack: We don't want udriver to be probed until
         * the serial drivers are registered, because the probe would
         * simply fail for lack of a matching serial driver.
-        * Therefore save off udriver's id_table until we are all set.
+        * So we leave udriver's id_table set to NULL until we are all set.
         *
         * Suspend/resume support is implemented in the usb-serial core,
         * so fill in the PM-related fields in udriver.
         */
-       saved_id_table = udriver->id_table;
-       udriver->id_table = NULL;
+       udriver = kzalloc(sizeof(*udriver), GFP_KERNEL);
+       if (!udriver)
+               return -ENOMEM;
 
+       udriver->name = name;
        udriver->no_dynamic_id = 1;
        udriver->supports_autosuspend = 1;
        udriver->suspend = usb_serial_suspend;
        udriver->resume = usb_serial_resume;
+       udriver->probe = usb_serial_probe;
+       udriver->disconnect = usb_serial_disconnect;
+
+       /* we only set the reset_resume field if the serial_driver has one */
+       for (sd = serial_drivers; *sd; ++sd) {
+               if ((*sd)->reset_resume) {
+                       udriver->reset_resume = usb_serial_reset_resume;
+                       break;
+               }
+       }
+
        rc = usb_register(udriver);
        if (rc)
                return rc;
@@ -1411,8 +1421,8 @@ int usb_serial_register_drivers(struct usb_driver *udriver,
                        goto failed;
        }
 
-       /* Now restore udriver's id_table and look for matches */
-       udriver->id_table = saved_id_table;
+       /* Now set udriver's id_table and look for matches */
+       udriver->id_table = id_table;
        rc = driver_attach(&udriver->drvwrap.driver);
        return 0;
 
@@ -1426,17 +1436,20 @@ EXPORT_SYMBOL_GPL(usb_serial_register_drivers);
 
 /**
  * usb_serial_deregister_drivers - deregister drivers for a usb-serial module
- * @udriver: usb_driver to unregister
  * @serial_drivers: NULL-terminated array of pointers to drivers to be deregistered
  *
- * Deregisters @udriver and all the drivers in the @serial_drivers array.
+ * Deregisters all the drivers in the @serial_drivers array and deregisters and
+ * frees the struct usb_driver that was created by the call to
+ * usb_serial_register_drivers().
  */
-void usb_serial_deregister_drivers(struct usb_driver *udriver,
-               struct usb_serial_driver * const serial_drivers[])
+void usb_serial_deregister_drivers(struct usb_serial_driver *const serial_drivers[])
 {
+       struct usb_driver *udriver = (*serial_drivers)->usb_driver;
+
        for (; *serial_drivers; ++serial_drivers)
                usb_serial_deregister(*serial_drivers);
        usb_deregister(udriver);
+       kfree(udriver);
 }
 EXPORT_SYMBOL_GPL(usb_serial_deregister_drivers);
 
@@ -1444,6 +1457,3 @@ EXPORT_SYMBOL_GPL(usb_serial_deregister_drivers);
 MODULE_AUTHOR(DRIVER_AUTHOR);
 MODULE_DESCRIPTION(DRIVER_DESC);
 MODULE_LICENSE("GPL");
-
-module_param(debug, bool, S_IRUGO | S_IWUSR);
-MODULE_PARM_DESC(debug, "Debug enabled or not");