ChangeSet 1.870, 2002/12/12 11:58:03-08:00, greg@kroah.com [PATCH] USB: Moved usb-serial bus specific code to a separate file. diff -Nru a/drivers/usb/serial/Makefile b/drivers/usb/serial/Makefile --- a/drivers/usb/serial/Makefile Fri Dec 13 17:19:04 2002 +++ b/drivers/usb/serial/Makefile Fri Dec 13 17:19:04 2002 @@ -33,7 +33,7 @@ # Objects that export symbols. export-objs := usb-serial.o ezusb.o -usbserial-objs := usb-serial.o generic.o $(usbserial-obj-y) +usbserial-objs := usb-serial.o generic.o bus.o $(usbserial-obj-y) include $(TOPDIR)/Rules.make diff -Nru a/drivers/usb/serial/bus.c b/drivers/usb/serial/bus.c --- /dev/null Wed Dec 31 16:00:00 1969 +++ b/drivers/usb/serial/bus.c Fri Dec 13 17:19:04 2002 @@ -0,0 +1,138 @@ +/* + * USB Serial Converter Bus specific functions + * + * Copyright (C) 2002 Greg Kroah-Hartman (greg@kroah.com) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License version + * 2 as published by the Free Software Foundation. + */ + +#include +#include +#include +#include +#include +#include + +#ifdef CONFIG_USB_SERIAL_DEBUG + static int debug = 1; +#else + static int debug; +#endif + +#include "usb-serial.h" + + +static int usb_serial_device_match (struct device *dev, struct device_driver *drv) +{ + struct usb_serial_device_type *driver; + const struct usb_serial_port *port; + + /* + * drivers are already assigned to ports in serial_probe so it's + * a simple check here. + */ + port = to_usb_serial_port(dev); + if (!port) + return 0; + + driver = to_usb_serial_driver(drv); + + if (driver == port->serial->type) + return 1; + + return 0; +} + +struct bus_type usb_serial_bus_type = { + .name = "usb-serial", + .match = usb_serial_device_match, +}; + +static int usb_serial_device_probe (struct device *dev) +{ + struct usb_serial_device_type *driver; + struct usb_serial_port *port; + int retval = 0; + int minor; + + port = to_usb_serial_port(dev); + if (!port) { + retval = -ENODEV; + goto exit; + } + + driver = port->serial->type; + if (driver->port_probe) { + if (!try_module_get(driver->owner)) { + err ("module get failed, exiting"); + retval = -EIO; + goto exit; + } + retval = driver->port_probe (port); + module_put(driver->owner); + if (retval) + goto exit; + } + + minor = port->number; + + tty_register_devfs (&usb_serial_tty_driver, 0, minor); + info("%s converter now attached to ttyUSB%d (or usb/tts/%d for devfs)", + driver->name, minor, minor); + +exit: + return retval; +} + +static int usb_serial_device_remove (struct device *dev) +{ + struct usb_serial_device_type *driver; + struct usb_serial_port *port; + int retval = 0; + int minor; + + port = to_usb_serial_port(dev); + if (!port) { + return -ENODEV; + } + + driver = port->serial->type; + if (driver->port_remove) { + if (!try_module_get(driver->owner)) { + err ("module get failed, exiting"); + retval = -EIO; + goto exit; + } + retval = driver->port_remove (port); + module_put(driver->owner); + } +exit: + minor = port->number; + tty_unregister_devfs (&usb_serial_tty_driver, minor); + info("%s converter now disconnected from ttyUSB%d", + driver->name, minor); + + return retval; +} + +int usb_serial_bus_register(struct usb_serial_device_type *device) +{ + int retval; + + device->driver.name = (char *)device->name; + device->driver.bus = &usb_serial_bus_type; + device->driver.probe = usb_serial_device_probe; + device->driver.remove = usb_serial_device_remove; + + retval = driver_register(&device->driver); + + return retval; +} + +void usb_serial_bus_deregister(struct usb_serial_device_type *device) +{ + driver_unregister (&device->driver); +} + diff -Nru a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c --- a/drivers/usb/serial/usb-serial.c Fri Dec 13 17:19:04 2002 +++ b/drivers/usb/serial/usb-serial.c Fri Dec 13 17:19:04 2002 @@ -382,38 +382,12 @@ */ static int serial_refcount; -static struct tty_driver serial_tty_driver; static struct tty_struct * serial_tty[SERIAL_TTY_MINORS]; static struct termios * serial_termios[SERIAL_TTY_MINORS]; static struct termios * serial_termios_locked[SERIAL_TTY_MINORS]; static struct usb_serial *serial_table[SERIAL_TTY_MINORS]; /* initially all NULL */ static LIST_HEAD(usb_serial_driver_list); -static int usb_serial_device_match (struct device *dev, struct device_driver *drv) -{ - struct usb_serial_device_type *driver; - const struct usb_serial_port *port; - - /* - * drivers are already assigned to ports in serial_probe so it's - * a simple check here. - */ - port = to_usb_serial_port(dev); - if (!port) - return 0; - - driver = to_usb_serial_driver(drv); - - if (driver == port->serial->type) - return 1; - - return 0; -} - -static struct bus_type usb_serial_bus_type = { - .name = "usb-serial", - .match = usb_serial_device_match, -}; struct usb_serial *usb_serial_get_by_minor (unsigned int minor) { @@ -1283,7 +1257,7 @@ } -static struct tty_driver serial_tty_driver = { +struct tty_driver usb_serial_tty_driver = { .magic = TTY_DRIVER_MAGIC, .driver_name = "usb-serial", #ifndef CONFIG_DEVFS_FS @@ -1337,9 +1311,9 @@ } /* register the tty driver */ - serial_tty_driver.init_termios = tty_std_termios; - serial_tty_driver.init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; - result = tty_register_driver (&serial_tty_driver); + usb_serial_tty_driver.init_termios = tty_std_termios; + usb_serial_tty_driver.init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; + result = tty_register_driver (&usb_serial_tty_driver); if (result) { err("%s - tty_register_driver failed", __FUNCTION__); goto exit_generic; @@ -1357,7 +1331,7 @@ return result; exit_tty: - tty_unregister_driver(&serial_tty_driver); + tty_unregister_driver(&usb_serial_tty_driver); exit_generic: usb_serial_generic_deregister(); @@ -1375,7 +1349,7 @@ usb_serial_generic_deregister(); usb_deregister(&usb_serial_driver); - tty_unregister_driver(&serial_tty_driver); + tty_unregister_driver(&usb_serial_tty_driver); bus_unregister(&usb_serial_bus_type); } @@ -1383,72 +1357,6 @@ module_init(usb_serial_init); module_exit(usb_serial_exit); -static int usb_serial_device_probe (struct device *dev) -{ - struct usb_serial_device_type *driver; - struct usb_serial_port *port; - int retval = 0; - int minor; - - port = to_usb_serial_port(dev); - if (!port) { - retval = -ENODEV; - goto exit; - } - - driver = port->serial->type; - if (driver->port_probe) { - if (!try_module_get(driver->owner)) { - err ("module get failed, exiting"); - retval = -EIO; - goto exit; - } - retval = driver->port_probe (port); - module_put(driver->owner); - if (retval) - goto exit; - } - - minor = port->number; - - tty_register_devfs (&serial_tty_driver, 0, minor); - info("%s converter now attached to ttyUSB%d (or usb/tts/%d for devfs)", - driver->name, minor, minor); - -exit: - return retval; -} - -static int usb_serial_device_remove (struct device *dev) -{ - struct usb_serial_device_type *driver; - struct usb_serial_port *port; - int retval = 0; - int minor; - - port = to_usb_serial_port(dev); - if (!port) { - return -ENODEV; - } - - driver = port->serial->type; - if (driver->port_remove) { - if (!try_module_get(driver->owner)) { - err ("module get failed, exiting"); - retval = -EIO; - goto exit; - } - retval = driver->port_remove (port); - module_put(driver->owner); - } -exit: - minor = port->number; - tty_unregister_devfs (&serial_tty_driver, minor); - info("%s converter now disconnected from ttyUSB%d", - driver->name, minor); - - return retval; -} int usb_serial_register(struct usb_serial_device_type *new_device) { @@ -1457,20 +1365,17 @@ /* Add this device to our list of devices */ list_add(&new_device->driver_list, &usb_serial_driver_list); - new_device->driver.name = (char *)new_device->name; - new_device->driver.bus = &usb_serial_bus_type; - new_device->driver.probe = usb_serial_device_probe; - new_device->driver.remove = usb_serial_device_remove; - - retval = driver_register(&new_device->driver); - - if (!retval) { - info("USB Serial support registered for %s", - new_device->name); - } else { - err("problem %d when registering driver %s", - retval, new_device->name); - } + retval = usb_serial_bus_register (new_device); + + if (retval) + goto error; + + info("USB Serial support registered for %s", new_device->name); + + return retval; +error: + err("problem %d when registering driver %s", retval, new_device->name); + list_del(&new_device->driver_list); return retval; } @@ -1493,6 +1398,7 @@ } list_del(&device->driver_list); + usb_serial_bus_deregister (device); } diff -Nru a/drivers/usb/serial/usb-serial.h b/drivers/usb/serial/usb-serial.h --- a/drivers/usb/serial/usb-serial.h Fri Dec 13 17:19:04 2002 +++ b/drivers/usb/serial/usb-serial.h Fri Dec 13 17:19:04 2002 @@ -269,7 +269,12 @@ extern int usb_serial_generic_register (int debug); extern void usb_serial_generic_deregister (void); +extern int usb_serial_bus_register (struct usb_serial_device_type *device); +extern void usb_serial_bus_deregister (struct usb_serial_device_type *device); + extern struct usb_serial_device_type usb_serial_generic_device; +extern struct bus_type usb_serial_bus_type; +extern struct tty_driver usb_serial_tty_driver; /* Inline functions to check the sanity of a pointer that is passed to us */ static inline int serial_paranoia_check (struct usb_serial *serial, const char *function)