Commit 0bf9a040 authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman

[PATCH] USB: Moved usb-serial bus specific code to a separate file.

parent 8570cd0b
...@@ -33,7 +33,7 @@ obj-$(CONFIG_USB_SERIAL_SAFE) += safe_serial.o ...@@ -33,7 +33,7 @@ obj-$(CONFIG_USB_SERIAL_SAFE) += safe_serial.o
# Objects that export symbols. # Objects that export symbols.
export-objs := usb-serial.o ezusb.o 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 include $(TOPDIR)/Rules.make
/*
* 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 <linux/config.h>
#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/tty.h>
#include <linux/module.h>
#include <linux/usb.h>
#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);
}
...@@ -382,38 +382,12 @@ static struct usb_driver usb_serial_driver = { ...@@ -382,38 +382,12 @@ static struct usb_driver usb_serial_driver = {
*/ */
static int serial_refcount; static int serial_refcount;
static struct tty_driver serial_tty_driver;
static struct tty_struct * serial_tty[SERIAL_TTY_MINORS]; static struct tty_struct * serial_tty[SERIAL_TTY_MINORS];
static struct termios * serial_termios[SERIAL_TTY_MINORS]; static struct termios * serial_termios[SERIAL_TTY_MINORS];
static struct termios * serial_termios_locked[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 struct usb_serial *serial_table[SERIAL_TTY_MINORS]; /* initially all NULL */
static LIST_HEAD(usb_serial_driver_list); 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) struct usb_serial *usb_serial_get_by_minor (unsigned int minor)
{ {
...@@ -1283,7 +1257,7 @@ void usb_serial_disconnect(struct usb_interface *interface) ...@@ -1283,7 +1257,7 @@ void usb_serial_disconnect(struct usb_interface *interface)
} }
static struct tty_driver serial_tty_driver = { struct tty_driver usb_serial_tty_driver = {
.magic = TTY_DRIVER_MAGIC, .magic = TTY_DRIVER_MAGIC,
.driver_name = "usb-serial", .driver_name = "usb-serial",
#ifndef CONFIG_DEVFS_FS #ifndef CONFIG_DEVFS_FS
...@@ -1337,9 +1311,9 @@ static int __init usb_serial_init(void) ...@@ -1337,9 +1311,9 @@ static int __init usb_serial_init(void)
} }
/* register the tty driver */ /* register the tty driver */
serial_tty_driver.init_termios = tty_std_termios; usb_serial_tty_driver.init_termios = tty_std_termios;
serial_tty_driver.init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; usb_serial_tty_driver.init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
result = tty_register_driver (&serial_tty_driver); result = tty_register_driver (&usb_serial_tty_driver);
if (result) { if (result) {
err("%s - tty_register_driver failed", __FUNCTION__); err("%s - tty_register_driver failed", __FUNCTION__);
goto exit_generic; goto exit_generic;
...@@ -1357,7 +1331,7 @@ static int __init usb_serial_init(void) ...@@ -1357,7 +1331,7 @@ static int __init usb_serial_init(void)
return result; return result;
exit_tty: exit_tty:
tty_unregister_driver(&serial_tty_driver); tty_unregister_driver(&usb_serial_tty_driver);
exit_generic: exit_generic:
usb_serial_generic_deregister(); usb_serial_generic_deregister();
...@@ -1375,7 +1349,7 @@ static void __exit usb_serial_exit(void) ...@@ -1375,7 +1349,7 @@ static void __exit usb_serial_exit(void)
usb_serial_generic_deregister(); usb_serial_generic_deregister();
usb_deregister(&usb_serial_driver); usb_deregister(&usb_serial_driver);
tty_unregister_driver(&serial_tty_driver); tty_unregister_driver(&usb_serial_tty_driver);
bus_unregister(&usb_serial_bus_type); bus_unregister(&usb_serial_bus_type);
} }
...@@ -1383,72 +1357,6 @@ static void __exit usb_serial_exit(void) ...@@ -1383,72 +1357,6 @@ static void __exit usb_serial_exit(void)
module_init(usb_serial_init); module_init(usb_serial_init);
module_exit(usb_serial_exit); 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) int usb_serial_register(struct usb_serial_device_type *new_device)
{ {
...@@ -1457,20 +1365,17 @@ int usb_serial_register(struct usb_serial_device_type *new_device) ...@@ -1457,20 +1365,17 @@ int usb_serial_register(struct usb_serial_device_type *new_device)
/* Add this device to our list of devices */ /* Add this device to our list of devices */
list_add(&new_device->driver_list, &usb_serial_driver_list); list_add(&new_device->driver_list, &usb_serial_driver_list);
new_device->driver.name = (char *)new_device->name; retval = usb_serial_bus_register (new_device);
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)
goto error;
if (!retval) { info("USB Serial support registered for %s", new_device->name);
info("USB Serial support registered for %s",
new_device->name); return retval;
} else { error:
err("problem %d when registering driver %s", err("problem %d when registering driver %s", retval, new_device->name);
retval, new_device->name); list_del(&new_device->driver_list);
}
return retval; return retval;
} }
...@@ -1493,6 +1398,7 @@ void usb_serial_deregister(struct usb_serial_device_type *device) ...@@ -1493,6 +1398,7 @@ void usb_serial_deregister(struct usb_serial_device_type *device)
} }
list_del(&device->driver_list); list_del(&device->driver_list);
usb_serial_bus_deregister (device);
} }
......
...@@ -269,7 +269,12 @@ extern void usb_serial_generic_shutdown (struct usb_serial *serial); ...@@ -269,7 +269,12 @@ extern void usb_serial_generic_shutdown (struct usb_serial *serial);
extern int usb_serial_generic_register (int debug); extern int usb_serial_generic_register (int debug);
extern void usb_serial_generic_deregister (void); 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 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 */ /* 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) static inline int serial_paranoia_check (struct usb_serial *serial, const char *function)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment