2 * USB Serial Converter Bus specific functions
4 * Copyright (C) 2002 Greg Kroah-Hartman (greg@kroah.com)
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License version
8 * 2 as published by the Free Software Foundation.
11 #include <linux/config.h>
12 #include <linux/kernel.h>
13 #include <linux/errno.h>
14 #include <linux/tty.h>
15 #include <linux/module.h>
16 #include <linux/usb.h>
17 #include "usb-serial.h"
19 static int usb_serial_device_match (struct device *dev, struct device_driver *drv)
21 struct usb_serial_device_type *driver;
22 const struct usb_serial_port *port;
25 * drivers are already assigned to ports in serial_probe so it's
26 * a simple check here.
28 port = to_usb_serial_port(dev);
32 driver = to_usb_serial_driver(drv);
34 if (driver == port->serial->type)
40 struct bus_type usb_serial_bus_type = {
42 .match = usb_serial_device_match,
45 static int usb_serial_device_probe (struct device *dev)
47 struct usb_serial_device_type *driver;
48 struct usb_serial_port *port;
52 port = to_usb_serial_port(dev);
58 driver = port->serial->type;
59 if (driver->port_probe) {
60 if (!try_module_get(driver->owner)) {
61 dev_err(dev, "module get failed, exiting\n");
65 retval = driver->port_probe (port);
66 module_put(driver->owner);
72 tty_register_device (usb_serial_tty_driver, minor, dev);
73 dev_info(&port->serial->dev->dev,
74 "%s converter now attached to ttyUSB%d\n",
81 static int usb_serial_device_remove (struct device *dev)
83 struct usb_serial_device_type *driver;
84 struct usb_serial_port *port;
88 port = to_usb_serial_port(dev);
93 driver = port->serial->type;
94 if (driver->port_remove) {
95 if (!try_module_get(driver->owner)) {
96 dev_err(dev, "module get failed, exiting\n");
100 retval = driver->port_remove (port);
101 module_put(driver->owner);
104 minor = port->number;
105 tty_unregister_device (usb_serial_tty_driver, minor);
106 dev_info(dev, "%s converter now disconnected from ttyUSB%d\n",
107 driver->name, minor);
112 int usb_serial_bus_register(struct usb_serial_device_type *device)
116 if (device->short_name)
117 device->driver.name = (char *)device->short_name;
119 device->driver.name = (char *)device->name;
120 device->driver.bus = &usb_serial_bus_type;
121 device->driver.probe = usb_serial_device_probe;
122 device->driver.remove = usb_serial_device_remove;
123 device->driver.owner = device->owner;
125 retval = driver_register(&device->driver);
130 void usb_serial_bus_deregister(struct usb_serial_device_type *device)
132 driver_unregister (&device->driver);