1 From 899e50aa6da8bfcc19551ab3232dd180c1d1e475 Mon Sep 17 00:00:00 2001
2 From: Luiz Fernando N. Capitulino <lcapitulino@mandriva.com.br>
3 Date: Sun, 28 May 2006 21:56:07 -0300
4 Subject: [PATCH 5/11] usbserial: Ports the core to the Serial Core.
6 This patch will break all USB-Serial drivers. It's big, but most of the
7 changes are just deletions.
9 I didn't write a document explaning how to make the port yet, will do when
10 I get enough feedback about this work. For now, the important points regarding
13 1. The registration process hasn't been changed, ie, you don't have to touch
14 the driver's init function
16 2. The way you send data to user-space (ie, calling the tty's flip buffer
17 functions) hasn't been changed either
19 3. The big interface change is the removal of the tty callbacks from the
20 struct usb_serial_driver (open(), close(), write(), write_room(), ioctl(),
21 set_termios(), break_ctl(), chars_in_buffer(), throttle(), unthrottle(),
22 tiocmget(), tiocmset()).
24 Now a driver must assign an allocated 'struct uart_ops' to the 'uart_ops'
25 member of the struct usb_serial_driver. And, of course, define its
28 That's the Serial Core interface, and it's explained in this document:
30 Documentation/serial/driver
32 Now lets speak about the general points:
36 The tty version of the USB-Serial's core supports multi-port devices by:
38 A) Allocating a minor number for each port in get_free_serial()
40 B) Filling the 'port' member of the device's struct usb_serial_port
41 with pointers to all the ports already set up
43 C) tty_register_device() will register each minor with the tty core
45 D) At open() time, USB-Serial's core gets the right port to use and
46 puts a pointer to it in the 'tty->private_data' so that the other
49 In the Serial Core version, steps A and B are the same, but the others
52 C) All the _individuals_ ports are registered with the Serial Core
53 by uart_add_one_port()
55 D) All the methods will get the port to be used from the USBSERIAL_PORT
58 The most important assumption I've made is this: the USBSERIAL_PORT macro
59 will bring the right port. It can be the third port of a device. The first
60 one. Doesn't matter, the right port will be there.
62 I have no sure whether this is really right. In fact, the multi-port support
63 is my main concern regarding the Serial Core port work. The problem here is
64 that I don't have multi-port devices, then my only choice was to read the
65 code and adapt it for what I think to be right.
67 2. struct usb_serial reference counting has been removed
71 A) IIUC, it's not needed anymore. In the tty version, the kref_put() is
72 called in three places: serial_close(), serial_read_proc() and
73 usb_serial_disconnect().
75 serial_read_proc() was dropped and serial_close() is only called when
76 the port is closed last time.
78 Then the call to the destroy_serial() function was moved to
79 usb_serial_disconnect(). If the device is disconnected before calling
80 close(), the Serial Core will notice it and serial_shutdown() won't
81 be called. If the device is close()ed but not disconnected, then yes,
82 that memory will remain allocated 'til the device is disconnected.
83 This leads us to the next reason.
85 B) uart_remove_one_port() cannot be called from the shutdown() method.
86 IOW: we can't call destroy_serial() from serial_shutdown(). If we do
87 this we'll get a deadlock because uart_close() takes the
88 'state->mutex' lock before calling the shutdown method _and_ the
89 uart_remove_one_port() will try to lock the same mutex when called.
93 In the uart port initialization (in usb_serial_probe()), all ports are
94 configured to be the 'PORT_16650' type. I don't know how the Serial Core
95 uses that information, and 'PORT_16650' is something that worked.
99 It's 16 for all ports, but it's just another guess. What should it be?
103 I've made the methods which has default behaivor defined by the Serial Core
104 as optionals, ie, if an optional method wasn't defined by a driver the
105 USB-Serial's core will perfom the default behaivor.
107 Those methods currently are: tx_empty(), ioctl(), pm() and type().
109 Signed-off-by: Luiz Fernando N. Capitulino <lcapitulino@mandriva.com.br>
111 drivers/usb/serial/bus.c | 19 +
112 drivers/usb/serial/usb-serial.c | 546 +++++++++++++--------------------------
113 drivers/usb/serial/usb-serial.h | 23 +-
114 3 files changed, 195 insertions(+), 393 deletions(-)
116 diff --git a/drivers/usb/serial/bus.c b/drivers/usb/serial/bus.c
117 index e9f9f4b..832a34c 100644
118 --- a/drivers/usb/serial/bus.c
119 +++ b/drivers/usb/serial/bus.c
121 #include <linux/config.h>
122 #include <linux/kernel.h>
123 #include <linux/errno.h>
124 -#include <linux/tty.h>
125 +#include <linux/serial_core.h>
126 #include <linux/module.h>
127 #include <linux/usb.h>
128 #include "usb-serial.h"
129 @@ -42,7 +42,6 @@ static int usb_serial_device_probe (stru
130 struct usb_serial_driver *driver;
131 struct usb_serial_port *port;
135 port = to_usb_serial_port(dev);
137 @@ -63,11 +62,15 @@ static int usb_serial_device_probe (stru
141 - minor = port->number;
142 - tty_register_device (usb_serial_tty_driver, minor, dev);
143 + port->uart_port.line = port->number;
144 + retval = uart_add_one_port(&usb_serial_uart_driver, &port->uart_port);
146 + dev_err(dev, "Can't add uart port, exiting\n");
149 dev_info(&port->serial->dev->dev,
150 "%s converter now attached to ttyUSB%d\n",
151 - driver->description, minor);
152 + driver->description, port->number);
156 @@ -78,7 +81,6 @@ static int usb_serial_device_remove (str
157 struct usb_serial_driver *driver;
158 struct usb_serial_port *port;
162 port = to_usb_serial_port(dev);
164 @@ -96,10 +98,9 @@ static int usb_serial_device_remove (str
165 module_put(driver->driver.owner);
168 - minor = port->number;
169 - tty_unregister_device (usb_serial_tty_driver, minor);
170 + uart_remove_one_port(&usb_serial_uart_driver, &port->uart_port);
171 dev_info(dev, "%s converter now disconnected from ttyUSB%d\n",
172 - driver->description, minor);
173 + driver->description, port->uart_port.line);
177 diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
178 index 4165035..f4db7a9 100644
179 --- a/drivers/usb/serial/usb-serial.c
180 +++ b/drivers/usb/serial/usb-serial.c
181 @@ -24,6 +24,7 @@ #include <linux/slab.h>
182 #include <linux/tty.h>
183 #include <linux/tty_driver.h>
184 #include <linux/tty_flip.h>
185 +#include <linux/serial_core.h>
186 #include <linux/module.h>
187 #include <linux/moduleparam.h>
188 #include <linux/spinlock.h>
189 @@ -60,21 +61,12 @@ static int debug;
190 static struct usb_serial *serial_table[SERIAL_TTY_MINORS]; /* initially all NULL */
191 static LIST_HEAD(usb_serial_driver_list);
193 -struct usb_serial *usb_serial_get_by_index(unsigned index)
195 - struct usb_serial *serial = serial_table[index];
198 - kref_get(&serial->kref);
202 static struct usb_serial *get_free_serial (struct usb_serial *serial, int num_ports, unsigned int *minor)
207 - dbg("%d", num_ports);
208 + dbg("%d ports", num_ports);
211 for (i = 0; i < SERIAL_TTY_MINORS; ++i) {
212 @@ -104,7 +96,7 @@ static void return_serial(struct usb_ser
217 + dbg("%s", serial->type->description);
221 @@ -114,14 +106,11 @@ static void return_serial(struct usb_ser
225 -static void destroy_serial(struct kref *kref)
226 +static void destroy_serial(struct usb_serial *serial)
228 - struct usb_serial *serial;
229 struct usb_serial_port *port;
232 - serial = to_usb_serial(kref);
234 dbg("%s", serial->type->description);
236 serial->type->shutdown(serial);
237 @@ -169,361 +158,184 @@ static void destroy_serial(struct kref *
240 /*****************************************************************************
241 - * Driver tty interface functions
242 + * Driver Serial Core interface functions
243 *****************************************************************************/
244 -static int serial_open (struct tty_struct *tty, struct file * filp)
245 +static unsigned int serial_tx_empty(struct uart_port *port)
247 - struct usb_serial *serial;
248 - struct usb_serial_port *port;
249 - unsigned int portNumber;
254 - /* get the serial object associated with this tty pointer */
255 - serial = usb_serial_get_by_index(tty->index);
257 - tty->driver_data = NULL;
261 - portNumber = tty->index - serial->minor;
262 - port = serial->port[portNumber];
265 - goto bailout_kref_put;
268 - if (mutex_lock_interruptible(&port->mutex)) {
269 - retval = -ERESTARTSYS;
270 - goto bailout_kref_put;
273 - ++port->open_count;
275 - if (port->open_count == 1) {
277 - /* set up our port structure making the tty driver
278 - * remember our port object, and us it */
279 - tty->driver_data = port;
282 - /* lock this module before we call it
283 - * this may fail, which means we must bail out,
284 - * safe because we are called with BKL held */
285 - if (!try_module_get(serial->type->driver.owner)) {
287 - goto bailout_mutex_unlock;
289 + unsigned int (*tx_empty)(struct uart_port *);
291 - /* only call the device specific open if this
292 - * is the first time the port is opened */
293 - retval = serial->type->open(port, filp);
295 - goto bailout_module_put;
297 + dbg("port %d", port->line);
299 - mutex_unlock(&port->mutex);
301 + tx_empty = USBSERIAL_PORT->serial->type->uart_ops->tx_empty;
303 + return tx_empty(port);
306 - module_put(serial->type->driver.owner);
307 -bailout_mutex_unlock:
308 - port->open_count = 0;
309 - mutex_unlock(&port->mutex);
311 - kref_put(&serial->kref, destroy_serial);
313 + return TIOCSER_TEMT;
316 -static void serial_close(struct tty_struct *tty, struct file * filp)
317 +static void serial_set_mctrl(struct uart_port *port, unsigned int mctrl)
319 - struct usb_serial_port *port = tty->driver_data;
324 - dbg("port %d", port->number);
326 - mutex_lock(&port->mutex);
327 + dbg("port %d", port->line);
329 - if (port->open_count == 0) {
330 - mutex_unlock(&port->mutex);
334 - --port->open_count;
335 - if (port->open_count == 0) {
336 - /* only call the device specific close if this
337 - * port is being closed by the last owner */
338 - port->serial->type->close(port, filp);
341 - if (port->tty->driver_data)
342 - port->tty->driver_data = NULL;
345 + USBSERIAL_PORT->serial->type->uart_ops->set_mctrl(port, mctrl);
348 - module_put(port->serial->type->driver.owner);
350 +static unsigned int serial_get_mctrl(struct uart_port *port)
352 + dbg("port %d", port->line);
354 - mutex_unlock(&port->mutex);
355 - kref_put(&port->serial->kref, destroy_serial);
356 + return USBSERIAL_PORT->serial->type->uart_ops->get_mctrl(port);
359 -static int serial_write (struct tty_struct * tty, const unsigned char *buf, int count)
360 +static void serial_stop_tx(struct uart_port *port)
362 - struct usb_serial_port *port = tty->driver_data;
363 - int retval = -EINVAL;
364 + dbg("port %d", port->line);
368 + USBSERIAL_PORT->serial->type->uart_ops->stop_tx(port);
371 - dbg("port %d, %d byte(s)", port->number, count);
372 +static void serial_start_tx(struct uart_port *port)
374 + dbg("port %d", port->line);
376 - if (!port->open_count) {
377 - dbg("port not opened");
380 + USBSERIAL_PORT->serial->type->uart_ops->start_tx(port);
383 - /* pass on to the driver specific version of this function */
384 - retval = port->serial->type->write(port, buf, count);
385 +static void serial_send_xchar(struct uart_port *port, char ch)
387 + dbg("port %d", port->line);
391 + USBSERIAL_PORT->serial->type->uart_ops->send_xchar(port, ch);
394 -static int serial_write_room (struct tty_struct *tty)
395 +static void serial_stop_rx(struct uart_port *port)
397 - struct usb_serial_port *port = tty->driver_data;
398 - int retval = -EINVAL;
399 + dbg("port %d", port->line);
403 + USBSERIAL_PORT->serial->type->uart_ops->stop_rx(port);
406 - dbg("port %d", port->number);
407 +static void serial_enable_ms(struct uart_port *port)
409 + dbg("port %d", port->line);
411 - if (!port->open_count) {
412 - dbg("port not open");
415 + USBSERIAL_PORT->serial->type->uart_ops->enable_ms(port);
418 - /* pass on to the driver specific version of this function */
419 - retval = port->serial->type->write_room(port);
420 +static void serial_break(struct uart_port *port, int break_state)
422 + dbg("port %d", port->line);
426 + USBSERIAL_PORT->serial->type->uart_ops->break_ctl(port, break_state);
429 -static int serial_chars_in_buffer (struct tty_struct *tty)
430 +static int serial_startup(struct uart_port *port)
432 - struct usb_serial_port *port = tty->driver_data;
433 - int retval = -EINVAL;
438 + dbg("port %d", port->line);
440 - dbg("port %d", port->number);
441 + if (!try_module_get(USBSERIAL_PORT->serial->type->driver.owner))
444 - if (!port->open_count) {
445 - dbg("port not open");
448 + ret = USBSERIAL_PORT->serial->type->uart_ops->startup(port);
452 - /* pass on to the driver specific version of this function */
453 - retval = port->serial->type->chars_in_buffer(port);
459 + module_put(USBSERIAL_PORT->serial->type->driver.owner);
463 -static void serial_throttle (struct tty_struct * tty)
464 +static void serial_shutdown(struct uart_port *port)
466 - struct usb_serial_port *port = tty->driver_data;
467 + dbg("port %d", port->line);
471 + USBSERIAL_PORT->serial->type->uart_ops->shutdown(port);
473 - dbg("port %d", port->number);
475 - if (!port->open_count) {
476 - dbg ("port not open");
480 - /* pass on to the driver specific version of this function */
481 - if (port->serial->type->throttle)
482 - port->serial->type->throttle(port);
483 + module_put(USBSERIAL_PORT->serial->type->driver.owner);
486 -static void serial_unthrottle (struct tty_struct * tty)
487 +static int serial_ioctl(struct uart_port *port, unsigned int cmd, unsigned long arg)
489 - struct usb_serial_port *port = tty->driver_data;
490 + int (*ioctl)(struct uart_port *, unsigned int, unsigned long);
491 + int ret = -ENOIOCTLCMD;
496 - dbg("port %d", port->number);
497 + dbg("port %d", port->line);
499 - if (!port->open_count) {
500 - dbg("port not open");
503 + ioctl = USBSERIAL_PORT->serial->type->uart_ops->ioctl;
505 + ret = ioctl(port, cmd, arg);
507 - /* pass on to the driver specific version of this function */
508 - if (port->serial->type->unthrottle)
509 - port->serial->type->unthrottle(port);
513 -static int serial_ioctl (struct tty_struct *tty, struct file * file, unsigned int cmd, unsigned long arg)
514 +static void serial_set_termios(struct uart_port *port,
515 + struct termios *termios,
516 + struct termios *old_termios)
518 - struct usb_serial_port *port = tty->driver_data;
519 - int retval = -ENODEV;
520 + dbg("port %d", port->line);
525 - dbg("port %d, cmd 0x%.4x", port->number, cmd);
527 - if (!port->open_count) {
528 - dbg ("port not open");
532 - /* pass on to the driver specific version of this function if it is available */
533 - if (port->serial->type->ioctl)
534 - retval = port->serial->type->ioctl(port, file, cmd, arg);
536 - retval = -ENOIOCTLCMD;
540 + USBSERIAL_PORT->serial->type->uart_ops->set_termios(port,
545 -static void serial_set_termios (struct tty_struct *tty, struct termios * old)
546 +static void serial_pm(struct uart_port *port, unsigned int state,
547 + unsigned int oldstate)
549 - struct usb_serial_port *port = tty->driver_data;
550 + void (*pm)(struct uart_port *, unsigned int, unsigned int);
554 + dbg("port %d", port->line);
556 - dbg("port %d", port->number);
558 - if (!port->open_count) {
559 - dbg("port not open");
563 - /* pass on to the driver specific version of this function if it is available */
564 - if (port->serial->type->set_termios)
565 - port->serial->type->set_termios(port, old);
566 + pm = USBSERIAL_PORT->serial->type->uart_ops->pm;
568 + USBSERIAL_PORT->serial->type->uart_ops->pm(port, state,
572 -static void serial_break (struct tty_struct *tty, int break_state)
573 +static const char *serial_type(struct uart_port *port)
575 - struct usb_serial_port *port = tty->driver_data;
579 + const char *(*type)(struct uart_port *);
581 - dbg("port %d", port->number);
582 + dbg("port %d", port->line);
584 - if (!port->open_count) {
585 - dbg("port not open");
588 + type = USBSERIAL_PORT->serial->type->uart_ops->type;
590 + return USBSERIAL_PORT->serial->type->uart_ops->type(port);
592 - /* pass on to the driver specific version of this function if it is available */
593 - if (port->serial->type->break_ctl)
594 - port->serial->type->break_ctl(port, break_state);
598 -static int serial_read_proc (char *page, char **start, off_t off, int count, int *eof, void *data)
599 +static void serial_release_port(struct uart_port *port)
601 - struct usb_serial *serial;
608 - length += sprintf (page, "usbserinfo:1.0 driver:2.0\n");
609 - for (i = 0; i < SERIAL_TTY_MINORS && length < PAGE_SIZE; ++i) {
610 - serial = usb_serial_get_by_index(i);
611 - if (serial == NULL)
613 + dbg("port %d", port->line);
615 - length += sprintf (page+length, "%d:", i);
616 - if (serial->type->driver.owner)
617 - length += sprintf (page+length, " module:%s", module_name(serial->type->driver.owner));
618 - length += sprintf (page+length, " name:\"%s\"", serial->type->description);
619 - length += sprintf (page+length, " vendor:%04x product:%04x",
620 - le16_to_cpu(serial->dev->descriptor.idVendor),
621 - le16_to_cpu(serial->dev->descriptor.idProduct));
622 - length += sprintf (page+length, " num_ports:%d", serial->num_ports);
623 - length += sprintf (page+length, " port:%d", i - serial->minor + 1);
625 - usb_make_path(serial->dev, tmp, sizeof(tmp));
626 - length += sprintf (page+length, " path:%s", tmp);
628 - length += sprintf (page+length, "\n");
629 - if ((length + begin) > (off + count))
631 - if ((length + begin) < off) {
635 - kref_put(&serial->kref, destroy_serial);
639 - if (off >= (length + begin))
641 - *start = page + (off-begin);
642 - return ((count < begin+length-off) ? count : begin+length-off);
643 + USBSERIAL_PORT->serial->type->uart_ops->release_port(port);
646 -static int serial_tiocmget (struct tty_struct *tty, struct file *file)
647 +static int serial_request_port(struct uart_port *port)
649 - struct usb_serial_port *port = tty->driver_data;
650 + dbg("port %d", port->line);
655 - dbg("port %d", port->number);
657 - if (!port->open_count) {
658 - dbg("port not open");
662 - if (port->serial->type->tiocmget)
663 - return port->serial->type->tiocmget(port, file);
667 + return USBSERIAL_PORT->serial->type->uart_ops->request_port(port);
670 -static int serial_tiocmset (struct tty_struct *tty, struct file *file,
671 - unsigned int set, unsigned int clear)
672 +static void serial_config_port(struct uart_port *port, int flags)
674 - struct usb_serial_port *port = tty->driver_data;
679 - dbg("port %d", port->number);
680 + dbg("port %d", port->line);
682 - if (!port->open_count) {
683 - dbg("port not open");
686 + USBSERIAL_PORT->serial->type->uart_ops->config_port(port, flags);
689 - if (port->serial->type->tiocmset)
690 - return port->serial->type->tiocmset(port, file, set, clear);
691 +static int serial_verify_port(struct uart_port *port,
692 + struct serial_struct *serinfo)
694 + dbg("port %d", port->line);
698 + return USBSERIAL_PORT->serial->type->uart_ops->verify_port(port, serinfo);
701 void usb_serial_port_softint(void *private)
702 @@ -531,12 +343,12 @@ void usb_serial_port_softint(void *priva
703 struct usb_serial_port *port = private;
704 struct tty_struct *tty;
706 - dbg("port %d", port->number);
708 + dbg("port %d", port->uart_port.line);
714 + tty = port->uart_port.info->tty;
718 @@ -547,7 +359,8 @@ static void port_release(struct device *
720 struct usb_serial_port *port = to_usb_serial_port(dev);
722 - dbg ("%s", dev->bus_id);
723 + dbg("Releasing port %s", dev->bus_id);
725 usb_kill_urb(port->read_urb);
726 usb_free_urb(port->read_urb);
727 usb_kill_urb(port->write_urb);
728 @@ -601,6 +414,28 @@ static struct usb_serial_driver *search_
732 +static struct uart_ops usb_serial_uart_ops = {
733 + .tx_empty = serial_tx_empty,
734 + .set_mctrl = serial_set_mctrl,
735 + .get_mctrl = serial_get_mctrl,
736 + .stop_tx = serial_stop_tx,
737 + .start_tx = serial_start_tx,
738 + .send_xchar = serial_send_xchar,
739 + .stop_rx = serial_stop_rx,
740 + .enable_ms = serial_enable_ms,
741 + .break_ctl = serial_break,
742 + .startup = serial_startup,
743 + .shutdown = serial_shutdown,
744 + .ioctl = serial_ioctl,
745 + .set_termios = serial_set_termios,
747 + .type = serial_type,
748 + .release_port = serial_release_port,
749 + .request_port = serial_request_port,
750 + .config_port = serial_config_port,
751 + .verify_port = serial_verify_port,
754 int usb_serial_probe(struct usb_interface *interface,
755 const struct usb_device_id *id)
757 @@ -931,6 +766,16 @@ #endif
758 port->dev.bus = &usb_serial_bus_type;
759 port->dev.release = &port_release;
762 + * uart_port initialization
764 + port->uart_port.ops = &usb_serial_uart_ops;
765 + port->uart_port.dev = &interface->dev;
766 + port->uart_port.iotype = UPIO_PORT;
767 + port->uart_port.membase = NULL;
768 + port->uart_port.type = PORT_16650;
769 + port->uart_port.fifosize = 16;
771 snprintf (&port->dev.bus_id[0], sizeof(port->dev.bus_id), "ttyUSB%d", port->number);
772 dbg ("registering %s", port->dev.bus_id);
773 device_register (&port->dev);
774 @@ -994,112 +839,79 @@ void usb_serial_disconnect(struct usb_in
775 struct device *dev = &interface->dev;
776 struct usb_serial_port *port;
779 + dbg("%s", serial->type->description);
781 usb_set_intfdata (interface, NULL);
783 for (i = 0; i < serial->num_ports; ++i) {
784 port = serial->port[i];
785 - if (port && port->tty)
786 - tty_hangup(port->tty);
787 + if (port && port->uart_port.info &&
788 + port->uart_port.info->tty)
789 + tty_hangup(port->uart_port.info->tty);
791 - /* let the last holder of this object
792 - * cause it to be cleaned up */
793 - kref_put(&serial->kref, destroy_serial);
794 + destroy_serial(serial);
796 - dev_info(dev, "device disconnected\n");
797 + dev_info(dev, "device disconnected");
800 -static struct tty_operations serial_ops = {
801 - .open = serial_open,
802 - .close = serial_close,
803 - .write = serial_write,
804 - .write_room = serial_write_room,
805 - .ioctl = serial_ioctl,
806 - .set_termios = serial_set_termios,
807 - .throttle = serial_throttle,
808 - .unthrottle = serial_unthrottle,
809 - .break_ctl = serial_break,
810 - .chars_in_buffer = serial_chars_in_buffer,
811 - .read_proc = serial_read_proc,
812 - .tiocmget = serial_tiocmget,
813 - .tiocmset = serial_tiocmset,
814 +struct uart_driver usb_serial_uart_driver = {
815 + .owner = THIS_MODULE,
816 + .driver_name = "usbserial",
817 + .dev_name = "ttyUSB",
818 + .major = SERIAL_TTY_MAJOR,
820 + .nr = SERIAL_TTY_MINORS,
824 -struct tty_driver *usb_serial_tty_driver;
826 static int __init usb_serial_init(void)
832 - usb_serial_tty_driver = alloc_tty_driver(SERIAL_TTY_MINORS);
833 - if (!usb_serial_tty_driver)
835 + result = uart_register_driver(&usb_serial_uart_driver);
839 /* Initialize our global data */
840 - for (i = 0; i < SERIAL_TTY_MINORS; ++i) {
841 + for (i = 0; i < SERIAL_TTY_MINORS; ++i)
842 serial_table[i] = NULL;
845 result = bus_register(&usb_serial_bus_type);
847 - err("registering bus driver failed");
851 - usb_serial_tty_driver->owner = THIS_MODULE;
852 - usb_serial_tty_driver->driver_name = "usbserial";
853 - usb_serial_tty_driver->devfs_name = "usb/tts/";
854 - usb_serial_tty_driver->name = "ttyUSB";
855 - usb_serial_tty_driver->major = SERIAL_TTY_MAJOR;
856 - usb_serial_tty_driver->minor_start = 0;
857 - usb_serial_tty_driver->type = TTY_DRIVER_TYPE_SERIAL;
858 - usb_serial_tty_driver->subtype = SERIAL_TYPE_NORMAL;
859 - usb_serial_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_NO_DEVFS;
860 - usb_serial_tty_driver->init_termios = tty_std_termios;
861 - usb_serial_tty_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
862 - tty_set_operations(usb_serial_tty_driver, &serial_ops);
863 - result = tty_register_driver(usb_serial_tty_driver);
865 - err("tty_register_driver failed");
866 - goto exit_reg_driver;
867 + err("Registering bus driver failed");
871 /* register the USB driver */
872 result = usb_register(&usb_serial_driver);
874 err("usb_register failed");
879 /* register the generic driver, if we should */
880 result = usb_serial_generic_register(debug);
882 - err("registering generic driver failed");
884 + err("Registering generic driver failed");
890 + dbg("usbserial module loaded");
895 usb_deregister(&usb_serial_driver);
898 - tty_unregister_driver(usb_serial_tty_driver);
901 - bus_unregister(&usb_serial_bus_type);
904 - err ("returning with error %d", result);
905 - put_tty_driver(usb_serial_tty_driver);
906 + bus_unregister(&usb_serial_bus_type);
908 + uart_unregister_driver(&usb_serial_uart_driver);
910 + err("Returning with error %d", result);
915 static void __exit usb_serial_exit(void)
917 usb_serial_console_exit();
918 @@ -1107,12 +919,11 @@ static void __exit usb_serial_exit(void)
919 usb_serial_generic_deregister();
921 usb_deregister(&usb_serial_driver);
922 - tty_unregister_driver(usb_serial_tty_driver);
923 - put_tty_driver(usb_serial_tty_driver);
924 bus_unregister(&usb_serial_bus_type);
925 + uart_unregister_driver(&usb_serial_uart_driver);
926 + dbg("usbserial module exiting");
930 module_init(usb_serial_init);
931 module_exit(usb_serial_exit);
933 @@ -1167,7 +978,6 @@ #endif
938 void usb_serial_deregister(struct usb_serial_driver *device)
940 info("USB Serial deregistering driver %s", device->description);
941 @@ -1175,8 +985,6 @@ void usb_serial_deregister(struct usb_se
942 usb_serial_bus_deregister(device);
947 /* If the usb-serial core is built into the core, the usb-serial drivers
948 need these symbols to load properly as modules. */
949 EXPORT_SYMBOL_GPL(usb_serial_register);
950 diff --git a/drivers/usb/serial/usb-serial.h b/drivers/usb/serial/usb-serial.h
951 index 40b660b..b273efa 100644
952 --- a/drivers/usb/serial/usb-serial.h
953 +++ b/drivers/usb/serial/usb-serial.h
954 @@ -17,17 +17,21 @@ #define __LINUX_USB_SERIAL_H
955 #include <linux/config.h>
956 #include <linux/kref.h>
957 #include <linux/mutex.h>
958 +#include <linux/serial_core.h>
960 #define SERIAL_TTY_MAJOR 188 /* Nice legal number now */
961 #define SERIAL_TTY_MINORS 255 /* loads of devices :) */
963 #define MAX_NUM_PORTS 8 /* The maximum number of ports one device can grab at once */
965 +#define USBSERIAL_PORT ((struct usb_serial_port *)port)
967 /* parity check flag */
968 #define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
971 * usb_serial_port: structure for the specific ports of a device.
972 + * @uart_port: the uart_port of this device
973 * @serial: pointer back to the struct usb_serial owner of this port.
974 * @tty: pointer to the corresponding tty for this port.
975 * @lock: spinlock to grab when updating portions of this structure.
976 @@ -60,6 +64,7 @@ #define RELEVANT_IFLAG(iflag) (iflag & (
979 struct usb_serial_port {
980 + struct uart_port uart_port;
981 struct usb_serial * serial;
982 struct tty_struct * tty;
984 @@ -204,6 +209,8 @@ struct usb_serial_driver {
985 struct list_head driver_list;
986 struct device_driver driver;
988 + struct uart_ops *uart_ops;
990 int (*probe) (struct usb_serial *serial, const struct usb_device_id *id);
991 int (*attach) (struct usb_serial *serial);
992 int (*calc_num_ports) (struct usb_serial *serial);
993 @@ -213,20 +220,6 @@ struct usb_serial_driver {
994 int (*port_probe) (struct usb_serial_port *port);
995 int (*port_remove) (struct usb_serial_port *port);
997 - /* serial function calls */
998 - int (*open) (struct usb_serial_port *port, struct file * filp);
999 - void (*close) (struct usb_serial_port *port, struct file * filp);
1000 - int (*write) (struct usb_serial_port *port, const unsigned char *buf, int count);
1001 - int (*write_room) (struct usb_serial_port *port);
1002 - int (*ioctl) (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg);
1003 - void (*set_termios) (struct usb_serial_port *port, struct termios * old);
1004 - void (*break_ctl) (struct usb_serial_port *port, int break_state);
1005 - int (*chars_in_buffer) (struct usb_serial_port *port);
1006 - void (*throttle) (struct usb_serial_port *port);
1007 - void (*unthrottle) (struct usb_serial_port *port);
1008 - int (*tiocmget) (struct usb_serial_port *port, struct file *file);
1009 - int (*tiocmset) (struct usb_serial_port *port, struct file *file, unsigned int set, unsigned int clear);
1011 void (*read_int_callback)(struct urb *urb, struct pt_regs *regs);
1012 void (*write_int_callback)(struct urb *urb, struct pt_regs *regs);
1013 void (*read_bulk_callback)(struct urb *urb, struct pt_regs *regs);
1014 @@ -271,7 +264,7 @@ extern void usb_serial_bus_deregister (s
1016 extern struct usb_serial_driver usb_serial_generic_device;
1017 extern struct bus_type usb_serial_bus_type;
1018 -extern struct tty_driver *usb_serial_tty_driver;
1019 +extern struct uart_driver usb_serial_uart_driver;
1021 static inline void usb_serial_debug_data(int debug,