summaryrefslogtreecommitdiff
path: root/drivers/usb/serial/bus.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 15:20:36 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 15:20:36 -0700
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/usb/serial/bus.c
Linux-2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'drivers/usb/serial/bus.c')
-rw-r--r--drivers/usb/serial/bus.c134
1 files changed, 134 insertions, 0 deletions
diff --git a/drivers/usb/serial/bus.c b/drivers/usb/serial/bus.c
new file mode 100644
index 000000000000..2f612c2d894b
--- /dev/null
+++ b/drivers/usb/serial/bus.c
@@ -0,0 +1,134 @@
+/*
+ * 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>
+#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)) {
+ dev_err(dev, "module get failed, exiting\n");
+ retval = -EIO;
+ goto exit;
+ }
+ retval = driver->port_probe (port);
+ module_put(driver->owner);
+ if (retval)
+ goto exit;
+ }
+
+ minor = port->number;
+ tty_register_device (usb_serial_tty_driver, minor, dev);
+ dev_info(&port->serial->dev->dev,
+ "%s converter now attached to ttyUSB%d\n",
+ driver->name, 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)) {
+ dev_err(dev, "module get failed, exiting\n");
+ retval = -EIO;
+ goto exit;
+ }
+ retval = driver->port_remove (port);
+ module_put(driver->owner);
+ }
+exit:
+ minor = port->number;
+ tty_unregister_device (usb_serial_tty_driver, minor);
+ dev_info(dev, "%s converter now disconnected from ttyUSB%d\n",
+ driver->name, minor);
+
+ return retval;
+}
+
+int usb_serial_bus_register(struct usb_serial_device_type *device)
+{
+ int retval;
+
+ if (device->short_name)
+ device->driver.name = (char *)device->short_name;
+ else
+ 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;
+ device->driver.owner = device->owner;
+
+ retval = driver_register(&device->driver);
+
+ return retval;
+}
+
+void usb_serial_bus_deregister(struct usb_serial_device_type *device)
+{
+ driver_unregister (&device->driver);
+}
+